IntegrationResponse SAM 模板
IntegrationResponse SAM Template
问题:
- 对 Sam 模板的集成响应?没有 OpenApi 可以吗?
- 如何将 headers 添加到 SAM 模板中的 GatewayResponses?
我想要实现的目标:
- 在 SAM 中定义网关响应和集成响应 CloudFront 模板。
到目前为止我检查了什么:
我正在检查 SAM github,但我不清楚如何根据上述 link 进行检查。 我也没有在 Whosebug 上找到任何答案,这可以解释为什么 headers 在我的 gatewayresponse 片段
中不好感谢您的帮助
一些示例:
Globals:
Api:
GatewayResponses:
MISSING_AUTHENTICATION_TOKEN:
ResponseParameters:
# gatewayresponse.header.Cache-Control: "no-cache"
ResponseTemplates:
"application/json" : '{"errors": [{errorKey: "error Value"}]}'
StatusCode: '404'
#defaultResponse: true
预期的功能级集成响应:
Function:
Type: AWS::Serverless::Function
Properties:
Handler: Function.handler
Timeout: 20
CodeUri: "src/Function"
Role: .......
Events:
FunctionGet:
Type: Api
Properties:
Path: /Function
Method: get
IntegrationResponse:
SOME_ERROR_CODE
ResponseTemplates
integrationresponse.header
长话短说,我的问题有一半是愚蠢的。在代理集成中 API GW 默认返回从服务器到客户端的响应,无需在 SAM 模板中进一步声明。
至于headers,正确的做法是:
Globals:
Api:
GatewayResponses:
MISSING_AUTHENTICATION_TOKEN:
ResponseParameters:
Headers:
Access-Control-Allow-Origin: "'*'"
Access-Control-Allow-Headers: "'*'"
Cache-Control: "'no-cache'"
Content-Type: "'application/json'"
ResponseTemplates:
"application/json" : '{"errors": [{errorKey: "error Value"}]}'
StatusCode: '404'
#defaultResponse: true