gpt4 book ai didi

amazon-web-services - AWS SAM : Stage already exists error during deployment

转载 作者:行者123 更新时间:2023-12-03 07:33:22 25 4
gpt4 key购买 nike

我正在尝试部署一个与 Lambda 函数集成的简单 API 网关。我正在使用 GitLab CICD 来部署资源,但即使在尝试了如此多的修复之后,我似乎仍无法成功部署它。下面是我正在使用的 YAML 模板。

Resources:
MyFunction:
Type: AWS::Serverless::Function
FunctionName : MyFunctionName
CodeUri: MyFunctionName/
Handler: app.lambda_handler
Role: MyRole
Tags:
env : dev
Architectures:
- x86_64
Events:
MyAPI:
Type: Api
Properties:
Path: /dev
Method: POST
RestApiId:
Ref: MyAPI
VpcConfig:
SecurityGroupIds: <sec grp id>
SubnetIds: <subnet id>

MyAPI:
Type: AWS::Serverless::Api
Properties:
DefinitionBody:
swagger: 2.0
info:
title: MyAPIName
host: "xxxxx.execute-api.ap-south-1.amazonaws.com"
schemes:
- https
basePath: /dev
paths:
/:
post:
responses: {}
x-amazon-apigateway-integration:
type: "aws_proxy"
httpMethod: "POST"
uri: "arn:aws:apigateway:ap-south-1:lambda:path/2015-03-31/functions/<MyFunction ARN>/invocations"
responses:
default:
statusCode: "200"
passthroughBehavior: "when_no_match"
contentHandling: "CONVERT_TO_TEXT"
x-amazon-apigateway-policy:
Version: '2012-10-17'
Statement:
- Effect: Deny
Principal: "*"
Action: execute-api:Invoke
Resource: "*"
Condition:
StringNotEquals:
aws:sourceVpce:
- vpce-xxxxxx
- Effect: Allow
Principal: "*"
Action: execute-api:Invoke
Resource: "*"
EndpointConfiguration:
Type: PRIVATE
StageName: dev

MyAPIDeployment:
Type: AWS::ApiGateway::Deployment
Properties:
RestApiId:
Ref: MyAPI
StageName: dev

当我尝试部署上述脚本时,收到的错误是:(使用 GitLab CI)

dev already exists in stack arn:aws:cloudformation:ap-south-1:xxxx:stack/stackname/xxxx

我在控制台上检查了 API GW,发现了一个名为 Stage 的阶段(来自旧的部署)。但没有“开发”。我认为这是导致问题的原因,因此删除了该阶段并尝试再次部署。但它仍然给我同样的错误。我已经被这个问题困扰了几天了,任何形式的帮助将不胜感激。

最佳答案

编辑

我没有正确关联此问题 - 这是可能的方法之一:CloudFormation doesn't deploy to API gateway stages on update (纯CFN相当复杂,但是CDK提供了一些构造来轻松实现自定义资源,如果可能的话我建议将代码迁移到CDK)

我在这里看到的第二种方法是创建一个 lambda 函数,它将等到更新完成,然后请求部署 API。该 lambda 应由 Cloudformation 模板调用。

关于amazon-web-services - AWS SAM : Stage already exists error during deployment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73742927/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com