I have a Cloudfront distribution pointing at a custom url. In that distribution, I have setup 2 lambda function associations. 1 on the Cloudfront event of viewer-request to query parameter store and redirect to the correct url The other on the Cloudfront event of origin-response to gather response stats from the call.
The viewer-reqest function is as follows - note dummy urls for purpose of question
exports.handler = async (event, context) => {
const origin = "main";
const primaryUrl = "https://www.google.com";
const drUrl = "https://www.yahoo.com";
let url = primaryUrl;
if (origin != "main") {
url = drUrl;
} else {
url = primaryUrl;
}
const response = {
status: '302',
statusDescription: 'Found',
headers: {
location: [{
key: 'Location',
value: url,
}],
},
};
return response;
};
The origin response lambda is very simple for now var AWS = require('aws-sdk'); AWS.config.update({ region: 'us-east-1' }); var cloudwatch = new AWS.CloudWatch();
exports.handler = async (event, context) => {
console.log("Custom Metrics Event");
console.log(JSON.stringify(event));
const response = {
status: '200',
};
return response;
};
When I call the cloudfront distribution domain, the viewer-request lambda@edge kicks in but the origin-response lambda does not trigger and I see nothing in cloudwatch If I remove the viewer-request lambda - the origin-response lambda does trigger
Am I doing anything wrong here or does anyone have any recommendations?
Thank you Damien
viewer-request
Lambda does it work? – Chris Williams