0

error

I'm using lambda@edge + cloudfront to do some image resizes etc. My origin is S3 bucket.

ISSUE: When I try to call for an object inside s3 via cloudfront over browser I get the above error (picture). it even happens when I use just a test function(below).

how I call/query it: My s3 is set as origin, so I just use my cloudfront Domain Name d5hbjkkm17mxgop.cloudfront.net and add s3 path /my_folder/myimage.jpg

browser url used: d5hbjkkm17mxgop.cloudfront.net/my_folder/myimage.jpg

exports.handler = (event, context, callback) => {
    var request = event.Records[0].cf.request;
    console.log(event);
    console.log("\n\n\n");
    console.log(request);

    callback(null, request);

};

I'm pretty sure that request is an object - have no idea why is this happening. If testing in aws console all works - so it has to be an cloudfront/lambda interface error - because lambda is not even invoked (no new log entrie being generated).

I also have an access error from cloudfront:

2018-01-08  12:40:20    CDG50   855 62.65.189.38    GET d3h4fd56s4fs65d4f6somxgyh.cloudfront.net    /nv1_andrej_fake_space/98f741e0b87877c607a6ad0d2b8af7f3ba2f949d7788b07a9e89453043369196 502 -   Mozilla/5.0%2520(X11;%2520Ubuntu;%2520Linux%2520x86_64;%2520rv:57.0)%2520Gecko/20100101%2520Firefox/57.0    -   -   LambdaValidationError   usnOquwt7A0R7JkFD3H6biZp21dqnWwC5szU6tHxKxcHv5ZAU_g6cg==    d3hb8km1omxgyh.cloudfront.net   https   260 0.346   -   TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 LambdaValidationError   HTTP/2.0

Any ideas?

EDITED: semicolon

Yves M.
  • 29,855
  • 23
  • 108
  • 144
scagbackbone
  • 681
  • 1
  • 8
  • 20
  • The `CDG` in `CDG50` means you hit a CloudFront edge location near Paris -- CDG in the logs is a reference to [Charles de Gaulle Airport](https://en.m.wikipedia.org/wiki/Charles_de_Gaulle_Airport) -- so for this event, your Lambda logs in CloudWatch are probably going to be in Paris (or perhaps London, or Frankfurt), not in us-east-1. The logs are typically dropped in the nearest region to the edge serving each individual request. – Michael - sqlbot Jan 09 '18 at 02:41
  • Is this a viewer request, origin request, origin response, or viewer response trigger? – Michael - sqlbot Jan 09 '18 at 02:45
  • sorry I forgot to specify **origin request** trigger – scagbackbone Jan 09 '18 at 07:16
  • Also found some logs (in Frankfurt) however they're not much of a help. I can only see **request id**, start, end, and duration of request. – scagbackbone Jan 10 '18 at 09:15
  • Isn't there a syntax error at `console.log("\n\n\n") // missing semicolon here`? It's very critical that you show the actual code that is running. – Michael - sqlbot Jan 10 '18 at 11:49
  • Nope, it just gives me warning (tried with semicolon thou, but same result). It is an actual code that I'm trying. I wasn't sure if my prod code is bug free, so I made this easy function. Prod code not working, nor this easy function. Same error. – scagbackbone Jan 10 '18 at 12:06
  • Capture the log of an execution with just `console.log(event);` If the event payload isn't there, something is definitely wrong. Also check the configuration in the CloudFront console to be sure that the version number of the Lambda function (after `:` in the ARN) is correct. – Michael - sqlbot Jan 10 '18 at 12:12
  • if I execute it inside console without cloudfront (testing in console, with my test event) - I see it works correctly. However, as I said trying via cloudfront, when I grab logs from Frankfurt - where it eventually landed i only see id, start and end time, and request duration. ARN version number is correct. – scagbackbone Jan 10 '18 at 12:47
  • `console.log('hello, world');` Verify the basic functionality of the function and logging when invoked from CloudFront. It doesn't make sense that you see only start/end/duration. Also, the problem with testing in the console is that this only really tests that the Lambda function doesn't throw an exception -- the returned response isn't parsed for validity against what the CloudFront systems need to see as a response from the function invocation. – Michael - sqlbot Jan 10 '18 at 15:19
  • **same error** (I can't even see logs in Frankfurt for now (also checked London, Dublin, and Paris - nothing is there)) but maybe there is some time drift... – scagbackbone Jan 10 '18 at 16:23

1 Answers1

0

enter image description here

Do not forget to Publish new version of your Lambda. It is not sufficient to save it. Lambda that was last published is the one actually deployed, however you may have different code in aws console window.

EDIT: another gotcha - do not forget to change your function version in CloudFront settings. You have to select desired CF distribution that is bind to your Lambda. Choose that CF distribution, then go to behaviors, choose edit behaviors. Scroll down and last entry is Lambda Function Associations (see pic below)

enter image description here

Last number in Lambda Function ARN is the version number of deployed lambda.

scagbackbone
  • 681
  • 1
  • 8
  • 20