1
votes

I'm using cdk to add a lambda on edge to a cloudfront web distribution (details see code below).

const edgeFunction = new cloudfront.experimental.EdgeFunction(this, 'LambdaOnEdgeAuthFunction', {
   runtime: lambda.Runtime.NODEJS_12_X,
   handler: 'index.handler',
   code: lambda.Code.fromAsset('lambda/auth'),
   description: `Generated on: ${new Date().toISOString()}`
});

// A numbered version to give to cloudfront
const egdeFunctionVersion = new lambda.Version(this, "edgeVersion", {
   lambda: edgeFunction,
   description: `Generated on: ${new Date().toISOString()}`, //adding this did not create new version
});

Adding the function to my cloudfront webdistribution

// CloudFront distribution that provides HTTPS and used the key pair above
const distribution = new cloudfront.CloudFrontWebDistribution(this, 'SiteDistribution', {
originConfigs: [{
     s3OriginSource: {
       /* my s3 bucket*/
     },
     behaviors: [{
        isDefaultBehavior: true,
        lambdaFunctionAssociations: [{
          eventType: cloudfront.LambdaEdgeEventType.ORIGIN_REQUEST,
          lambdaFunction: egdeFunctionVersion
          }]
 /*... end of declaration ...*/

However, deploying the changes via cdk deploy --all always throws the same exception:

A version for this Lambda function exists ( 1 ). Modify the function to create a new version.

I removed all existing lambda function from my account and removed all lambda functions from my existing contributions. But it did not solve the issue. I also applied the fix that is mentioned here with the same result.

Can you help me with a create a new version or to find and delete the lambda version I have to delete (as said no function does exist in the aws account so far) ?

1

1 Answers

1
votes

AWS Lambda@Edge functions are ONLY deployed in us-east-1 region. Reference

So you can do 2 things. Try cdk destroy and deploy again to see if it fixes the problem.

Alternatively create a new version of lambda function and try again. Reference for version of Lambda function is here

Verify your Lambda function is in us-east-1 region to verify the root cause of issue.