Serverless Framework - Variables resolution error

Viewed 6106

I have serverless.yaml script that use to work before - next after updating to newer version of SLS (2.72.0) I start getting warning:

Cannot resolve serverless.yaml: Variables resolution errored with:
  - Cannot resolve variable at "custom.S3_BUCKET_NAME": Value not found at "self" source

my custom section looks like this:

custom:
  S3_BUCKET_NAME: ${self:service}-data-${opt:stage, self:provider.stage}
  s3Sync:
    - bucketName: ${self:custom.S3_BUCKET_NAME}-website
      localDir: ./dist
      deleteRemoved: true

how I can fix this warning?

2 Answers

There is a slight change in variables resolution and in your case, the best way to resolve it would be to use the following syntax:

custom:
  S3_BUCKET_NAME: ${self:service}-data-${sls:stage}
  s3Sync:
    - bucketName: ${self:custom.S3_BUCKET_NAME}-website
      localDir: ./dist
      deleteRemoved: true

for resolving the stage. Alternatively, you can use old syntax, but provide explicit fallback value for stage:

custom:
  S3_BUCKET_NAME: ${self:service}-data-${opt:stage, self:provider.stage, 'dev'}
  s3Sync:
    - bucketName: ${self:custom.S3_BUCKET_NAME}-website
      localDir: ./dist
      deleteRemoved: true

I would recommend going with sls:stage version.

Related