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

ec2: Cannot configure 'securityGroups' without configuring a VPC #28572

Closed
mbhaalalhhaexchange opened this issue Jan 4, 2024 · 4 comments
Closed
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/medium Medium work item – several days of effort p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@mbhaalalhhaexchange
Copy link

Status

Investigating (Default)

What is the issue?

I have migrated my CDK code from CDK V1 to CDK V2 and installed the aws-cdk-lib package and made the changes into the files for imports.

Now, I am synthesizing my stack with cdk synth command and my stack is failed with Cannot configure 'securityGroups' without configuring a VPC error message.

Earlier with AWS CDK V1, I was not getting this type of bug, but it is started after the CDK V2 migration.

Error message

Cannot configure 'securityGroups' without configuring a VPC

What is the impact?

Earlier with AWS CDK V1 @aws-cdk package this issue was not coming but when code is migrated to aws-cdk-lib this issue has been started.
Actually , we are creating the lambda Cloudwatch logs for which we are putting it in security group but we do not want to assign VPC to it.

Workaround

No response

Who is affected?

Our entire CDK stack is impacted due to this and we are not able to migrate our code from AWS CDK V1 to AWS CDK V2 version.

How do I resolve this?

TBD

Related issues

No response

@mbhaalalhhaexchange mbhaalalhhaexchange added management/tracking Issues that track a subject or multiple issues p0 labels Jan 4, 2024
@pahud
Copy link
Contributor

pahud commented Jan 4, 2024

Can you share code snippets for that?

@pahud pahud changed the title ❗ aws-cdk-lib: Cannot configure 'securityGroups' without configuring a VPC ec2: Cannot configure 'securityGroups' without configuring a VPC Jan 4, 2024
@pahud pahud added p2 bug This issue is a bug. @aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud effort/medium Medium work item – several days of effort response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed management/tracking Issues that track a subject or multiple issues p0 labels Jan 4, 2024
@mbhaalalhhaexchange
Copy link
Author

Yes kindly refer below code that was using with aws cdk v1 with @aws-cdk/aws-lambda package and aws cdk v2 with aws-cdk-lib/aws-lambda package,

   super(scope, id, {
  ...props,
  **vpc: undefined,**  // here we are not passing
  code: resolve(__dirname, '..', 'dist', 'src'),
  lambdas: lambdas.map((lambda) => ({
    ...lambda,
    environment: {
      ...(lambda.environment || {}),
      DB_SECRET_ARN: props.dbSecretArn,
      LOGGING_LEVEL: 'debug',
      SQS_CALL_INFO_QUEUE: props.sqsCallInfoQueue.queueUrl
    },
    **securityGroups: [props.securityGroup],**  // here we are passing security group
    policyStatements: [
      ...(lambda.policyStatements || []),
      new PolicyStatement({
        actions: ['secretsmanager:GetSecretValue'],
        resources: [props.dbSecretArn]
      }),
      new PolicyStatement({
        actions: ['kms:Decrypt'],
        resources: [props.dbSecretKmsKeyArn]
      }),
      new PolicyStatement({
        actions: ['cloudwatch:PutMetricData'],
        resources: ['*']
      }),
      new PolicyStatement({
        actions: ['sqs:SendMessage'],
        resources: [props.sqsCallInfoQueue.queueArn]
      }),
      new PolicyStatement({
        actions: ['connect:StartOutboundVoiceContact'],
        resources: ['*']
      })
    ],
    memorySize: lambda.memorySize || 512,
    retryAttempts: 0,
    lambdaTimeout: lambda?.lambdaTimeout || 8,
    runtime: Runtime.NODEJS_18_X
  })),
  layer: {
    folderPath: resolve(__dirname, '..', 'dist', 'lambdaLayer'),
    compatibleRuntimes: [Runtime.NODEJS_18_X]
  }

});

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jan 4, 2024
@pahud
Copy link
Contributor

pahud commented Jul 26, 2024

Cannot configure 'securityGroups' without configuring a VPC

This error generate indicates you can't just specify security groups with vpc undefined.

Please check this doc string:

/**
* The security group of this Lambda, if in a VPC.
*
* This needs to be given in order to support allowing connections
* to this Lambda.
*/
readonly securityGroup?: ec2.ISecurityGroup;

securityGroup is used when lambda function is in a VPC and you need to specify the vpc prop.

@pahud pahud added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jul 26, 2024
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 Jul 28, 2024
@github-actions github-actions bot closed this as completed Aug 2, 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 bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/medium Medium work item – several days of effort p2 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

2 participants