Use new CloudFormation support for Lambda@Edge to avoid duplicate CloudFront updates
See original GitHub issueAs mentioned in this discussion, CloudFormation support is now available (LambdaFunctionAssociation property).
Of course, this plugin is still super useful because it fixes the AssumeRolePolicy
Principal and the log group names & env variables problems, but since CloudFormation support is available we can now avoid the double CloudFront distribution update and define the trigger in serverless.yml
as follows:
resources:
Resources:
...
WebsiteDistribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
DefaultCacheBehavior:
...
LambdaFunctionAssociations:
- EventType: 'origin-response'
LambdaFunctionARN: XXX
The problem is that XXX
should contain the Function Version as well, and there doesn’t seem to be a way to easily reference it (CC @alexdebrie @pmuens).
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Deleting Lambda@Edge functions and replicas
You can delete a Lambda@Edge function only when the replicas of the function have been deleted by CloudFront. Replicas of a Lambda function...
Read more >Creating Lambda@Edge and Route 53 Resources with ...
Lambda@Edge allows us to run a function on our CloudFront edge nodes in ... Non-canonical URIs are redirected to prevent duplicate content ...
Read more >Amazon CloudFront - Developer Guide
For example, you can use IAM with CloudFront to control which users in your AWS account can create a new distribution or update...
Read more >Unable to add cloudfront as trigger to lambda function
In the CloudFront console, what do you see in the Behaviour tab of your distribution? You can update the ARN of the function...
Read more >Serving content only to logged-in users with CloudFront ...
A signed cookie protected CloudFront origin that uses the public key to verify signed cookies. A component that generates and returns signed ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@alexcasalboni - sorry for the delay on this. I’m actually working on a version 2.0 of the plugin that programmatically obtains the logical name to the
Lambda::FunctionVersion
resource and uses it as aRef
forLambdaFunctionARN
so that the plugin can directly modify the CloudFormation template to add the associations for you, thus allowing CloudFormation’s newfound support for Lambda@Edge to do all the heavy lifting for you. This will - as you mention - remove the need for the duplicate CloudFront deployment (and developers everywhere rejoice at the time savings!)cc @alexdebrie @pmuens
Yeah, we haven’t done any work to support simulating CloudFront events offline. That said, the format of CloudFront events is super simple, so it’s easy to write unit tests for your CloudFront-event-handling functions. That’s what we do. HTH