Reputation: 1731
When using boto most of the results that i get are in some form of a list and the contents of this list are Objects.
eg:
if i do
def elb_subnets( availability_zone ):
conn = boto.vpc.connect_to_region('us-west-2',aws_access_key_id,aws_secret_access_key)
subnet_list = conn.get_all_subnets(filters={"availability-zone":<availability_zone>})
return subnet_list;
subnet_list = elb_subnets("us-west-2a")
print subnet_list
[Subnet:subnet-8b9b31e0]
Now the above is a list which has items of type Subnet.
My problem is, I need to get rid of the part "Subnet:" and only pass subnet-8b9b31e0.
I tried using string operations on the list but get errors saying Subnet object doesn't have str operator modules
So how do i get this done?
This is one use case but i come across this with different modules of boto.
Upvotes: 1
Views: 673
Reputation: 34426
The subnet object has an id:
subnet_ids = [s.id for s in subnet_list]
This will give you a list of just the subnet IDs as strings.
Upvotes: 1
Reputation: 118001
You can do something like this, assuming the strings in subnet_list
always have the format that you showed.
subnet_list = ["Subnet:subnet-8b9b31e0","Subnet:subnet-1a1a1a1a", "Subnet:subnet-b2b2b2b2"]
strippedList = [i[7:] for i in subnet_list]
Output
['subnet-8b9b31e0', 'subnet-1a1a1a1a', 'subnet-b2b2b2b2']
Upvotes: 0