Sign in
agent:

List all VPCs in the AWS account.

There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.

Lists all VPCs in the AWS account across all regions.

import boto3 import json # Retrieve AWS credentials from environment variables aws_access_key_id = getEnvVar('AWS_ACCESS_KEY_ID') aws_secret_access_key = getEnvVar('AWS_SECRET_ACCESS_KEY') # Initialize a session using Amazon EC2 session = boto3.Session( aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, region_name='us-east-2' ) ec2_client = session.client('ec2') # Retrieve all regions regions = [region['RegionName'] for region in ec2_client.describe_regions()['Regions']] # List to store all VPCs vpcs = [] # Iterate over each region for region in regions: ec2_client = session.client('ec2', region_name=region) # Describe all VPCs vpcs_in_region = ec2_client.describe_vpcs()['Vpcs'] vpcs.extend(vpcs_in_region) # Print all VPCs print(json.dumps(vpcs, indent=4, default=str))
copied