Skip to content

Instantly share code, notes, and snippets.

@timoschilling
Created June 26, 2020 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timoschilling/c478513d0c1f7f7ebba92f5de9e7ccf0 to your computer and use it in GitHub Desktop.
Save timoschilling/c478513d0c1f7f7ebba92f5de9e7ccf0 to your computer and use it in GitHub Desktop.
CustomResponseHeader:
Type: AWS::Serverless::Function
Properties:
# FunctionName: !Sub ${AWS::StackName}-CustomResponseHeader
Handler: index.handler
Runtime: nodejs12.x
AutoPublishAlias: live
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
- edgelambda.amazonaws.com
Action:
- sts:AssumeRole
InlineCode: |
const addHeader = function(headers, key, value) {
headers[key.toLowerCase()] = [{ key: key, value: value }]
}
exports.handler = async (event) => {
console.log(JSON.stringify(event));
const { response } = event.Records[0].cf;
addHeader(response.headers, 'Strict-Transport-Security', 'max-age=300; includeSubdomains;')
addHeader(response.headers, '')
addHeader(response.headers)
console.log(JSON.stringify(response))
return response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment