Lockless
Lockless

Reputation: 497

Can you modify the URI on an AWS CloudFront event with Lambda@Edge in a language other than Javascript?

I'm trying to do some AB testing and inserting a Lambda in our AWS CloudFront setup seems a good way to do it. My company has problem with NodeJs. They were burned by some old devs using it and have banned its use.

Lambda supports a bunch of languages so no big deal. But after some research and looking at the source. Only the Javascript seems to be able to interact with CloudFront events and passing the request forward. All the libraries for other languages seem to only emit response events and don't allow for the passing forward of the request after modification.

Am I missing something or is this scenario only supported with JS?

Upvotes: 0

Views: 268

Answers (1)

Michael - sqlbot
Michael - sqlbot

Reputation: 179114

Lambda@Edge supports only Node.js runtimes.

You must create functions with the nodejs6.10 or nodejs8.10 runtime property.

https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-requirements-limits.html#lambda-requirements-lambda-function-configuration

Your observation about other runtimes "seem to only emit response events and don't allow for the passing forward of the request after modification" isn't really an accurate representation of what happens. Node.js doesn't do any special "passing forward" magic. CloudFront interprets the response payload from the Lambda function to determine how to proceed. If it's a request trigger and the Lambda function returns something structured like a request, then CloudFront continues processing the request, as modified. Otherwise CloudFront interprets the response payload as a response to be returned to the caller. Everything is handled by CloudFront's interpretation of what the Lambda function returns.

Any Lambda runtime could theoretically have accomplished the same purpose, but Lambda@Egde was designed for -- and currently only supports -- the Node.js runtimes, which are lightweight and fast, as they need to be, because CloudFront invokes the trigger function synchronously and then blocks (suspends its own processing) while waiting for the function to return.

Upvotes: 2

Related Questions