我有serverless.yaml脚本,在更新到SLS(2.72.0(的新版本之前-之后,我开始收到警告:
Cannot resolve serverless.yaml: Variables resolution errored with:
- Cannot resolve variable at "custom.S3_BUCKET_NAME": Value not found at "self" source
我的自定义部分如下:
custom:
S3_BUCKET_NAME: ${self:service}-data-${opt:stage, self:provider.stage}
s3Sync:
- bucketName: ${self:custom.S3_BUCKET_NAME}-website
localDir: ./dist
deleteRemoved: true
如何修复此警告?
变量解析略有变化,在您的情况下,解决它的最佳方法是使用以下语法:
custom:
S3_BUCKET_NAME: ${self:service}-data-${sls:stage}
s3Sync:
- bucketName: ${self:custom.S3_BUCKET_NAME}-website
localDir: ./dist
deleteRemoved: true
用于解决该阶段。或者,您可以使用旧语法,但为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
我建议使用sls:stage
版本。
更改从编写阶段的方式
self:provider.stage
收件人:
${sls:stage}
应该做这项工作!
您可以在以下位置找到更新的文档:https://www.serverless.com/framework/docs/providers/aws/guide/variables或者运行CCD_ 2以获得问题的更详细的响应。