aws lambda: how to get console.log logs from real request (not test)?












0















I've read this doc: https://docs.aws.amazon.com/en_us/lambda/latest/dg/nodejs-prog-model-logging.html and made this lambda:



exports.handler = async (event) => {
// TODO implement
// const response = {
// statusCode: 200,
// body: JSON.stringify('Hello from Lambda!'),
// };
console.log(123321);
console.log(event.Records[0].cf.response);
console.log(event.Records[0].cf.request);
console.log(JSON.stringify(event.Records[0].cf));
console.log(event);
console.log(arguments);

//Get contents of response
const response = event.Records[0].cf.response;
//Return modified response

return response;
};


It works (logs sends to CloudWatch) when I use "test" with fake model, but when I add CloudFront trigger and send request logs isn't send to any CloudWatch.



Lambda function configuration




  1. how to get real (from production) event object from lambda

  2. how to send/get logs from lambda which triggers by CloudFront?










share|improve this question

























  • Is your lambda getting called at all? I mean, do you see your other console.logs in CloudWatch when you are using CloudFront?

    – AlexK
    Nov 20 '18 at 12:56











  • @TenorFlyy, yes it called, because I see response in url xxx.cloudfront.net/test1.html. And I don't have any logs by calling it not with "Test" button.

    – MixerOID
    Nov 20 '18 at 12:58











  • No, I mean when it is behind CloudFront, does it get called then. I understand it is getting called when testing.

    – AlexK
    Nov 20 '18 at 12:59











  • @TenorFlyy now to check it?

    – MixerOID
    Nov 20 '18 at 13:01











  • When you try to call the lambda through CloudFront, it should log something, if it doesn't, then it isn't even being called. In order to make it easier and clear for debugging, change the code, e.g. add another console.log and save it, so next time your lambda gets called it will create new CloudWatch Log Stream. If no stream is created, then lambda wasn't called.

    – AlexK
    Nov 20 '18 at 13:04
















0















I've read this doc: https://docs.aws.amazon.com/en_us/lambda/latest/dg/nodejs-prog-model-logging.html and made this lambda:



exports.handler = async (event) => {
// TODO implement
// const response = {
// statusCode: 200,
// body: JSON.stringify('Hello from Lambda!'),
// };
console.log(123321);
console.log(event.Records[0].cf.response);
console.log(event.Records[0].cf.request);
console.log(JSON.stringify(event.Records[0].cf));
console.log(event);
console.log(arguments);

//Get contents of response
const response = event.Records[0].cf.response;
//Return modified response

return response;
};


It works (logs sends to CloudWatch) when I use "test" with fake model, but when I add CloudFront trigger and send request logs isn't send to any CloudWatch.



Lambda function configuration




  1. how to get real (from production) event object from lambda

  2. how to send/get logs from lambda which triggers by CloudFront?










share|improve this question

























  • Is your lambda getting called at all? I mean, do you see your other console.logs in CloudWatch when you are using CloudFront?

    – AlexK
    Nov 20 '18 at 12:56











  • @TenorFlyy, yes it called, because I see response in url xxx.cloudfront.net/test1.html. And I don't have any logs by calling it not with "Test" button.

    – MixerOID
    Nov 20 '18 at 12:58











  • No, I mean when it is behind CloudFront, does it get called then. I understand it is getting called when testing.

    – AlexK
    Nov 20 '18 at 12:59











  • @TenorFlyy now to check it?

    – MixerOID
    Nov 20 '18 at 13:01











  • When you try to call the lambda through CloudFront, it should log something, if it doesn't, then it isn't even being called. In order to make it easier and clear for debugging, change the code, e.g. add another console.log and save it, so next time your lambda gets called it will create new CloudWatch Log Stream. If no stream is created, then lambda wasn't called.

    – AlexK
    Nov 20 '18 at 13:04














0












0








0








I've read this doc: https://docs.aws.amazon.com/en_us/lambda/latest/dg/nodejs-prog-model-logging.html and made this lambda:



exports.handler = async (event) => {
// TODO implement
// const response = {
// statusCode: 200,
// body: JSON.stringify('Hello from Lambda!'),
// };
console.log(123321);
console.log(event.Records[0].cf.response);
console.log(event.Records[0].cf.request);
console.log(JSON.stringify(event.Records[0].cf));
console.log(event);
console.log(arguments);

//Get contents of response
const response = event.Records[0].cf.response;
//Return modified response

return response;
};


It works (logs sends to CloudWatch) when I use "test" with fake model, but when I add CloudFront trigger and send request logs isn't send to any CloudWatch.



Lambda function configuration




  1. how to get real (from production) event object from lambda

  2. how to send/get logs from lambda which triggers by CloudFront?










share|improve this question
















I've read this doc: https://docs.aws.amazon.com/en_us/lambda/latest/dg/nodejs-prog-model-logging.html and made this lambda:



exports.handler = async (event) => {
// TODO implement
// const response = {
// statusCode: 200,
// body: JSON.stringify('Hello from Lambda!'),
// };
console.log(123321);
console.log(event.Records[0].cf.response);
console.log(event.Records[0].cf.request);
console.log(JSON.stringify(event.Records[0].cf));
console.log(event);
console.log(arguments);

//Get contents of response
const response = event.Records[0].cf.response;
//Return modified response

return response;
};


It works (logs sends to CloudWatch) when I use "test" with fake model, but when I add CloudFront trigger and send request logs isn't send to any CloudWatch.



Lambda function configuration




  1. how to get real (from production) event object from lambda

  2. how to send/get logs from lambda which triggers by CloudFront?







amazon-web-services amazon-cloudfront amazon-cloudwatch






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 12:42







MixerOID

















asked Nov 20 '18 at 12:35









MixerOIDMixerOID

945823




945823













  • Is your lambda getting called at all? I mean, do you see your other console.logs in CloudWatch when you are using CloudFront?

    – AlexK
    Nov 20 '18 at 12:56











  • @TenorFlyy, yes it called, because I see response in url xxx.cloudfront.net/test1.html. And I don't have any logs by calling it not with "Test" button.

    – MixerOID
    Nov 20 '18 at 12:58











  • No, I mean when it is behind CloudFront, does it get called then. I understand it is getting called when testing.

    – AlexK
    Nov 20 '18 at 12:59











  • @TenorFlyy now to check it?

    – MixerOID
    Nov 20 '18 at 13:01











  • When you try to call the lambda through CloudFront, it should log something, if it doesn't, then it isn't even being called. In order to make it easier and clear for debugging, change the code, e.g. add another console.log and save it, so next time your lambda gets called it will create new CloudWatch Log Stream. If no stream is created, then lambda wasn't called.

    – AlexK
    Nov 20 '18 at 13:04



















  • Is your lambda getting called at all? I mean, do you see your other console.logs in CloudWatch when you are using CloudFront?

    – AlexK
    Nov 20 '18 at 12:56











  • @TenorFlyy, yes it called, because I see response in url xxx.cloudfront.net/test1.html. And I don't have any logs by calling it not with "Test" button.

    – MixerOID
    Nov 20 '18 at 12:58











  • No, I mean when it is behind CloudFront, does it get called then. I understand it is getting called when testing.

    – AlexK
    Nov 20 '18 at 12:59











  • @TenorFlyy now to check it?

    – MixerOID
    Nov 20 '18 at 13:01











  • When you try to call the lambda through CloudFront, it should log something, if it doesn't, then it isn't even being called. In order to make it easier and clear for debugging, change the code, e.g. add another console.log and save it, so next time your lambda gets called it will create new CloudWatch Log Stream. If no stream is created, then lambda wasn't called.

    – AlexK
    Nov 20 '18 at 13:04

















Is your lambda getting called at all? I mean, do you see your other console.logs in CloudWatch when you are using CloudFront?

– AlexK
Nov 20 '18 at 12:56





Is your lambda getting called at all? I mean, do you see your other console.logs in CloudWatch when you are using CloudFront?

– AlexK
Nov 20 '18 at 12:56













@TenorFlyy, yes it called, because I see response in url xxx.cloudfront.net/test1.html. And I don't have any logs by calling it not with "Test" button.

– MixerOID
Nov 20 '18 at 12:58





@TenorFlyy, yes it called, because I see response in url xxx.cloudfront.net/test1.html. And I don't have any logs by calling it not with "Test" button.

– MixerOID
Nov 20 '18 at 12:58













No, I mean when it is behind CloudFront, does it get called then. I understand it is getting called when testing.

– AlexK
Nov 20 '18 at 12:59





No, I mean when it is behind CloudFront, does it get called then. I understand it is getting called when testing.

– AlexK
Nov 20 '18 at 12:59













@TenorFlyy now to check it?

– MixerOID
Nov 20 '18 at 13:01





@TenorFlyy now to check it?

– MixerOID
Nov 20 '18 at 13:01













When you try to call the lambda through CloudFront, it should log something, if it doesn't, then it isn't even being called. In order to make it easier and clear for debugging, change the code, e.g. add another console.log and save it, so next time your lambda gets called it will create new CloudWatch Log Stream. If no stream is created, then lambda wasn't called.

– AlexK
Nov 20 '18 at 13:04





When you try to call the lambda through CloudFront, it should log something, if it doesn't, then it isn't even being called. In order to make it easier and clear for debugging, change the code, e.g. add another console.log and save it, so next time your lambda gets called it will create new CloudWatch Log Stream. If no stream is created, then lambda wasn't called.

– AlexK
Nov 20 '18 at 13:04












1 Answer
1






active

oldest

votes


















1














Due to Lambda being triggered by CloudFront, it now becomes a Lambda@Edge, so the CloudWatch Log streams are created in the region where the Lambda instance is called(that's decided by CloudFront).



So following the AWS Lambda@Edge Docs for Troubleshooting, the specific region could be easily determined with the provided shell script.



You can switch the region using dropdown at the header:
enter image description here






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53393121%2faws-lambda-how-to-get-console-log-logs-from-real-request-not-test%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Due to Lambda being triggered by CloudFront, it now becomes a Lambda@Edge, so the CloudWatch Log streams are created in the region where the Lambda instance is called(that's decided by CloudFront).



    So following the AWS Lambda@Edge Docs for Troubleshooting, the specific region could be easily determined with the provided shell script.



    You can switch the region using dropdown at the header:
    enter image description here






    share|improve this answer






























      1














      Due to Lambda being triggered by CloudFront, it now becomes a Lambda@Edge, so the CloudWatch Log streams are created in the region where the Lambda instance is called(that's decided by CloudFront).



      So following the AWS Lambda@Edge Docs for Troubleshooting, the specific region could be easily determined with the provided shell script.



      You can switch the region using dropdown at the header:
      enter image description here






      share|improve this answer




























        1












        1








        1







        Due to Lambda being triggered by CloudFront, it now becomes a Lambda@Edge, so the CloudWatch Log streams are created in the region where the Lambda instance is called(that's decided by CloudFront).



        So following the AWS Lambda@Edge Docs for Troubleshooting, the specific region could be easily determined with the provided shell script.



        You can switch the region using dropdown at the header:
        enter image description here






        share|improve this answer















        Due to Lambda being triggered by CloudFront, it now becomes a Lambda@Edge, so the CloudWatch Log streams are created in the region where the Lambda instance is called(that's decided by CloudFront).



        So following the AWS Lambda@Edge Docs for Troubleshooting, the specific region could be easily determined with the provided shell script.



        You can switch the region using dropdown at the header:
        enter image description here







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 20 '18 at 13:51

























        answered Nov 20 '18 at 13:44









        AlexKAlexK

        869513




        869513
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53393121%2faws-lambda-how-to-get-console-log-logs-from-real-request-not-test%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Guess what letter conforming each word

            Port of Spain

            Run scheduled task as local user group (not BUILTIN)