【发布时间】:2021-01-11 12:47:00
【问题描述】:
我有 AWS SAM 模板,其中一部分如下所示:
# .......
InternalApiKey:
Type: AWS::ApiGateway::ApiKey
Properties:
Enabled: true
Name: !Sub internal_api_key_${Env}
Value: !Ref InternalApiKeyValue
StageKeys:
- RestApiId: !Ref ServerlessRestApi
StageName: Prod
InternalUsagePlan:
Type: AWS::ApiGateway::UsagePlan
Properties:
ApiStages:
- ApiId: !Ref ServerlessRestApi
Stage: Prod
InternalUsagePlanKey:
Type: AWS::ApiGateway::UsagePlanKey
Properties:
KeyId: !Ref InternalApiKey
KeyType: API_KEY
UsagePlanId: !Ref InternalUsagePlan
#......
即使 api 键名不同,使用 sam deploy --stack-name=stack-a 和 sam deploy --stack-name=stack-b 将此模板部署为两个不同的应用程序(CloudFormation 堆栈)也会失败并出现以下错误:
API 密钥已存在(服务:AmazonApiGateway;状态代码:409;错误代码:ConflictException;请求 ID: 已编辑;代理: 空)
如何从这个模板部署两个堆栈?
【问题讨论】:
-
一个不同的键值,你的问题就会消失。因此,如果您自己设置 api 键值,请确保它们是唯一的。不知道为什么这是不同阶段之间的限制。
-
@AbdulMoeez 这就是原因!一旦你提交这个作为答案,我会接受这个。
标签: amazon-web-services amazon-cloudformation aws-serverless aws-sam