gpt4 book ai didi

amazon-web-services - AWS::ApiGateway::Method 在每次部署中都会被删除

转载 作者:行者123 更新时间:2023-12-03 07:27:21 26 4
gpt4 key购买 nike

我有一个带有 cloudformation 模板的代码管道。我正在创建 AWS::ApiGateway::Resource 和 AWS::ApiGateway::Method 来访问 S3 存储桶。第一次它使用 API 创建方法。但是当我将更改推送到存储库时并且它重新部署该方法被删除。

我不能,这就是原因。有人有任何线索吗!谢谢!

QrResource:
Type: "AWS::ApiGateway::Resource"
Properties:
ParentId:
Fn::GetAtt:
- "myApi"
- "RootResourceId"
RestApiId: !Ref myApi
PathPart: "qr"
QrItemResource:
Type: "AWS::ApiGateway::Resource"
Properties:
ParentId: !Ref QrResource
RestApiId: !Ref myApi
PathPart: "{item}"
Qr:
Type: "AWS::ApiGateway::Method"
Properties:
HttpMethod: GET
ApiKeyRequired: false
AuthorizationType: NONE
RequestParameters:
method.request.header.Content-Disposition: false
method.request.header.Content-Type: false
method.request.header.Accept: false
method.request.path.item: true
MethodResponses:
- StatusCode: 200
ResponseParameters:
method.response.header.Content-Type: integration.response.header.Content-Type
method.response.header.Content-Disposition: integration.response.header.Content-Disposition
method.response.header.Accept-Ranges: integration.response.header.Accept-Ranges
ResponseModels:
"application/json": EmptyModel
- StatusCode: 403
ResponseModels:
"application/json": ErrorModel
RestApiId: !Ref myApi
ResourceId: !Ref QrItemResource
Integration:
Type: AWS
Credentials: !Ref RoleApi
IntegrationHttpMethod: GET
PassthroughBehavior: WHEN_NO_MATCH
IntegrationResponses:
- StatusCode: 200
SelectionPattern: 200
ContentHandling: CONVERT_TO_BINARY
ResponseParameters:
method.response.header.Content-Type: integration.response.header.Content-Type
method.response.header.Accept-Ranges: "'bytes'"
method.response.header.Content-Disposition: "'inline'"
ResponseTemplates:
"application/json": ""
RequestParameters:
integration.request.header.Content-Disposition: method.request.header.Content-Disposition
integration.request.header.Content-Type: method.request.header.Content-Type
integration.request.header.Accept: method.request.header.Accept
integration.request.path.item: method.request.path.item
Uri: arn:aws:apigateway:us-east-1:s3:path/s3-bucket/{item}

最佳答案

我遇到了同样的问题,因此我在 AWS Support 中开了一张票。这是他们的答案:

Customer is using Serverless Application Model(SAM) (AWS::Serverless::Api+AWS::Serverless::Function) resources along with API Gateway CFN Resources (AWS::ApiGateway::Method) to define their API. 
This can have unpredictable situation where first can overwrite the second. We highly recommend customer to define this new resources in SAM directly under AWS::Serverless::Api as part of OpenApi.

首先,我认为这是一个错误,因为在不可预测的情况下,第一个可以覆盖第二个似乎不是任何人所期望的行为。

但后来,他们向我解释说 AWS::Serverless::Api 创建了所有必要的资源(例如 AWS::APIGateway::RestApi)连接所有东西。

因此,如果您要推送所有资源(AWS::Serverless::ApiAWS::ApiGateway::Resource AWS::ApiGateway::Method)正在修改,Cloudformation 将在 OpenAPI 定义中应用这些更改,一切都会按预期工作。

另一方面,如果您要在 AWS::Serverless::Api 中推送更改(例如添加附加的 AWS::Serverless::Function对于 AWS::Serverless::Api),Cloudformation 将检测到 AWS::ApiGateway::ResourceAWS::ApiGateway::Method 上没有任何更改 (因此 AWS::Serverless::Api OpenAPI 定义将覆盖您的独立方法和路径)。

他们似乎没有办法检查自己这边的这些冲突,这更有意义。

因此,最终的解决方案不是将 AWS::Serverless::Api 与独立的 AWS::ApiGateway 资源(例如 AWS: :ApiGateway::MethodAWS::ApiGateway::Resource)。

事实上,他们告诉我他们即将更新文档以添加此建议。(好像还没有推送,但是我们可以找到文档历史here)

关于amazon-web-services - AWS::ApiGateway::Method 在每次部署中都会被删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63995532/

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