如何解决使用模板文件从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 举报,一经查实,本站将立刻删除。