boto3将安全组添加到EC2实例

发布于 2025-02-12 07:47:19 字数 341 浏览 1 评论 0原文

我创建类似的实例:

client = boto3.client('ec2', region_name="eu-central-1")
client.run_instances(ImageId="ami-0df63501d4a3233e8", MinCount=1, MaxCount=1)

但是如何指定类型, SecurityGroup 等?

它们已经存储在ami中吗?

我已经看到了使用boto3.resources(“ ec2”)的解决方案,但我已经尝试过,但是我无法正确运行它。

I create instances like so:

client = boto3.client('ec2', region_name="eu-central-1")
client.run_instances(ImageId="ami-0df63501d4a3233e8", MinCount=1, MaxCount=1)

But how can I specify the type, securitygroup, etc. ?

Are they already stored in the ami ?

I have seen a solution using boto3.resources("ec2") which I have already tried, but then I can't properly run UnitTests on it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傲影 2025-02-19 07:47:19

如果要按照安全组的名称添加,请添加参数securityGroupids如果要添加一个或多个 securitygroups ,则将添加一个或多个。这两个都应属于list

client = boto3.client('ec2', region_name='eu-central-1')
client.run_instances(ImageId='ami-0df63501d4a3233e8', MinCount=1, MaxCount=1,
                     SecurityGroupIds=['sg-000000000000000'])

用您的真实安全组ID替换SG-0000000000000

You would add the parameter SecurityGroupIds if you want to add one or more by the ID or SecurityGroups if you want to add by the name of the security group. Both of these should be of type list.

client = boto3.client('ec2', region_name='eu-central-1')
client.run_instances(ImageId='ami-0df63501d4a3233e8', MinCount=1, MaxCount=1,
                     SecurityGroupIds=['sg-000000000000000'])

Replace sg-000000000000000 with your real security group ID.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文