banner

KuchBhiLearning - A free website to learn and code

This is a good learning site. This contains details of cloud computing, AWS, AWS-CDK, AWS-SDK codes and examples including S3, Redis, lambda, api-gateway, cloudfront, cloudformation.

 Get security group from id AWS-CDK


We can create security group from CDK. But there are chances that the security group has been created and we just need to import using CDK.

CDK does provide the methods where we can easily import security groups and use it in our application.

Here in our example we will go through a scenario where we have kept the security group id value in parameter store, So first pick the security group id and then search for security group.




Let's dive into the code
  const securityGroupId = ssm.StringParameter.fromStringParameterAttributes(
    stack,
    `ssm-params-api`,
    {
      parameterName: `securitygroup/value`,
    }
  ).stringValue;

  // Fetch the security group details and use it in lambda.
  const securityGroupValue = ec2.SecurityGroup.fromSecurityGroupId(
    stack,
    `sg`,
    `${securityGroupId}`,
    {
      mutable: false,
    }
  );

No comments:

Post a Comment

If you have any doubts, Please let me know

Copyright 2022, KuchBhiLearning - A free website to learn and code. All rights Reserved.
| Designed by Yaseen Shariff