简体   繁体   English

AWS Python SDK - 保证EBS卷和EC实例在同一个可用区

[英]AWS Python SDK - guarantee that EBS volume and EC instance are in the same availability zone

I am scripting the setup of AWS resources using the Python SDK (boto3).我正在使用 Python SDK (boto3) 编写 AWS 资源设置脚本。 I can create ec2 instances with:我可以创建 ec2 实例:

ec2_resource.create_instances( .... )

and a block storage volume with:和一个块存储卷:

ec2_client.create_volume(..., AvailabilityZone = "eu-north-1a")

As indicated I can specify the availability zone for the block storage, however I have not understood how to specify that for the ec2 instance;如前所述,我可以为块存储指定可用区,但是我不明白如何为 ec2 实例指定可用区; when looking in the console I generally find that the ec2 instance has been created in another availability zone - eg "eu-north-1c", and then instance.attach_volume() fails because they are not in the same availability zone.在控制台中查看时,我通常会发现 ec2 实例已在另一个可用区中创建 - 例如“eu-north-1c”,然后instance.attach_volume()失败,因为它们不在同一可用区中。

What is the correct way to approach this?解决这个问题的正确方法是什么?

I hope you're using boto3 and not the outdated boto library;-)我希望您使用的是 boto3 而不是过时的 boto 库;-)

By specifying the su.net ID to launch the instance into, you implicitly set the availability zone, because each su.net is located in exactly one availability zone.通过指定要在其中启动实例的 su.net ID,您可以隐式设置可用区,因为每个 su.net 都恰好位于一个可用区中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM