简体   繁体   English

尝试在默认 VPC 之外使用 Apache libcloud 部署 ec2 实例

[英]Trying to deploy ec2 instance with Apache libcloud outside of default VPC

My organization creates our own VPC's and does not leverage the default one provided by AWS.我的组织创建了我们自己的 VPC,并没有利用 AWS 提供的默认 VPC。 I am trying to use apache libcloud to deploy instances within non-default VPC's.我正在尝试使用 apache libcloud 在非默认 VPC 中部署实例。 However, libcloud complains that no VPC Id was specified.但是,libcloud 抱怨未指定 VPC Id。 I can't seem to find where you are supposed to specify this parameter.我似乎无法找到您应该在哪里指定此参数。 I looked in the code, asked on IRC, and combed through the documentation.我查看了代码,在 IRC 上询问,并梳理了文档。 I tried providing a "location" parameter using an AZ but that doesn't seemto take either.我尝试使用 AZ 提供“位置”参数,但这似乎也没有。 Has anyone come across this or dealt with it?有没有人遇到过或处理过这个问题?

Ok, looks like you have to specify the subnet id you want to deploy the instance to if you do not have a default VPC.好的,如果您没有默认 VPC,您似乎必须指定要将实例部署到的子网 ID。

Here is my example for anyone else that needs assistance with this.这是我的示例,供其他需要帮助的人使用。

from libcloud.compute.providers import get_driver
from libcloud.compute.base import NodeImage
import os

ACCESS_ID = os.getenv('AWS_ACCESS_KEY_ID')
SECRET_KEY = os.getenv('AWS_SECRET_ACCESS_KEY')
AMI_ID = os.getenv('AMI_ID')
SIZE_ID = os.getenv('SIZE_ID', 't2.micro')
REGION = os.getenv('REGION','us-east1')
KEYNAME = os.getenv('KEYNAME')
SUBNET = os.getenv('SUBNET')

cls = get_driver(Provider.EC2)

driver = cls(ACCESS_ID, SECRET_KEY, region=REGION)

subnet = [ s for s in driver.ex_list_subnets() if s.id == SUBNET][0]
size = [ s for s in driver.list_sizes() if s.id == SIZE_ID][0]
image = NodeImage(id=AMI_ID, name=None, driver=driver)

node = driver.create_node(name='group-test', image=image, size=size, ex_subnet=subnet, ex_keyname=keyname)

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

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