【发布时间】:2020-09-21 15:20:34
【问题描述】:
在具有 AWS::ApiGateway::Method - Integration:Type 和 Lambda 后端的 CloudFormation 模板中,AWS 和 AWS_PROXY 有什么区别?刚才我不断收到 502 错误,并意识到我需要使用格式非常明确的 JSON 响应进行响应。当我从控制台创建 API 网关时,我从未遇到过这个问题。它现在确实有效,但我想知道潜在的差异,以便我可以学习。
这是来自 CF 模板的部分:
VisitorCounterAPIGatewayRootMethod:
Type: AWS::ApiGateway::Method
Properties:
AuthorizationType: NONE
HttpMethod: GET
Integration:
IntegrationHttpMethod: POST
Type: AWS_PROXY #THIS is my question. AWS or AWS_PROXY?
Uri: !Sub
- arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${lambdaArn}/invocations
- lambdaArn: !GetAtt VisitorCountLambda.Arn
ResourceId: !GetAtt VisitorCounterAPIGateway.RootResourceId
RestApiId: !Ref VisitorCounterAPIGateway
这是我的 Lambda 函数 (Python3.7) 的响应代码:
apiResponse = {
"isBase64Encoded": False,
"statusCode": 200,
"body": json.dumps({
"visitorCount": int(float(response["Attributes"]["amount"]))
})
}
谢谢。
【问题讨论】:
标签: amazon-web-services aws-lambda amazon-cloudformation aws-api-gateway