amazon-web-services - 有没有办法像使用管理控制台一样使用 CLI 将安全组添加到 EC2 实例?

标签 amazon-web-services aws-cli

如果我想快速向实例添加 SG,有没有办法像在管理控制台中那样使用 CLI 来完成此操作?

management console example image

最佳答案

由于安全组实际上与网络接口(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/

相关文章:

amazon-web-services - AWS 和自动缩放 cassandra

amazon-web-services - AWS Data Pipeline 如何运行 EC2 实例?

amazon-web-services - 需要仅运行一次的 Cloudwatch 规则(预定的规则)

amazon-web-services - 如何使用 aws cloudformation 模板在 aws cognito 用户池中设置所需属性?

javascript - TypeError : headers[key]. trim 不是函数

amazon-ec2 - 我们可以使用一个 aws cli 命令向 AWS 资源添加多个标签吗?

amazon-web-services - JMESPath 过滤器表达式中的引用父元素

amazon-web-services - S3 cli 包括不工作

docker - 如何替换已弃用的 aws ecr get-login --registry-ids

amazon-web-services - AWS EC2 'You are not authorized to perform this operation. Encoded authorization failure message:'