Why Would Boto3 Not Show a Peering Connection That the AWS CLI Shows?

Problem scenario
You have found an AWS CLI command that shows you output consistent with the console. You run this:

aws ec2 describe-vpc-peering-connection --region us-west-2 | grep pcx-abcd1234

The results show you a peering connection called pcx-abcd1234

You run this from a Python3 interpreter prompt:

import boto3
foo = boto3.resource('ec2')

You then search the output for pcx-abcd1234. You do not see it. Using different methods and syntax, you can never see pcx-abcd1234 in Boto3.

Using the AWS CLI, you can readily find pcx-abcd1234. Using the web console you can find it too.

You can find other peering connections with Boto3. One peering connection is elusive however.

Why would Boto3 results be discrepant from the CLI?

In Python, you need a stanza like this with the region_name and the profile setting to make it consistent with your AWS CLI:

boto3.setup_default_session(profile_name="foobar", region='us-west-2')

If you want to see what your AWS CLI is using, see the .aws/config file. If the profile and region are not the same between the AWS CLI and Boto3, you could get seemingly inconsistent results in the output regarding VPC components.

Leave a comment

Your email address will not be published. Required fields are marked *