lambda edge logs and invocation counts are not showing

0 votes

I have created the cloud front distribution and attached the lambda with the trigger

`Event type: viewer-requestPath pattern: something/index.html`

 Event type: origin-requestPath pattern: something/index.html

When i hit the endpoint it's redirecting to the page where i want to redirect, according to my lambda.

but i was not able to see my lambda logs in any region.

it was not showing the invocation count also.

Did anyone faced this issue ??

Here is my lambda code

'use strict';

exports.handler = (event, context, callback) => {
    /*
     * Generate HTTP redirect response with 302 status code and Location header.
     */
    console.log('event',event);
    const response = {
        status: '302',
        statusDescription: 'Found',
        headers: {
            location: [{
                key: 'Location',
                value: 'http://<domainname>/something/root.html',
            }],
        },
    };
    callback(null, response);
};

Sep 10, 2018 in AWS by bug_seeker
• 15,510 points
2,450 views

1 answer to this question.

0 votes

Modify your function like this:

const response = {
        status: '302',
        statusDescription: 'Found',
        headers: {
            location: [{
                key: 'Location',
                value: 'http://<domainname>/something/root.html',
            }],
            'x-lae-region': [ { key: 'x-lae-region', value: process.env.AWS_REGION } ],
        },
    };

What this does is capture the region where your lambda function is running -- it will show us-east-1 during test, but show an accurate value once deployed.

Responses captured by your browser, curl, etc., will now include x-lae-region: some-aws-region to indicate the region linked to the edge where your specific requests are being handled. Check the logs for that specific region -- you should see logs and invocations there.

Also note that for an Origin Request (but not Viewer Request) trigger, CloudFront caches the response generated by Lambda, so the function will only be invoked when there is a cache miss. If CloudFront has cached the response, the trigger will not fire -- the cached response is served without contacting the origin. If you make this function live and you don't see the change in the responses, then you are almost certainly looking at cached responses, and will want to do an invalidation.

answered Sep 10, 2018 by Priyaj
• 58,020 points

Related Questions In AWS

0 votes
1 answer
0 votes
1 answer

What are the practical differences between AWS EFS, EBS and S3?

EFS  It is a file storage connected with ...READ MORE

answered Aug 8, 2018 in AWS by sunshine
• 1,300 points
1,645 views
+5 votes
2 answers

AWS EC2 Instances are not getting to internet access

Check your VPC settings, whether you are ...READ MORE

answered Oct 16, 2018 in AWS by Omkar
• 69,220 points
13,245 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
+3 votes
3 answers
0 votes
1 answer

Error creating Key Pair: You are not authorized to perform this operation

Try adding AmazonEC2FullAccess policy. If you are not sure how ...READ MORE

answered Sep 19, 2018 in AWS by Priyaj
• 58,020 points
5,724 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP