我有以下代码来启动新实例:
conn = boto.ec2.connect_to_region("us-east-1", security_token = "xx", aws_access_key_id= "xx", aws_secret_access_key= "xx")
security_groups = conn.get_all_security_groups()
for security_group in security_groups:
if str(security_group)[14:] == "xx":
conn.run_instances(
'ami-da2cd5b2',
key_name='fornax_keypair',
instance_type='c1.xlarge',
security_groups=security_group)
else:
continue
找到安全组,然后给出错误:
TypeError: 'SecurityGroup' object is not iterable
如果我将其更改为str(security_group),则会出现错误:
<Response><Errors><Error><Code>InvalidGroup.NotFound</Code><Message>The security groups 'f', 'g', 'd', 'e', 'c', 'n', 'o', 'j', '.', 'i', 'v', 'u', 't', 's', 'r', 'p', '
:', 'y' do not exist</Message></Error></Errors><RequestID>c96afd3c-de3f-4441-be65-c6a85fbe7868</RequestID></Response>
另外如何将连接附加到已建立的vpc连接和子网?
答案 0 :(得分:1)
security_groups
的{{1}}参数应该是安全组名称列表。您正在传递标量字符串值。试试这个:
run_instances