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) ?