Skip to content

Instantly share code, notes, and snippets.

@Burekasim
Created September 2, 2020 11:35
Show Gist options
  • Save Burekasim/1c097c5bcd1297b1be09dd007f9ddaa3 to your computer and use it in GitHub Desktop.
Save Burekasim/1c097c5bcd1297b1be09dd007f9ddaa3 to your computer and use it in GitHub Desktop.
def lambda_handler(event, context):
host_header = event['Records'][0]['cf']['request']['headers']['host'][0]['value']
new_host_header = host_header.replace('www.', '')
uri_path = event['Records'][0]['cf']['request']['uri']
response = {
'status': '301',
'statusDescription': 'Found',
'headers': {
'location': [{
'key': 'Location',
'value': 'https://' + new_host_header + uri_path
}]
}
}
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment