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

Multiple Config rules using same Lambda returns 'There is already a Construct' name error #9756

Closed
mcmluk123 opened this issue Aug 17, 2020 · 3 comments
Assignees
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@mcmluk123
Copy link

mcmluk123 commented Aug 17, 2020

I am trying to deploy multiple custom configuration rules which use the same lambda, but different input parameters. However, I get a duplicate construct error:

There is already a Construct with name 'Permission' in Function [amiComplianceFn]

Reproduction Steps

    //Create AMI compliance Lambda
    const amiComplianceFn = new lambda.Function(this, 'amiComplianceFn',{
      runtime: lambda.Runtime.NODEJS_10_X,  // execution environment
      code: lambda.Code.fromAsset('lambda'),  // code loaded from "lambda" directory
      handler: 'ami_lambda.handler',  // file is "report", function is "handler"
      timeout: cdk.Duration.seconds(15)
    });
    //Add Managed policy to Lambda function to allow query aws config amd EC2
    amiComplianceFn.role?.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('AmazonEC2FullAccess'));
    const amiCompliance = new awscfg.CustomRule(this, 'amiCompliance', {
      lambdaFunction: amiComplianceFn,
      configRuleName: `ampc-ami-30-days`,
      inputParameters: { amiExpiryDay: 30 },
      configurationChanges: true
    });
    amiCompliance.scopeToResources('AWS::EC2::Instance');

    const amiCompliance15 = new awscfg.CustomRule(this, 'amiCompliance15', {
      lambdaFunction: amiComplianceFn,
      configRuleName: `ampc-ami-15-days`,
      inputParameters: { amiExpiryDay: 15 },
      configurationChanges: true
    });
    amiCompliance15.scopeToResources('AWS::EC2::Instance');
    
    const amiCompliance25 = new awscfg.CustomRule(this, 'amiCompliance25', {
      lambdaFunction: amiComplianceFn,
      configRuleName: `ampc-ami-25-days`,
      inputParameters: { amiExpiryDay: 25 },
      configurationChanges: true
    });
    amiCompliance25.scopeToResources('AWS::EC2::Instance');

What did you expect to happen?

Multiple config rules created using the same lambda

What actually happened?

Error regarding duplicate construct :

There is already a Construct with name 'Permission' in Function [amiComplianceFn]

Environment

  • CLI Version : 1.53.0 (build 6c326cb)
  • Framework Version:
  • Node.js Version: v12.18.2
  • OS :
  • Language (Version):

Other


This is 🐛 Bug Report

@mcmluk123 mcmluk123 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Aug 17, 2020
@SomayaB SomayaB added the @aws-cdk/aws-lambda Related to AWS Lambda label Aug 18, 2020
@SomayaB
Copy link
Contributor

SomayaB commented Aug 18, 2020

Related to #8553 #4459

@nija-at
Copy link
Contributor

nija-at commented Sep 2, 2020

This should be fixed in 0fc5899 which has been released in 1.61.0.

Please upgrade to this version and see if this fixes the issue for you.

@nija-at nija-at added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Sep 2, 2020
@SomayaB SomayaB removed the needs-triage This issue or PR still needs to be triaged. label Sep 3, 2020
@github-actions
Copy link

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Sep 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

3 participants