我遵循了使用SAM模板设置Lambda + API网关的AWS教程。但是在lambda模板下定义的事件会创建代理集成。我遵循本教程是因为我想为我的一个项目设置类似的内容。我需要那个特定用例的非代理集成。因为我必须将xml格式返回给客户机,这只能通过修改Integration来完成。但是在代理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发布于 2021-12-21 13:16:23
更新:如果有人碰到这个愚蠢的问题,这是给你的。使用Lambda的代理API网关的全部目的是只返回lambda返回的任何内容。
我能够使用代理API本身来完成我的需求。遵循这个线程作为起点,https://forums.aws.amazon.com/thread.jspa?messageID=649836
我被要求把这个东西移到一个新的AWS帐户,看到我以前写的代码,对它畏缩,然后重写它。当我写这篇文章的时候,我开始为为什么要问这个愚蠢的问题而感到害怕。
发布于 2021-09-24 10:23:27
您需要的是API网关的“映射模板”功能。不幸的是,在AWS SAM中没有直接的方法来做到这一点。
但是有一种方法可以通过利用AWS SAM内部的Open支持来实现这一点,AWS SAM有一个API网关扩展的子集。(x网关-集成.对象)
RestApi:
Type: AWS::Serverless::Api
Properties:
DefinitionBody:
<add openAPI defintaion>https://stackoverflow.com/questions/69310681
复制相似问题