Home > OS >  How do I reference a variable inside a ssm in Serverless
How do I reference a variable inside a ssm in Serverless

Time:12-08

Recently I updated a serverless environment from an extremely outdated version to the latest and have run into many issues. one of which I don't seem to understand why it isn't working. Previously we reference AWS parameter store variable with ssm references like so:

SQS_URL: ${ssm:/foo/${opt:env}/sqsUrl}

Now I have updated our use of the opt to make use of env so it looks like:

SQS_URL: ${ssm:/foo/${env:ENV, "NOT_VALID"}/sqsUrl}

But I get the following error:

Cannot resolve variable at "provider.environment.SQS_URL": Value not found at "ssm" source,

We used to make extensive use all over the place of this to set environment variables on lambdas so that we could pass values to them for them to use at run time, but serverless doesn't seem to like this anymore but looking at the documentation it seems like it should work. Can anyone help me resolve this please?

Thank you!

CodePudding user response:

You have defined SQS_URL variable. Error message says it can't find SQS_QUEUE_URL.

If it's still working after fixing variable names. Try with a given environment to narrow it down.

SQS_URL: ${ssm:/foo/DEV/sqsUrl}

CodePudding user response:

In Serverless, you can reference variables inside a Serverless Service Model (SSM) using the ${ssm:yourVariableName} syntax. For example, if you have a variable named myVariable in SSM, you can reference it in your Serverless configuration file like this:

# serverless.yml

provider:
  name: aws
  runtime: nodejs12.x

functions:
  myFunction:
    handler: handler.myFunction
    environment:
      MY_VARIABLE: ${ssm:/my/variable/path/myVariable}

In the example above, the myFunction function will have access to the value of the myVariable variable in SSM through the MY_VARIABLE environment variable.

It's important to note that the myVariable variable must exist in SSM for this to work. You can create and manage your variables in the SSM console or using the aws ssm put-parameter command.

  • Related