title: grabbing key and value from nested dict aws response
body: <p>I'm struggling to get my head around nested dicts and how to grab the key and value from them. </p>
  
  <p>I have a nice script that grabs the VPC information from my AWS account:</p>
  
  <pre><code>import boto3
  from pprint import pprint
  
  #Declaring some resources for the below scripts. 
  ec2 = boto3.resource('ec2')
  client = boto3.client('ec2')
  
  #Grabing the VPC information and printing to console. 
  filters = [{'Name':'tag:Name', 'Values':['*']}]
  vpcs = list(ec2.vpcs.filter(Filters=filters))
  
  for vpc in vpcs:
      response = client.describe_vpcs(
          VpcIds=[
              vpc.id,
          ]
      )
      pprint(response['Vpcs'])
      print('-------')
  </code></pre>
  
  <p>This outputs like:</p>
  
  <p><em>[{'CidrBlock': '666.666.0.0/66',   'DhcpOptionsId': '55555',   'InstanceTenancy': 'default',   'IsDefault': False,'State': 'available',   'Tags': [{'Key': 'Environment', 'Value':'dev.aws'},
  {'Key': 'Name', 'Value': 'dev.aws.co.uk'}],   'VpcId': 'vpc-755555'}]</em></p>
  
  <p>now what I want is to grab only the VpcId and Tags, I have tried multiple variations of pprint(response['Vpcs']["VpcId"]). I have searched the web and tried a number of variations but I can't seem to get my head around it</p>
  
  <p>cany anyone offer any advice to my example? </p>
  
  <p><strong>Update</strong>:
  thanks again are you able to assist with a follow on question?</p>
  
  <p>I'm trying now to put this into a for loop so i can grab the output of any VPCs and Resulting tags that could be present in the AWS account but hitting a wall with "TypeError: string indices must be integers"</p>
  
  <p>Code i have tried (many variations of this):</p>
  
  <pre><code>  for vpcs in client.describe_vpcs():
      vpcid = vpcs['Vpcs'][0]['VpcId']
      print("Vpc Id:" + vpcid)
  
      for vpcs in client.describe_vpcs()['Vpcs']:
          print("VPC ID: " + vpcs['VpcId'])
          print(response['Vpcs'][0]['Tags'])
          print("Tags: " + vpcs['Tags'][0])
  </code></pre>
  
  <p>any ideas?</p>
  
  <p><strong>Update 2:</strong></p>
  
  <p>This loop works and will print out my VPCs with the tags of the fist VPC:</p>
  
  <pre><code>for vpcs in client.describe_vpcs()['Vpcs']:
      print("VPC ID: " + vpcs['VpcId'])
      print(response['Vpcs'][0]['Tags'])
  </code></pre>
  
  <p>I am trying to get it to loop the tags with the VPC id. </p>
  
  <p><strong>Output of <code>print(client.describe_vpcs())</code>:</strong></p>
  
  <p><code>{'ResponseMetadata': {'RequestId': 'nnnnn-e323-nn-a9a3-254nnnn2c3b6', 'RetryAttempts': 0, 'HTTPHeaders': {'transfer-encoding': 'chunked', 'content-type': 'text/xml;charset=UTF-8', 'vary': 'Accept-Encoding', 'server': 'AmazonEC2', 'date': 'Fri, 27 Jan 2017 14:21:58 GMT'}, 'HTTPStatusCode': 200}, 'Vpcs': [{'State': 'available', 'IsDefault': True, 'CidrBlock': '172.31.0.0/16', 'DhcpOptionsId': 'dopt-1d555578', 'VpcId': 'vpc-85555eb', 'InstanceTenancy': 'default', 'Tags': [{'Value': 'Default VPC', 'Key': 'Name'}]}, {'State': 'available', 'IsDefault': False, 'CidrBlock': '172.22.0.0/16', 'DhcpOptionsId': 'dopt-1d55558', 'VpcId': 'vpc-255554d', 'InstanceTenancy': 'default', 'Tags': [{'Value': 'DEV', 'Key': 'Environment'}, {'Value': 'dev2.aws.co.uk', 'Key': 'Name'}]}, {'State': 'available', 'IsDefault': False, 'CidrBlock': '172.30.0.0/16', 'DhcpOptionsId': 'dopt-16666d78', 'VpcId': 'vpc-7666617', 'InstanceTenancy': 'default', 'Tags': [{'Value': 'dev.aws', 'Key': 'Environment'}, {'Value': 'dev.aws.co.uk', 'Key': 'Name'}]}]}</code></p>
  
  <p><strong>Fix was:</strong></p>
  
  <pre><code>import boto3
  client = boto3.client('ec2')
  
  #This is the VPC ID and Linked Tags
  for vpctags in client.describe_vpcs()['Vpcs']: 
      print("VPC ID: ", vpctags['VpcId']) 
      print("Tags: ", vpctags['Tags'])
  </code></pre>
  
  <p>Big thanks to MYGz for taking the time to help. </p>