Skip to content

Instantly share code, notes, and snippets.

@jebai0521
Last active October 14, 2019 15:59
Show Gist options
  • Save jebai0521/332f58e1569347aa2dc2d41aeaa4bb21 to your computer and use it in GitHub Desktop.
Save jebai0521/332f58e1569347aa2dc2d41aeaa4bb21 to your computer and use it in GitHub Desktop.
'use strict';
exports.handler = (event, context, callback) => {
const request = event.Records[0].cf.request;
const s3DomainName = 'static-jebai.s3.amazonaws.com';
const countryCode = request.headers['cloudfront-viewer-country'][0].value.toLowerCase();
request.origin = {
s3: {
domainName: s3DomainName,
region: '',
authMethod: 'none',
path: "/" + countryCode,
customHeaders: {}
}
}
request.headers['host'] = [{ key: 'host', value: s3DomainName }];
callback(null, request);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment