本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
自定义响应示例
你可 API Gateway 过在你的Amazon SAMTemplate 要执行此操作,请使用网关响应对象
以下是示例:Amazon SAMAPI Gateway 响应的模板部分:
Resources: MyApi: Type: AWS::Serverless::Api Properties: StageName: Prod GatewayResponses: DEFAULT_4XX: ResponseParameters: Headers: Access-Control-Expose-Headers: "'WWW-Authenticate'" Access-Control-Allow-Origin: "'*'" GetFunction: Type: AWS::Serverless::Function Properties: Handler: index.get Runtime: nodejs12.x InlineCode: module.exports = async () => throw new Error('Check out the response headers!') Events: GetResource: Type: Api Properties: Path: /error Method: get RestApiId: !Ref MyApi
有关 API Gateway 响应的更多信息,请参阅。API Gateway 中的网关响应中的API Gateway 开发人员指南.