question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use new CloudFormation support for Lambda@Edge to avoid duplicate CloudFront updates

See original GitHub issue

As 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:closed
  • Created 6 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
jthomersoncommented, Apr 10, 2018

@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 a Ref for LambdaFunctionARN 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

1reaction
jthomersoncommented, May 6, 2019

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found