Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(aws-ec2): Cannot create to InitFiles with same target file name #25105

Closed
bpauwels opened this issue Apr 13, 2023 · 4 comments
Closed

(aws-ec2): Cannot create to InitFiles with same target file name #25105

bpauwels opened this issue Apr 13, 2023 · 4 comments
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud p2

Comments

@bpauwels
Copy link

bpauwels commented Apr 13, 2023

Describe the bug

Opening a new bug report for an already reported bug: #16891

Naming collision of InitFile constructs for multiple ec2 instances defined in the same stack definition when using the fromAsset or fromSource methods. Affected file: https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/aws-ec2/lib/cfn-init-elements.ts. Cause is most likely due to the underlying InitFile fromAsset and fromSource methods creating an s3 asset with interpolated id of ${targetFileName}Asset.

This bug just occurred to me again. I think it should not be closed until fixed.

Expected Behavior

One can create as many InitFiles as wanted with the same target file names

Current Behavior

You cannot create more than one InitFile with the same target file name

Reproduction Steps

Create more than one InitFile with the same target file name

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.67.0

Framework Version

No response

Node.js Version

16.19.1

OS

amazon linux 2

Language

Typescript, Python, .NET, Java, Go

Language Version

No response

Other information

No response

@bpauwels bpauwels added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 13, 2023
@github-actions github-actions bot added the @aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud label Apr 13, 2023
@pahud
Copy link
Contributor

pahud commented Apr 17, 2023

Thank you for your report. Can you share a little CDK sample that we can quickly reproduce and verify it in our account?

@pahud pahud added needs-reproduction This issue needs reproduction. investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed needs-triage This issue or PR still needs to be triaged. bug This issue is a bug. labels Apr 17, 2023
@pahud pahud self-assigned this Apr 17, 2023
@bpauwels
Copy link
Author

Sure,

import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import {Vpc, Instance, InstanceType, InstanceClass, InstanceSize, AmazonLinuxImage,
  AmazonLinuxGeneration, CloudFormationInit, InitConfig, InitFile} from 'aws-cdk-lib/aws-ec2';

export class CdkIssue25105Stack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const vpc = new Vpc(this, "vpc");

    new Instance(this, "FirstInstance", {
      vpc,
      instanceType:
        InstanceType.of(InstanceClass.T3A, InstanceSize.MICRO),
      machineImage: new AmazonLinuxImage({
        generation: AmazonLinuxGeneration.AMAZON_LINUX_2,
      }),
      init: CloudFormationInit.fromConfigSets({
        configSets: {
          default: ["default"],
        },
        configs: {
          default: new InitConfig([
            InitFile.fromAsset(
              "/target/path/config.json",
              "configFileForFirstInstance.json"
            )
          ])
        },
      })
    });

    new Instance(this, "SecondInstance", {
      vpc,
      instanceType:
        InstanceType.of(InstanceClass.T3A, InstanceSize.MICRO),
      machineImage: new AmazonLinuxImage({
        generation: AmazonLinuxGeneration.AMAZON_LINUX_2,
      }),
      init: CloudFormationInit.fromConfigSets({
        configSets: {
          default: ["default"],
        },
        configs: {
          default: new InitConfig([
            InitFile.fromAsset(
              "/target/path/config.json",
              "configFileForSecondInstance.json"
            )
          ])
        },
      })
    });

  }
}

If I run cdk synth with this, I see the following error:

/path/to/cdk/project/node_modules/constructs/src/construct.ts:403
      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 '--target--path--config.jsonAsset' in CdkIssue25105Stack [CdkIssue25105Stack]
...

@peterwoodworth
Copy link
Contributor

Thanks @bpauwels, I'm going to close this and reopen the original issue, as well as provide the context you've been able to provide to us 🙂

@github-actions
Copy link

github-actions bot commented May 1, 2023

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@pahud pahud removed investigating This issue is being investigated and/or work is in progress to resolve the issue. needs-reproduction This issue needs reproduction. labels Aug 12, 2024
@pahud pahud removed their assignment Aug 12, 2024
@pahud pahud added the p2 label Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud p2
Projects
None yet
Development

No branches or pull requests

3 participants