I believe you are triggering your lambda function manually instead of via the assigned event trigger(s3, sns etc).
For manual triggering you need to pass the event by yourself, something like below, I am using an event sample from s3.(If you are not doing it manual let me know how you are triggering it.)
Also, make sure the event that you have received is an object and not a string.
let event = {
"Records": [
{
"eventVersion": "2.0",
"eventSource": "aws:s3",
"awsRegion": "us-west-2",
"eventTime": "2018-04-20T21:01:59.672Z",
"eventName": "ObjectCreated:Put",
"userIdentity": {
"principalId": "AWS:xxxxxxxxxxx:xxx"
},
"requestParameters": {
"sourceIPAddress": "172.0.0.1"
},
"responseElements": {
"x-amz-request-id": "xxxxxxxxxxx",
"x-amz-id-2": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
"s3": {
"s3SchemaVersion": "1.0",
"configurationId": "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxxxxxxx",
"bucket": {
"name": "testing-process",
"ownerIdentity": {
"principalId": "xxxxxxxxxxxxxxx"
},
"arn": "arn:aws:s3:::testing-process"
},
"object": {
"key": "5a2a37db9b15036253a4336d/1kmultipayables_together_chunk_2.csv",
"size": 193,
"eTag": "0ae33a40954ee4c745ea39f7e5e3d830",
"sequencer": "005ADA554796220809"
}
}
}
]
}
exports.handler = (event, context, callback) => {
const request = event.Records[0].cf.request;
const headers = request.headers;
const origin = request.origin;
const client_IP = request.clientIp;
console.log(JSON.stringify(event));
//Setup the two different origins
const originA = "cloudfront-S3-origin1";
const originB = "Cloudfront-S3-origin2";
if (client_IP == "xx.xx.xx.xx") {
origin.s3.domainName = originA;
} else {
origin.s3.domainName = originB;
}
callback(null, request);
};
module.exports.handler(event, null, function (err, res) {
if (err) {
console.log(err);
} else {
console.log(res);
}
});````