Skip to content

Conversation

@danielcondemarin
Copy link
Contributor

@danielcondemarin danielcondemarin commented Aug 26, 2019

Adds support for CloudFront lambda event triggers:

For example:

# serverless.yml

distribution:
  component: '@serverless/aws-cloudfront'
  inputs:
    origins:
      - url: https://sampleorigin.com
        pathPatterns:
          /sample/path:
            ttl: 10
            lambda@edge:
              viewer-request: arn:aws:lambda:us-east-1:123:function:myFunc:5 # lambda ARN including version

Event types supported: viewer-request | origin-request | viewer-response | origin-response

https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-cloudfront-trigger-events.html

In future you may want to consider provisioning the Lambda as part of the aws-cloudfront component. That could be another iteration of the API, for example by setting an object rather than the ARN string:

lambda@edge:
     viewer-request:
       code: ./edge-src
       handler: ./my-handler.js

@danielcondemarin danielcondemarin marked this pull request as ready for review August 26, 2019 20:17
Copy link
Member

@eahefnawy eahefnawy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @danielcondemarin ... I've added some comments

/sample/path:
ttl: 10
lambda@edge:
viewer-request: arn:aws:lambda:us-east-1:123:function:myFunc:version # lambda ARN including version
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the version a strict requirement for Lambda@Edge? I don't think we support versioning in our lambda component 🤔 ... In that case, this component wouldn't be composable with a lambda/function component cause they output a simple versionless ARN.

This effectively means that users of this component could only use it with an already deployed lambda via another tool, which kinda defeats the purpose of the whole thing. What you think? 🤔

Copy link
Contributor Author

@danielcondemarin danielcondemarin Aug 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately it must be the ARN of a function version and $LATEST can't be used either. How difficult would it be to add versioning onto the aws-lambda component? Or maybe a higher level component that uses aws-lambda but also manages versioning?

@eahefnawy eahefnawy self-requested a review August 27, 2019 12:51
@eahefnawy eahefnawy merged commit c139495 into serverless-components:master Aug 29, 2019
thiagozf pushed a commit to thiagozf/aws-cloudfront that referenced this pull request Apr 28, 2020
…lambda-at-edge-support

Add lambda at edge support
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants