How to access existing security group by tag using aws cdk?

0

I am creating a lambda function where I have added existing vpc (by tags) and private subnets. I want to add existing security group also to the lambda. Any idea how to access existing security by tags using cdk with typescript? Please help me with your valuable suggestions. Thank you in advance.

1개 답변
0

Hi,

To be transparent, I did not try this on your specific use case: lambda + sec group. But, I usually use CDK Construct.fromXXX() to achieve what you want to achieve here.

The section "How can I reference existing resources?" in this article https://garbe.io/blog/2019/09/20/hey-cdk-how-to-use-existing-resources/ explains it well with all possible options for "fromXXX()" with their differences.

It seems quite possible , see https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.SecurityGroup.html

If you have an existing security group you want to use in your CDK application, you would import it like this:

const securityGroup = ec2.SecurityGroup.fromSecurityGroupId(this, 'SG', 'sg-12345', {
  mutable: false
});

Best,

Didier

profile pictureAWS
전문가
답변함 9달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠