Skip to content

Commit

Permalink
Fix getting VpcId on a potentially a shutting-down instance
Browse files Browse the repository at this point in the history
  • Loading branch information
Veetaha committed Jul 18, 2024
1 parent 840c87a commit ac3e04c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions elastio-nat-provision-lambda/lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,17 +290,22 @@ def cleanup_nat(current_instance_id, event_time):
def instance_az(inst):
return subnets.get(inst['SubnetId'], {}).get('AvailabilityZone')

active_statuses = ('pending', 'running', 'stopping', 'shutting-down')
active_statuses = ('pending', 'running', 'stopping')

for nat_deployment in nat_deployments:
nat_vpc_id = nat_deployment.vpc_id
nat_az = nat_deployment.az

active_instances = (
instance for instance in elastio_instances.values()

# VpcId is not always present in the instance object.
# It isn't present in case if the instance is in shutting-down state,
# for example (seen during testing). Maybe there are some other cases
# where VpcId isn't present, so we gracefully default to `None`.
if (instance['State']['Name'] in active_statuses
and
instance['VpcId'] == nat_vpc_id
instance.get(['VpcId'], None) == nat_vpc_id
and
instance_az(instance) == nat_az)
)
Expand Down

0 comments on commit ac3e04c

Please sign in to comment.