如果我想快速向实例添加 SG,有没有办法像在管理控制台中那样使用 CLI 来完成此操作?
最佳答案
由于安全组实际上与网络接口(interface)相关联:
默认情况:(只有单个网络接口(interface)可用)
aws ec2 modify-instance-attribute --instance-id i-123 --groups sg-1 sg-2 ..
如果一个 ec2 实例有多个网络接口(interface)(即 ENI),您可以将不同的安全组关联到不同的 ENI
aws ec2 modify-network-interface-attribute --groups sg-1 sg-2 --network-interface-id eni-1
来源: https://docs.aws.amazon.com/cli/latest/reference/ec2/modify-instance-attribute.html
特别是注释:
Note: Using this action to change the security groups associated with an elastic network interface (ENI) attached to an instance in a VPC can result in an error if the instance has more than one ENI. To change the security groups associated with an ENI attached to an instance that has multiple ENIs, we recommend that you use the modify-network-interface-attribute action.
关于amazon-web-services - 有没有办法像使用管理控制台一样使用 CLI 将安全组添加到 EC2 实例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51587391/