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
• 14,970 points
97 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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
• 56,120 points

Related Questions In AWS

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 7, 2018 in AWS by sunshine
• 640 points
104 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
• 65,850 points
228 views
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
• 56,120 points
178 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.