【发布时间】:2021-11-17 11:34:41
【问题描述】:
我按照 AWS 教程使用 SAM 模板设置 Lambda + API Gateway。 但是在 lambda 模板下定义的事件会创建一个代理集成。 我遵循本教程是因为我想为我的一个项目设置类似的设置。 我需要针对该特定用例的非代理集成。因为我必须将 xml 格式返回给客户端,而这只能通过修改集成响应来完成。 但在代理 API 集成响应中无法修改。 我搜索了很多,但找不到答案。 现在 template.yaml 看起来像这样
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
callforward
Sample SAM Template for callforward
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
Timeout: 3
Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: hello_world/
Handler: app.lambda_handler
Runtime: python3.8
Events:
HelloWorld:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /hello
Method: get
Outputs:
# ServerlessRestApi is an implicit API created out of Events key under Serverless::Function
# Find out more about other implicit resources you can reference within SAM
# https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api
HelloWorldApi:
Description: "API Gateway endpoint URL for Prod stage for Hello World function"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/"
HelloWorldFunction:
Description: "Hello World Lambda Function ARN"
Value: !GetAtt HelloWorldFunction.Arn
HelloWorldFunctionIamRole:
Description: "Implicit IAM Role created for Hello World function"
Value: !GetAtt HelloWorldFunctionRole.Arn
【问题讨论】:
标签: amazon-web-services aws-lambda amazon-cloudformation aws-api-gateway