使用模板文件从Cloudformation创建多个API密钥

问题描述

使用云形成来设置新的API密钥时遇到问题。

我有一个用于部署API的通用堆栈的模板和1个认密钥。这是通过CI / CD管道中的Python脚本执行的。这样就可以了。

现在我们希望加入更多的团队,并需要为其提供自己的API密钥。

我创建了一个单独的模板,该模板仅包含密钥,并且是要更新的文件。这只能通过CI / CD管道中的Python脚本执行。

执行脚本时,出现以下错误UsagePlanKey already exists in stack arn:aws:stackINFO

据我了解,对于每个新的API密钥,我都需要创建一个API密钥和一个UsagePlanKey。所以我正在做的是这样:

  TEAMNAMEApiKey:
    Type: AWS::ApiGateway::ApiKey
    Properties:
      Enabled: true
      StageKeys:
        - RestApiId: !ImportValue ApiGatewayID
          StageName: !ImportValue StageName
  
  TEAMNAMEUsagePlanKey:
    Type: AWS::ApiGateway::UsagePlanKey
    Properties:
      KeyId: !ImportValue KeyId
      KeyType: API_KEY
      UsagePlanId: !ImportValue UsagePlanId

!ImportValue从另一个模板中导出,如下所示:

Outputs:
  ApiGatewayID:
    Description: The ApiGateway
    Value: !Ref ApiGateway
    Export:
      Name: ApiGatewayID
  StageName:
    Description: The stagename for the Api
    Value: !Ref Stage
    Export:
      Name: StageName
  KeyId:
    Description: ID of the Api Key
    Value: !Ref ApiKey
    Export:
      Name: KeyId
  UsagePlanId:
    Description: The ID of the usage plan.
    Value: !Ref UsagePlan
    Export:
      Name: UsagePlanId

我不确定这是否重要,但是出于某些原因,api键是在新堆栈中设置的,而不是添加到先前创建的堆栈中。只要能用,对我来说这不是问题,但目前不起作用,不确定是否是问题。

如果您需要其他信息,请告诉我。

谢谢您的帮助!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)