I have a Cloudfront distribution with a default behavior and the following function association:
origin request: Lambda@Edge / arn:aws:lambda:us-east-1:...:function:*functionName*:4
I can see the CloudFront trigger in the triggers tab in my lambda function version 4:
Event type: origin-request
Include Body: Yes
Path pattern: *
Service principal: replicator.lambda.amazonaws.com
Statement ID: replicator.lambda.GetFunction
My function's code looks like this:
'use strict';
exports.handler = (event, context, callback) => {
console.log("context: ", context);
console.log("event: ", event);
I made a GET request to my Cloudfront distribution using the Distribution domain name and this is what I found in the logs using the AWS CLI:
2023-04-18T20:50:37.021Z e52078b4-2efa-40a8-9a28-51ed50ac0132 INFO event: {}
How can the event be empty here?
This is a two-fold answer.
us-east-1
while my execution region was us-east-2
), and the empty event log did not come from a proper execution of my lambda@edge function (I am not sure where they came from, maybe the initialization of the function).us-east-2
and the event
argument was properly passed.To allow the lambda function to create/write logs, I had to add the AWSLambdaEdgeExecutionRole
role to it (under lambda/configuration/permissions/execution role -> edit
), which should look like this:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": [
"arn:aws:logs:*:*:*"
]
}
]
}