How to _remove_ security groups from launch template version

0

I'm trying to use the CLI to remove security groups (SGs) from a launch template (LT). When updating the LT version, my config JSON looks like so:

{
    "SecurityGroupIds": []
}

... but this isn't removing the SGs from the newly-created LT version. I believe the create-launch-template-version operation is taking the union of the existing SGs and the newly-specified SGs, but I want to replace the existing SGs (in this case with zero SGs).

How can I delete SGs for a new LT version? (Using the Console isn't feasible for me, I have thousands of LTs.)

已提问 3 个月前140 查看次数
1 回答
0

To remove all security groups from a launch template version when creating a new version, you need to use the SecurityGroupIds parameter along with the DefaultSecurityGroupIds parameter in the create-launch-template-version command. Here's the command you can use:

aws ec2 create-launch-template-version \
    --launch-template-id <launch-template-id> \
    --version-description "Remove security groups" \
    --source-version <source-version-number> \
    --launch-template-data '{"SecurityGroupIds": [], "DefaultSecurityGroupIds": []}' \
    --region <region>

Replace the following:

  • <launch-template-id> with the ID of your launch template
  • <source-version-number> with the version number you want to base the new version on
  • <region> with the AWS region where your launch template resides

However, when you create a new EC2 instance using a launch template without any security groups specified, AWS will automatically assign the default security group to the instance.

If your goal is to not allow any inbound/outbound traffic to the instance, I would suggest attaching a security group with no inbound/outbound rules. Alternatively, you could edit the default security group to remove the inbound/outbound rules, but I would not recommend doing this. If you go either of these routes, you will not be able to connect to your instances, and your instances won't be able to connect to anything.

To make sure we're implementing the best solution, may I ask why you want to launch instances without a security group attached?

AWS
已回答 1 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则