How to create a Lamda@Edge from the command line?

Viewed 482

Is there a way to create a Lambda@Edge from the command line? Or is there a way to take an existing lambda and deploy it to cloudfront from the command line?

I've looked here: aws lambda ? and here: aws cloudfront ?

The only thing that looks remotely useful is update-distribution.

1 Answers

You've already found it- although I'll grant you that it's pretty arduous.

aws cloudfront update-distribution includes the array key LambdaFunctionAssociations, which allows you to link existing lambdas (by LambdaFunctionARN) to various cache responses.

More information here: https://docs.aws.amazon.com/cli/latest/reference/cloudfront/update-distribution.html

Unfortunately, as seems to be the case with all of cloudfront, there's no helper commands to just add/remove lambdas.

If you're scripting you might want to look at get-distribution which allows you to at least pre-populate most of the distribution configuration from whatever you've set up in the console; rather than learning everything from scratch.

This document might also be helpful for you: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/distribution-overview-required-fields.html as it discusses what information you have to provide to the distribution operation commands.

Related