I am trying to send a custom Response header from my API, I tried using events.response.statusCodes
but it is not working, looks like it was only implemented for http
but not for httpApi
event.
functions:
myfunction:
name: test
handler: src/index.handler
events:
- httpApi:
path: /graphql
method: post
response:
statusCodes:
200:
headers:
Strict-Transport-Security: "'max-age=31536000'"
500:
headers:
Strict-Transport-Security: "'max-age=31536000'"
You are corrrect that it hasn't been implemented for httpApi
. It is supported by HTTP API on AWS level though, so you can override manually properties of created AWS::ApiGatewayV2::Integration
by using the following syntax:
resources:
extensions:
HttpApiIntegrationMain:
Properties:
ResponseParameters:
200:
ResponseParameters:
- Source: "'max-age=31536000'"
Destination: overwrite:header.Strict-Transport-Security
500:
ResponseParameters:
- Source: "'max-age=31536000'"
Destination: overwrite:header.Strict-Transport-Security
See CloudFormation docs for that resource for reference: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-integration.html#cfn-apigatewayv2-integration-responseparameters