2

I'm still very new to AWS so this may be wrong but it seems to my Cloudfront distribution is pointing to an old broken versions of my Lambda@Edge function.

I followed this tutorial to get my initial setup: https://aws.amazon.com/blogs/networking-and-content-delivery/resizing-images-with-amazon-cloudfront-lambdaedge-aws-cdn-blog/

It worked fine for weeks as I updated the Lambda functions to do exactly what I needed, all the way up to version 16 of the Origin Response function. However, when I created version 17 (to format .gif as .png) something broke. I rolled back to 16 and I was still getting a 503 error. I've since created quite a few new versions from rolling all the way back to creating new functions and my Origin Response is still throwing a 503 Error. https://d361pysytz4143.cloudfront.net/images/blackhat.png?d=200x200

I noticed my Cloudwatch for the Origin Response is constantly referencing version 17, no matter how many times I delete the log stack and/or publish a new Lambda function.

00:50:51
START RequestId: 6118af00-3d22-11e8-a163-5577c9775707 Version: 17
START RequestId: 6118af00-3d22-11e8-a163-5577c9775707 Version: 17
00:50:51
2018-04-11T00:50:51.179Z 6118af00-3d22-11e8-a163-5577c9775707 TypeError: Cannot read property 'status' of undefined at exports.handler.err (/var/task/index.js:19:51)
2018-04-11T00:50:51.179Z 6118af00-3d22-11e8-a163-5577c9775707 TypeError: Cannot read property 'status' of undefined at exports.handler.err (/var/task/index.js:19:51)

I made sure to a attach the Cloudfront to my newest Lambda function so it should be pointing the correct one but it isn't updating. The Viewer Request function is updating correctly if I switch versions.

What is going on, is there any cache or something I need to clear?

DasBeasto
  • 2,082
  • 5
  • 25
  • 65

2 Answers2

1

CloudFront needs versioned lambda to be attached to its events.

Which means every time you update the Lambda@edge code, you need to get its latest lambda and update it in the CloudFront.

There are ways to automate these manual steps depending on the way you have automated your AWS resource creation. (CloudFormation/CDK).

0

When using Origin response and Origin request triggers with lambda@edge, cloud front caches the response. So this could be probably serving the chached content. You can run an invalidation to the specific path you set the lambda@edge and check again. To learn more about invalidation refer this document https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Invalidation.html

dilantha111
  • 1,388
  • 1
  • 17
  • 19