Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serverless Framework - Variables resolution error

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?

like image 469
bensiu Avatar asked Mar 10 '26 12:03

bensiu


1 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.

like image 174
pgrzesik Avatar answered Mar 13 '26 01:03

pgrzesik