成功后
sls remove
所有sls
命令失败
ID为X的堆栈不存在
检查已删除堆栈、附加堆栈和 S3 部署存储桶。尝试删除
.serverless/
,但没有帮助。
问题是
${cf:...}
语法需要现有 CloudFormation 堆栈的输出,当您尚未部署项目时,堆栈及其输出尚不存在。
如果您需要从“当前”堆栈内部访问该输出,您应该查看无服务器如何定义输出(此示例来自我的一个项目):
"ServiceEndpoint":{
"Description": "URL of the service endpoint",
"Value": {"Fn::Join":["", [
"https://",
{"Ref":"ApiGatewayRestApi"},
".execute-api.eu-central-1.",
{"Ref":"AWS::URLSuffix"},"/dev"]]}
}
您可以使用相同的语法在您自己的堆栈中需要的地方“生成”该值,将动态部分替换为无服务器变量,如
${self:provider.region}
和${self:provider.stage}
,或者您的项目选择使用的任何内容而不是他们。例如,将其添加到 Lambda 环境中:
provider:
environment:
SERVICE_ENDPOINT: {"Fn::Join":["", [
"https://",
{"Ref":"ApiGatewayRestApi"},
".execute-api.${self:provider.region}.",
{"Ref":"AWS::URLSuffix"},
"/${self:provider.stage}"]]}
在我的例子中,我手动删除了 cloudformation 堆栈并运行了
sls deploy -s <stage> --force
并且它起作用了。
事实证明,我的
${cf:${self:service}-${self:provider.stage}.ServiceEndpoint}
中的冒犯位是 serverless.yml
。显然,如果主堆栈不存在,serverless.yml 中的${cf:...}
内容(或至少是特定情况)会失败,即您尚未部署。
我无法确定这是 sls 错误还是我应该知道得更好。
CloudFormation 是区域特定的。我遇到了同样的错误。我使用命令创建了一个堆栈
aws cloudformation create-stack --stack-name myFirstTest --region us-east-1 --template-body file://myFirstTemplate.yml
但是当我试图描述堆栈时,我得到了同样的错误,因为我在我的 .aws/config 文件中将默认区域设置为 us-east-2。您可以使用
cat ~/.aws/config
检查此文件
我遇到了这个错误,然后在命令中使用 --region 标签解决了它
aws cloudformation describe-stacks --stack-name myFirstTest --region us-east-1