awslabs / aws-solutions-constructs

The AWS Solutions Constructs Library is an open-source extension of the AWS Cloud Development Kit (AWS CDK) that provides multi-service, well-architected patterns for quickly defining solutions
https://docs.aws.amazon.com/solutions/latest/constructs/
Apache License 2.0
1.19k stars 240 forks source link

SnsToSqs: There is already a Construct with name 'EncryptionKey' #1101

Closed fl0wo closed 2 months ago

fl0wo commented 2 months ago

I'm using SnsToSqs two times (more than one) with the same SNS (existingTopicObj) and a queueProps with visibilityTimeout 15min.

I also tried playing around with encryptionKeyProps but without luck.

Reproduction Steps

const s3tosns = new S3ToSns(stack, `${id}s3-to-sns`, {
        existingBucketObj: bucket,  // <-- third part bucket
        topicProps: {
            topicName: `${id}sns`,
            displayName: `${id}sns`,
        },
        s3EventFilters: [
            {
                prefix: prefixS3Files,
                suffix: suffixS3Files,
            }
        ],
        s3EventTypes: [
            EventType.OBJECT_CREATED
        ],
    });

   const sns2sqs = new SnsToSqs(stack, id + '_sns_to_sqs', {
        existingTopicObj: s3tosns.snsTopic,  // <-- previously generated topic
        queueProps: {
            visibilityTimeout: Duration.minutes(15),
        },
    });

Error Log

  throw new Error(`There is already a Construct with name '${childName}' in ${typeName}${name.length > 0 ? ' [' + name + ']' : ''}`);
        ^

Error: There is already a Construct with name 'EncryptionKey' in TradingResourcesStack [TradingResourcesTEST] at Node.addChild (/Users/xx/node_modules/constructs/src/construct.ts:447:13) at new Node (/Users/xx/node_modules/constructs/src/construct.ts:71:17) at new Construct (/Usersxx/node_modules/constructs/src/construct.ts:499:17) at new Resource (/Users/xx/node_modules/aws-cdk-lib/core/lib/resource.js:1:1309) at new KeyBase (/Users/xx/node_modules/aws-cdk-lib/aws-kms/lib/key.js:1:898) at new Key (/Users/flo/xx/node_modules/aws-cdk-lib/aws-kms/lib/key.js:1:7094) at Object.buildEncryptionKey (/Users/flo/xx/node_modules/@aws-solutions-constructs/aws-sns-sqs/node_modules/@aws-solutions-constructs/core/lib/kms-helper.ts:36:10) at new SnsToSqs (/Users/flo/xx/node_modules/@aws-solutions-constructs/aws-sns-sqs/lib/index.ts:137:32)

Environment


This is :bug: Bug Report

fl0wo commented 2 months ago

Update

Found a temporary workaround:


const encKey = new Key(stack, id + '_key', {
        enableKeyRotation: true,
        alias: `alias/${id}_key`,
        description: `Key for ${id}`,
        enabled: true
    });

    const sns2sqs = new SnsToSqs(stack, id + '_sns_to_sqs', {
        existingTopicObj: topic,
        queueProps: {
            visibilityTimeout: Duration.minutes(15),
        },
        encryptionKey: encKey
    });

Basically I create the encryptionKey. Am I missing something? I think the issue is the id of the Key.

biffgaut commented 2 months ago

Thanks for pointing this out - my first thought is this is on us and could be straightforward to fix. Let us dig into it, we'll have an hours/days/weeks level ETA shortly.

biffgaut commented 2 months ago

Can you doublecheck your CDK and Constructs versions? Solution Constructs v2.54.0 was built on CDK v2.130.0, so it requires CDK 2.130.0 or later and won't install on CDK 2.99.0 project. (could package.json say "^2.99.0" ?)

fl0wo commented 2 months ago

Hi @biffgaut thanks for the quick reply.

cdk --version
2.124.0 (build 4b6724c)

// package.json
"aws-cdk-lib": "^2.99.0",
"@aws-solutions-constructs/aws-s3-sns": "^2.54.0",
"@aws-solutions-constructs/aws-s3-sqs": "^2.54.0",
"@aws-solutions-constructs/aws-sns-lambda": "^2.54.0",
"@aws-solutions-constructs/aws-sns-sqs": "^2.54.0",
"@aws-solutions-constructs/aws-sqs-lambda": "^2.54.0",

Not sure if that's the reason.

biffgaut commented 2 months ago

The caret (^) indicates that more recent versions are OK. I'm pretty sure if you look at:

your-project/node_modules/aws-cdk-lib/package.json

that you will find that it has installed 2.130.0 or later

fl0wo commented 2 months ago

Yeah, my bad forgot to include ^

My aws-cdk-lib version is: 2.135.0

biffgaut commented 2 months ago

I believe v2.55.0 should address your issue.

biffgaut commented 2 months ago

(please reopen if the issue is not actually corrected)