TristanMatthews
TristanMatthews

Reputation: 2571

AWS boto check if security group or other elements is ready

I'm creating a VPC and security groups with boto. If I just create and tag elements in a script I keep getting errors, because the elements aren't ready yet. I can just put in a manual wait, but I prefer to pull them to see if they are actually ready. For the VPCs or subnets I can use something like:

import boto.vpc

v = boto.vpc.VPCConnection(
    region=primary_region,
    aws_access_key_id=aws_access_key,
    aws_secret_access_key=aws_secret_key)

vpcs = v.get_all_vpcs()
print vpcs[0].state

with some more logic and a while loop to check if the state is available, running or whatever. This works fine for most vpc / aws elements, but some elements like security groups don't have a state attribute when returned with get_all_security_groups or there equivalent.

How do people check if these elements are ready to be used?

Upvotes: 5

Views: 690

Answers (1)

Liyan Chang
Liyan Chang

Reputation: 8061

Turns out that for the elements without a state property, you have to get creative and write some potentially brittle code.

For the specific example of security groups, I do:

  1. Uses get_all_security_groups with a filter to find the security group.
  2. Checks for sg.rules_egress
  3. Retries with exponential backoff.

When it starts to fail (and I'm sure it will), I'll take another look at other and better ways, but has worked without fail so far.

Upvotes: 1

Related Questions