serverless-operations / serverless-lambda-edge-pre-existing-cloudfront

A Serverless Framework plugin to create your Lambda@Edge against a pre-existing CloudFront.
Other
56 stars 17 forks source link

Missing permission lambda:EnableReplication when trying to deploy a Lambda@Edge #36

Open pherrymason opened 2 years ago

pherrymason commented 2 years ago

As the title says, I'm trying to deploy a Lambda@Edge, and I'm getting the following error:

ServerlessError: Lambda@Edge cannot enable replication for the specified Lambda function.
Update the IAM policy to add permission: lambda:EnableReplication* for 
resource: arn:aws:lambda:us-east-1:xxxxxxxxxx:function:XXXZZZZYYYYY:2 and try again.

There's little documentation about this error in internet, but the little I've found pointed to add a permission to the lambda function:

EdgeAuthEnableReplicationPermission:
      Type: 'AWS::Lambda::Permission'
      Properties:
        Action: "lambda:EnableReplication"
        FunctionName: "XXXZZZZYYYYY"
        Principal: "*"

This is my serverless.yml file:

service: lambda-test
  useDotenv: true
  provider:
    name: aws
    region: 'us-east-1'
    stage: 'sbx'
    versionFunctions: true

  plugins:
    - serverless-lambda-edge-pre-existing-cloudfront

  functions:
    countryResolver:
      name: 'XXXZZZZYYYYY'
      handler: src/index.js
      events:
      - preExistingCloudFront:
          distributionId: 'zzzzzzzz'
          eventType: 'origin-request'
          pathPattern: '*'
          includeBody: false
          stage: sbx
  resources:
    Resources:
      IamRoleLambdaExecution:
        Type: "AWS::IAM::Role"
        Properties:
          AssumeRolePolicyDocument:
            Version: '2012-10-17'
            Statement:
              - Effect: Allow
                Principal:
                  Service:
                    - lambda.amazonaws.com
                    - edgelambda.amazonaws.com
                Action: sts:AssumeRole
      EdgeAuthEnableReplicationPermission:
        Type: 'AWS::Lambda::Permission'
        Properties:
          Action: "lambda:EnableReplication"
          FunctionName: "XXXZZZZYYYYY"
          Principal: "*"
mohrash92 commented 2 months ago

I am running into the exact same problem, any luck?