0
votes

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.

1
You cannot have a 30s timeout. Maximum is 5. Lambda@edge also as a memory limit of 128m. - Gianluca Mereu

1 Answers

0
votes

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}