0
1

More than 1 year has passed since last update.

Dictionaryの紐解き方

Last updated at Posted at 2022-08-24

Boto3 でのお話。
NatGateway を短時間に同じタグ名で立ち上げていて、前のものは削除しているのだが describe すると削除の状態で残ってしまっているので、タグでフィルターしても複数がひっかかってしまっている。
現在、available のものを選択して削除したい、ということで、次の関数に渡すために AllocationId が必要。
Dictionary を紐解くために、以下のコードとした。

for i in range(10):
    nat_gateway_id=response1['NatGateways'][i]['NatGatewayId']
    public_ip=response1['NatGateways'][i]['NatGatewayAddresses'][0]['PublicIp']
    allocation_id=response1['NatGateways'][i]['NatGatewayAddresses'][0]['AllocationId']
    state=response1['NatGateways'][i]['State']
    print('allocation_id:' + allocation_id)
    print('state:' + state)
    if state == 'available':
        break
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1