[英]AWS-BOTO security group error
I have the following code to spin up new instances: 我有以下代码来启动新实例:
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
It finds the security group and then gives the error : 它找到安全组,然后给出错误:
TypeError: 'SecurityGroup' object is not iterable
If I change it to str(security_group), it then gives the error: 如果我将其更改为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>
Also how do I attach the connection to an already established vpc connection and subnet ? 另外,如何将连接附加到已建立的vpc连接和子网?
The security_groups
parameter to run_instances
is supposed to be list of security group names. run_instances
的security_groups
参数应该是安全组名称的列表。 You are passing a scalar string value. 您正在传递标量字符串值。 Try this instead:
尝试以下方法:
conn.run_instances(
'ami-da2cd5b2',
key_name='fornax_keypair,
instance_type='c1.xlarge',
security_groups=[security_group])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.