gpt4 book ai didi

amazon-web-services - AWS APIgateway 响应映射

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

我有一个 API 网关集成,其中数据直接发送到 dynamodbx-amazon-apigateway-integration 定义了响应代码映射,因此我的目的是在客户端获取 dynamodb 抛出的类似响应代码。

我的 apigateway-integration 响应代码映射如下所示。

      x-amazon-apigateway-integration:
type: aws
uri: !Sub arn:aws:apigateway:${AWS::Region}:dynamodb:action/PutItem
credentials: !GetAtt ApiGatewayDynamoRole.Arn
httpMethod: POST
passthroughBehavior: when_no_match
responses:
"default":
statusCode: "200"
SelectionPattern: "2\\d{2}"
responseParameters:
method.response.header.Access-Control-Allow-Methods: "'OPTIONS,POST'"
method.response.header.Access-Control-Allow-Headers: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'"
method.response.header.Access-Control-Allow-Origin: "'*'"
"BAD.*":
statusCode: "400"
SelectionPattern: "4\\d{2}"
responseParameters:
method.response.header.Access-Control-Allow-Methods: "'OPTIONS,POST'"
method.response.header.Access-Control-Allow-Headers: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'"
method.response.header.Access-Control-Allow-Origin: "'*'"
"INT.*":
statusCode: "500"
SelectionPattern: "5\\d{2}"
responseParameters:
method.response.header.Access-Control-Allow-Methods: "'OPTIONS,POST'"
method.response.header.Access-Control-Allow-Headers: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'"
method.response.header.Access-Control-Allow-Origin: "'*'"
responses:
"200":
description: The unique identifier of the new feedback
headers:
Access-Control-Allow-Origin:
type: "string"
Access-Control-Allow-Methods:
type: string
Access-Control-Allow-Headers:
type: string
schema:
$ref: "#/definitions/NewFeedbackResponse"
"400":
description: Bad request
headers:
Access-Control-Allow-Origin:
type: "string"
Access-Control-Allow-Methods:
type: string
Access-Control-Allow-Headers:
type: string
schema:
$ref: "#/definitions/Error"
"500":
description: Internal error
headers:
Access-Control-Allow-Origin:
type: "string"
Access-Control-Allow-Methods:
type: string
Access-Control-Allow-Headers:
type: string
schema:
$ref: "#/definitions/Error"

但这不起作用,如下所示,400 响应已映射到 200。知道我错过了什么吗?

Mon Mar 22 16:33:25 UTC 2021 : Sending request to https://dynamodb.us-west-2.amazonaws.com/?Action=PutItem
Mon Mar 22 16:33:25 UTC 2021 : Received response. Status: 400, Integration latency: 13 ms
Mon Mar 22 16:33:25 UTC 2021 : Endpoint response headers: {Server=Server, Date=Mon, 22 Mar 2021 16:33:25 GMT, Content-Type=application/x-amz-json-1.0, Content-Length=310, Connection=keep-alive, x-amzn-RequestId=XXXXXXXXXXXGBB7126RVV4KQNSO5AXXXXXXXXXX, x-amz-crc32=418088284}
Mon Mar 22 16:33:25 UTC 2021 : Endpoint response body before transformations: {"__type":"com.amazon.coral.service#AccessDeniedException","Message":"User: arn:aws:sts::XXXXXXX:assumed-role/dynamoapi-ApiGatewayDynamoRole-BBBFKOGK2NP5/BackplaneAssumeRoleSession is not authorized to perform: dynamodb:PutItem on resource: arn:aws:dynamodb:us-west-2:XXXXXXX:table/feedback_events2"}
Mon Mar 22 16:33:25 UTC 2021 : Method response body after transformations: {"__type":"com.amazon.coral.service#AccessDeniedException","Message":"User: arn:aws:sts::3XXXXXXX:assumed-role/dynamoapi-ApiGatewayDynamoRole-BBBFKOGK2NP5/BackplaneAssumeRoleSession is not authorized to perform: dynamodb:PutItem on resource: arn:aws:dynamodb:us-west-2:380672241378:table/feedback_events2"}
Mon Mar 22 16:33:25 UTC 2021 : Method response headers: {X-Amzn-Trace-Id=Root=1-6058c6d5-02f9e3bf2c1da22f6c7fdab6, Access-Control-Allow-Headers=Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token, Access-Control-Allow-Methods=OPTIONS,POST, Access-Control-Allow-Origin=*, Content-Type=application/json}
Mon Mar 22 16:33:25 UTC 2021 : Successfully completed execution
Mon Mar 22 16:33:25 UTC 2021 : Method completed with status: 200

最佳答案

如果有人有同样的疑问,它不是对我有用的 SelectionPattern,而是 Response status pattern 属性,更多详细信息 here .

  x-amazon-apigateway-integration:
type: aws
uri: !Sub arn:aws:apigateway:${AWS::Region}:dynamodb:action/PutItem
credentials: !GetAtt ApiGatewayDynamoRole.Arn
httpMethod: POST
passthroughBehavior: when_no_match
responses:
"2\\d{2}":
statusCode: "200"
SelectionPattern: "2\\d{2}"
responseParameters:
method.response.header.Access-Control-Allow-Methods: "'OPTIONS,POST'"
method.response.header.Access-Control-Allow-Headers: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'"
method.response.header.Access-Control-Allow-Origin: "'*'"
"4\\d{2}":
statusCode: "400"
SelectionPattern: "4\\d{2}"
responseParameters:
method.response.header.Access-Control-Allow-Methods: "'OPTIONS,POST'"
method.response.header.Access-Control-Allow-Headers: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'"
method.response.header.Access-Control-Allow-Origin: "'*'"
"5\\d{2}":
statusCode: "500"
SelectionPattern: "5\\d{2}"
responseParameters:
method.response.header.Access-Control-Allow-Methods: "'OPTIONS,POST'"
method.response.header.Access-Control-Allow-Headers: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'"
method.response.header.Access-Control-Allow-Origin: "'*'"

关于amazon-web-services - AWS APIgateway 响应映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66750646/

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