【问题标题】:Reusing cloudformation template for AWS::ApiGateway::ApiKey为 AWS::ApiGateway::ApiKey 重用 cloudformation 模板
【发布时间】: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-asam deploy --stack-name=stack-b 将此模板部署为两个不同的应用程序(CloudFormation 堆栈)也会失败并出现以下错误:

API 密钥已存在(服务:AmazonApiGateway;状态代码:409;错误代码:ConflictException;请求 ID: 已编辑;代理: 空)

如何从这个模板部署两个堆栈?

【问题讨论】:

  • 一个不同的键值,你的问题就会消失。因此,如果您自己设置 api 键值,请确保它们是唯一的。不知道为什么这是不同阶段之间的限制。
  • @AbdulMoeez 这就是原因!一旦你提交这个作为答案,我会接受这个。

标签: amazon-web-services amazon-cloudformation aws-serverless aws-sam


【解决方案1】:

一个不同的键值,你的问题就会消失。因此,如果您自己设置 api 键值,请确保它们是唯一的。不知道为什么这是不同阶段之间的限制。

【讨论】:

    【解决方案2】:

    您真的必须为您的密钥提供一个值吗?它是一个可选参数。您可以将其从模板中删除,AWS 将在每​​次部署中为您生成一个唯一密钥。

    【讨论】:

      猜你喜欢
      • 2018-11-24
      • 1970-01-01
      • 2020-07-22
      • 2018-11-16
      • 1970-01-01
      • 2021-07-20
      • 2016-12-12
      • 2018-05-04
      • 1970-01-01
      相关资源
      最近更新 更多