Skip to content

Instantly share code, notes, and snippets.

@dhsathiya
Created November 17, 2020 09:00
Show Gist options
  • Save dhsathiya/b24761556820a36ae77d75c31c877256 to your computer and use it in GitHub Desktop.
Save dhsathiya/b24761556820a36ae77d75c31c877256 to your computer and use it in GitHub Desktop.
Get Real-IP of a user in a separate request header with CloudFront <-> Lambda@Edge
// Get Real-IP of a user in a separate request header with CloudFront <-> Lambda@Edge
'use strict';
exports.handler = (event, context, callback) => {
const request = event.Records[0].cf.request;
const headers = request.headers;
headers['true-client-ip'] = [{
key: 'True-Client-IP',
value: request['clientIp']
}];
callback(null, request);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment