无服务器 CLI --stage 参数不会传递到“provider.stage”
我有以下 serverless.yml 文件内容,
custom:
alarms:
- functionErrors
- functionThrottles
myStage: ${opt:stage, self:provider.stage}
daas-aa-maturity-model-env-stage: !Join
- '-'
- - ${self:service}
- ${self:custom.myStage}
- ${self:provider.region}
scripts:
hooks:
'deploy:finalize': serverless invoke -f copyGlueScripts
provider:
name: aws
lambdaHashingVersion: "20201221"
managedPolicyArns:
- 'arn:aws:iam::aws:policy/service-role/AWSGlueServiceRole'
- ${self:provider.environment.GLUE_JOB_POLICY_ARN}
...
当我部署时,
serverless deploy --aws-profile "${PROFILE_NAME}" --stage nonprod && \
sleep 10 && \
sls s3deploy --profile "${PROFILE_NAME}" --stage nonprod
它会生成一个文件 .serverless/serverless-state.json
,该文件具有以下值
"provider": {
...
"stage": "dev",
,在使用“dev”调用 lambda 时会出现错误以它的名义。在我的例子中,“阶段”不应该是“非产品”吗?
如果我在 serverless.yml 中执行类似操作
provider:
stage: ${opt:stage}
,则会出现以下错误:
ServerlessError: Cannot resolve serverless.yml: Variables resolution errored with:
- Cannot resolve variable at "provider.stage": Value not found at "opt" source
解决方法是在提供程序中专门指定 nonprod:
provider:
stage: nonprod
name: aws
但我们经常将服务部署到不同的环境,例如 dev、nonprod 或 prod。我们希望这是自动化的。
有人可以帮忙吗?谢谢!
I have the following serverless.yml file content
custom:
alarms:
- functionErrors
- functionThrottles
myStage: ${opt:stage, self:provider.stage}
daas-aa-maturity-model-env-stage: !Join
- '-'
- - ${self:service}
- ${self:custom.myStage}
- ${self:provider.region}
scripts:
hooks:
'deploy:finalize': serverless invoke -f copyGlueScripts
provider:
name: aws
lambdaHashingVersion: "20201221"
managedPolicyArns:
- 'arn:aws:iam::aws:policy/service-role/AWSGlueServiceRole'
- ${self:provider.environment.GLUE_JOB_POLICY_ARN}
...
when I deploy using
serverless deploy --aws-profile "${PROFILE_NAME}" --stage nonprod && \
sleep 10 && \
sls s3deploy --profile "${PROFILE_NAME}" --stage nonprod
it generates a file .serverless/serverless-state.json
which has the following values
"provider": {
...
"stage": "dev",
which runs into error when invoking a lambda with a "dev" in its name. Isn't that the "stage" supposed to be "nonprod" in my case?
If I do something like
provider:
stage: ${opt:stage}
in serverless.yml, it gets the following error:
ServerlessError: Cannot resolve serverless.yml: Variables resolution errored with:
- Cannot resolve variable at "provider.stage": Value not found at "opt" source
The workaround is to specify nonprod specifically in provider:
provider:
stage: nonprod
name: aws
But we frequently deploy the service to different env such as dev, nonprod or prod. We would like this to be automated.
Can anyone help? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以执行类似
sls deploy --stage nonprod
的操作,否则它将默认为 dev${opt:stage, 'dev'} 获取从命令行 --stage 选项传递的值。在这种情况下,产品。如果没有传递任何选项,则将 dev 作为默认值。
You can do something like this
sls deploy --stage nonprod
otherwise it will default to dev${opt:stage, 'dev'} takes the value passed from command line --stage option. In this case prod. If no option is passed dev is taken as default.