0

I'm a little lost here, I'm trying to deploy a simple function that uses Lambda@edge but I having some problems creating the Cloudfront resource and attaching that CF to the lambda function.

Here is an example of the serverless.yml

service: some-service

plugins:
  - serverless-pseudo-parameters

provider:
  name: aws
  runtime: nodejs10.x
  stage: ${env:STAGE}
  region: us-east-1

resources:
  - ${file(./resources.yml):resources}

functions:
  - ${file(./lambda-at-edge/function.yml):functions}

The function definition:

functions:
  lambda-at-edge-function:
    description: Lambda at edge authentication
    handler: serverless/index.handler
    events:
      - cloudFront:
        eventType: viewer-response
        origin: s3://some.s3.amazonaws.com/

One thing if I don't define the Cloudfront resources it's not created and If I define the resource and attach that to the serverless definition it's create the resource, but then I don' know how to attach that cloudfront to the function.

Edit:

So I'm deploying everithing with sls deploy, so my question now is how can I attach the funtion name to be used in LambdaFunctionAssociations from cloudfront distribution.

Diego
  • 493
  • 1
  • 9
  • 26

1 Answers1

0

When using Lambda@edge you have to respect the limits. Check them out here: Requirements and Restrictions on Lambda Functions

This should work:

service: some-service

plugins:
  - serverless-pseudo-parameters

provider:
  name: aws
  runtime: nodejs10.x
  stage: ${env:STAGE}
  region: us-east-1
  memorySize: 128
  timeout: 5

resources:
  - ${file(./resources.yml):resources}

functions:
  - ${file(./lambda-at-edge/function.yml):functions}
Gianluca Mereu
  • 300
  • 1
  • 4
  • Thanks for your reply, and yes I already reviewed the lambda@edge limits, I forgot to remove that. My original question was that I was having some problems using the builtin serverless event for CloudFront. I end up using this plugin since I couldn't make work the builtin event for functions. "@silvermine/serverless-plugin-cloudfront-lambda-edge": "^2.1.1". Do you have any example using that event for serverless? – Diego Mar 23 '20 at 12:33
  • I am not sure to understand your original problem sorry. The problem with the memory blocked me when I was on it. But for my usecase I had to associate the lambda to the Clodufront manullay in the Cloudformation definition so I am not using the plugin. I can share that if you're interested. – Gianluca Mereu Mar 24 '20 at 11:21