AWS::ApiGateway::ApiKey 重复使用 cloudformation 模板
Reusing cloudformation template for AWS::ApiGateway::ApiKey
我有 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
#......
使用 sam deploy --stack-name=stack-a
和 sam deploy --stack-name=stack-b
将此模板部署为两个不同的应用程序(CloudFormation 堆栈)失败并出现以下错误,即使 api 键名不同也是如此:
API Key already exists (Service: AmazonApiGateway; Status Code: 409; Error Code: ConflictException; Request ID:
redacted; Proxy:
null)
如何从此模板部署两个堆栈?
一个不同的键值,您的问题就会消失。因此,如果您自己设置 api 键值,请确保它们是唯一的。不确定为什么这是不同阶段之间的限制。
您真的必须为您的密钥提供一个值吗?这是一个可选参数。您可以将其从您的模板中删除,AWS 将在每次部署中为您生成一个唯一的密钥。
我有 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
#......
使用 sam deploy --stack-name=stack-a
和 sam deploy --stack-name=stack-b
将此模板部署为两个不同的应用程序(CloudFormation 堆栈)失败并出现以下错误,即使 api 键名不同也是如此:
API Key already exists (Service: AmazonApiGateway; Status Code: 409; Error Code: ConflictException; Request ID: redacted; Proxy: null)
如何从此模板部署两个堆栈?
一个不同的键值,您的问题就会消失。因此,如果您自己设置 api 键值,请确保它们是唯一的。不确定为什么这是不同阶段之间的限制。
您真的必须为您的密钥提供一个值吗?这是一个可选参数。您可以将其从您的模板中删除,AWS 将在每次部署中为您生成一个唯一的密钥。