Skip to content

Which EC2 instances are in which VPCs across all regions?

list-ec-instances-by-vpc-across · the answer aws-bench grades against: 6 instances across 4 VPCs

Below is what each tool's agent actually ran. The scores say which tools answered. This says how, and the how is where they differ most.

chant — answered

1 commands, from chant-i3.

cd /workspace/chant && chant search "kind:EC2::Instance" --at latest --env floci --show VpcId,region --explain

No tool (AWS CLI) — answered

9 commands, from bare-i3.

aws ec2 describe-instances --region us-east-1 --output json --query 'Reservations[*].Instances[*].[InstanceId,VpcId,InstanceType,State.Name,Tags[?Key==`Name`].Value|[0]]' | jq -r '.[] | .[] | @csv' 2>/dev/null | head -20
aws ec2 describe-instances --region us-west-1 --output json --query 'Reservations[*].Instances[*].[InstanceId,VpcId,InstanceType,State.Name,Tags[?Key==`Name`].Value|[0]]' | jq -r '.[] | .[] | @csv' 2>/dev/null | head -20
aws ec2 describe-instances --region us-west-2 --output json --query 'Reservations[*].Instances[*].[InstanceId,VpcId,InstanceType,State.Name,Tags[?Key==`Name`].Value|[0]]' | jq -r '.[] | .[] | @csv' 2>/dev/null | head -20
aws ec2 describe-instances --region us-east-1 --output json --query 'Reservations[*].Instances[*].[InstanceId,VpcId,InstanceType,State.Name,Tags[?Key==`Name`].Value|[0]]' | jq -r '.[] | .[] | "\(.): Instance=\(.[0]), VPC=\(.[1]), Type=\(.[2]), State=\(.[3]), Name=\(.[4])"' 2>/dev/null
aws ec2 describe-instances --region us-west-1 --output json --query 'Reservations[*].Instances[*].[InstanceId,VpcId,InstanceType,State.Name,Tags[?Key==`Name`].Value|[0]]' | jq -r '.[] | .[] | "\(.): Instance=\(.[0]), VPC=\(.[1]), Type=\(.[2]), State=\(.[3]), Name=\(.[4])"' 2>/dev/null
aws ec2 describe-instances --region us-west-2 --output json --query 'Reservations[*].Instances[*].[InstanceId,VpcId,InstanceType,State.Name,Tags[?Key==`Name`].Value|[0]]' | jq -r '.[] | .[] | "\(.): Instance=\(.[0]), VPC=\(.[1]), Type=\(.[2]), State=\(.[3]), Name=\(.[4])"' 2>/dev/null
aws ec2 describe-vpcs --region us-east-1 --output json --query 'Vpcs[*].[VpcId,Tags[?Key==`Name`].Value|[0],IsDefault]' | jq -r '.[] | "\(.[0]): Name=\(.[1]), IsDefault=\(.[2])"' 2>/dev/null
aws ec2 describe-vpcs --region us-west-1 --output json --query 'Vpcs[*].[VpcId,Tags[?Key==`Name`].Value|[0],IsDefault]' | jq -r '.[] | "\(.[0]): Name=\(.[1]), IsDefault=\(.[2])"' 2>/dev/null
aws ec2 describe-vpcs --region us-west-2 --output json --query 'Vpcs[*].[VpcId,Tags[?Key==`Name`].Value|[0],IsDefault]' | jq -r '.[] | "\(.[0]): Name=\(.[1]), IsDefault=\(.[2])"' 2>/dev/null

Terraform — answered

17 commands, from terraform-i3.

cd /workspace/terraform && ./terraform show -json | jq '.'
cd /workspace/terraform && ./terraform show -json | jq '.values.root_module.resources[] | select(.type == "aws_instance") | {address, provider_name, values: {id: .values.id, vpc_id: .values.vpc_id, subnet_id: .values.subnet_id, availability_zone: .values.availability_zone, private_ip: .values.private_ip, public_ip: .values.public_ip, tags: .values.tags}}' 2>/dev/null
cd /workspace/terraform && ./terraform state list | grep aws_instance
cd /workspace/terraform && for instance in "module.primary.aws_instance.default_vpc_server" "module.primary.aws_instance.launch_template_server" "module.primary.aws_instance.private_server" "module.primary.aws_instance.web_server" "module.west1.aws_instance.server" "module.west2.aws_instance.server"; do echo "=== $instance ===" ./terraform state show "$instance" | grep -E "id |vpc_id|availability_zone" | head -5 done
cd /workspace/terraform && ./terraform state show "module.primary.aws_instance.default_vpc_server" 2>/dev/null | head -50
cd /workspace/terraform && ./terraform state list | grep aws_subnet
cd /workspace/terraform && ./terraform state list | grep aws_vpc
cd /workspace/terraform && ./terraform show -json > /tmp/terraform_state.json && python3 << 'EOF' import json with open('/tmp/terraform_state.json', 'r') as f: state = json.load(f) # Build a map of subnet_id -> vpc_id subnet_to_vpc = {} vpc_info = {} # First pass: collect VPC info for resource in state['values']['root_module']['resources']: if resource['type'] == 'aws_vpc': vpc_id = resource['values']['id'] vpc_info[resource['address']] = { 'id': vpc_id, 'cidr_block': resource['values']['cidr_block'] } # Second pass: collect subnet to VPC mappings for resource in state['values']['root_module']['resources']: if resource['type'] == 'aws_subnet': subnet_id = resource['values']['id'] vpc_id = resource['values']['vpc_id'] subnet_to_vpc[subnet_id] = vpc_id # Third pass: collect instances instances = [] for resource in state['values']['root_module']['resources']: if resource['type'] == 'aws_instance': instance = { 'id': resource['values']['id'], 'address': resource['address'], 'region': resource['values']['region'], 'availability_zone': resource['values']['availability_zone'], 'subnet_id': resource['values']['subnet_id'], 'vpc_id': subnet_to_vpc.get(resource['values']['subnet_id'], 'N/A'), 'private_ip': resource['values']['private_ip'], 'public_ip': resource['values'].get('public_ip'), 'instance_type': resource['values']['instance_type'] } instances.append(instance) # Sort by region, then VPC instances.sort(key=lambda x: (x['region'], x['vpc_id'])) # Print results for instance in instances: print(f"{instance['id']} | Region: {instance['region']} | VPC: {instance['vpc_id']} | AZ: {instance['availability_zone']} | Private IP: {instance['private_ip']}") EOF
cd /workspace/terraform && python3 << 'EOF' import json with open('/tmp/terraform_state.json', 'r') as f: state = json.load(f) # Find aws_instance resources instances = [r for r in state['values']['root_module']['resources'] if r['type'] == 'aws_instance'] print(f"Found {len(instances)} instances") # Find subnets subnets = [r for r in state['values']['root_module']['resources'] if r['type'] == 'aws_subnet'] print(f"Found {len(subnets)} subnets") # Build subnet to vpc map subnet_to_vpc = {} for subnet in subnets: subnet_id = subnet['values']['id'] vpc_id = subnet['values']['vpc_id'] subnet_to_vpc[subnet_id] = vpc_id print(f"Subnet {subnet_id} -> VPC {vpc_id}") # Print instance info print("\nInstances:") for instance in instances: subnet_id = instance['values']['subnet_id'] vpc_id = subnet_to_vpc.get(subnet_id, 'UNKNOWN') print(f" {instance['values']['id']} | Region: {instance['values']['region']} | VPC: {vpc_id}") EOF
cd /workspace/terraform && python3 << 'EOF' import json with open('/tmp/terraform_state.json', 'r') as f: state = json.load(f) # Check structure root = state['values']['root_module'] print("Root module keys:", root.keys()) if 'child_modules' in root: print(f"Child modules: {len(root['child_modules'])}") for child in root['child_modules']: print(f" - {child.get('address')}") EOF
cd /workspace/terraform && python3 << 'EOF' import json def collect_resources(module, resource_type): """Recursively collect resources of a given type from a module""" results = [] # Add resources from this module if 'resources' in module: for resource in module['resources']: if resource['type'] == resource_type: results.append(resource) # Recurse into child modules if 'child_modules' in module: for child in module['child_modules']: results.extend(collect_resources(child, resource_type)) return results with open('/tmp/terraform_state.json', 'r') as f: state = json.load(f) root = state['values']['root_module'] # Collect all instances and subnets instances = collect_resources(root, 'aws_instance') subnets = collect_resources(root, 'aws_subnet') vpcs = collect_resources(root, 'aws_vpc') print(f"Found {len(instances)} instances") print(f"Found {len(subnets)} subnets") print(f"Found {len(vpcs)} VPCs") # Build subnet to vpc map subnet_to_vpc = {} for subnet in subnets: subnet_id = subnet['values']['id'] vpc_id = subnet['values']['vpc_id'] subnet_to_vpc[subnet_id] = vpc_id # Build VPC ID to name map vpc_names = {} for vpc in vpcs: vpc_id = vpc['values']['id'] address = vpc['address'] vpc_names[vpc_id] = address # Print instance info organized by region and VPC print("\n" + "="*80) print("EC2 INSTANCES BY REGION AND VPC") print("="*80) # Organize by region by_region = {} for instance in instances: region = instance['values']['region'] subnet_id = instance['values']['subnet_id'] vpc_id = subnet_to_vpc.get(subnet_id, 'UNKNOWN') if region not in by_region: by_region[region] = {} if vpc_id not in by_region[region]: by_region[region][vpc_id] = [] by_region[region][vpc_id].append(instance) # Print organized results for region in sorted(by_region.keys()): print(f"\n{region}:") for vpc_id in sorted(by_region[region].keys()): vpc_addr = vpc_names.get(vpc_id, vpc_id) print(f" VPC: {vpc_id} ({vpc_addr})") for instance in by_region[region][vpc_id]: inst_id = instance['values']['id'] inst_type = instance['values']['instance_type'] private_ip = instance['values']['private_ip'] public_ip = instance['values'].get('public_ip', 'N/A') az = instance['values']['availability_zone'] print(f" - {inst_id} ({inst_type}) | Private IP: {private_ip} | Public IP: {public_ip} | AZ: {az}") EOF
cd /workspace/terraform && python3 << 'EOF' import json def collect_resources(module, resource_type): """Recursively collect resources of a given type from a module""" results = [] # Add resources from this module if 'resources' in module: for resource in module['resources']: if resource['type'] == resource_type: results.append(resource) # Recurse into child modules if 'child_modules' in module: for child in module['child_modules']: results.extend(collect_resources(child, resource_type)) return results with open('/tmp/terraform_state.json', 'r') as f: state = json.load(f) root = state['values']['root_module'] # Collect data sources for default VPC data_vpcs = [r for r in collect_resources(root, 'aws_vpc') if r['mode'] == 'data'] data_subnets = [r for r in collect_resources(root, 'aws_subnets') if r['mode'] == 'data'] print("Data Sources (Default VPC):") for vpc in data_vpcs: print(f" VPC: {vpc['address']} -> ID: {vpc['values']['id']}") for subnet in data_subnets: print(f" Subnets: {subnet['address']} -> IDs: {subnet['values'].get('ids', [])}") EOF
# … 5 more

Pulumi — answered

5 commands, from pulumi-i3.

cd /workspace/pulumi && ./pulumi-export | jq '.deployment.resources[] | select(.type == "aws:ec2/instance:Instance") | {urn, region: (.outputs.arn // .inputs.region // .outputs.availabilityZone | capture("^(?<r>[^-]+-[^-]+-\\d+)").r), vpc_id: .outputs.vpcId, subnet_id: .outputs.subnetId, instance_id: .outputs.id}' -c
cd /workspace/pulumi && ./pulumi-export | jq '.deployment.resources[] | select(.type == "aws:ec2/instance:Instance")' -c | head -1 | jq .
cd /workspace/pulumi && ./pulumi-export | jq '.deployment.resources[] | select(.type == "aws:ec2/subnet:Subnet") | {subnet_id: .outputs.id, vpc_id: .outputs.vpcId}' -c
cd /workspace/pulumi && ./pulumi-export | jq '.deployment.resources[] | select(.type == "aws:ec2/instance:Instance") | {name: (.urn | split("::")[-1]), instance_id: .outputs.id, subnet_id: .outputs.subnetId, az: .outputs.availabilityZone, instance_name: (.outputs.tags.Name // "N/A")}' | jq -s '.'
cd /workspace/pulumi && ./pulumi-export | jq '.deployment.resources[] | select(.type == "aws:ec2/vpc:Vpc") | {vpc_id: .outputs.id, is_default: .outputs.isDefault}' -c

AWS CDK — answered

9 commands, from cdk-i1.

cd /workspace/cdk_app && npx cdk ls
cd /workspace/cdk_app && npx cdk synth ec2-multiregion-QARoles-us-east-1 --json 2>/dev/null | jq '.Resources[] | select(.Type == "AWS::EC2::Instance") | {LogicalId: .LogicalId, Properties: .Properties}' 2>/dev/null || echo "No EC2 instances in this stack"
cd /workspace/cdk_app && for stack in "ec2-multiregion-QARoles-us-east-1" "ec2-multiregion-EC2-ks84v1fh12-us-east-1" "ec2-multiregion-EC2-ls9fuhb522-us-west-1" "ec2-multiregion-EC2-ls9fuhb522-us-west-2"; do echo "=== $stack ===" npx cdk synth "$stack" --json 2>/dev/null | jq -r '.Resources | keys[] as $key | select(.[$key].Type == "AWS::EC2::Instance") | "\($key): \(.[$key].Properties.SubnetId // "No SubnetId")"' 2>/dev/null || echo "No EC2 instances" done
cd /workspace/cdk_app && npx cdk synth ec2-multiregion-EC2-ks84v1fh12-us-east-1 --json 2>/dev/null | jq -r '.Resources | to_entries[] | select(.value.Type == "AWS::EC2::Instance" or .value.Type == "AWS::EC2::Subnet" or .value.Type == "AWS::EC2::VPC" or .value.Type == "AWS::EC2::LaunchTemplate") | {LogicalId: .key, Type: .value.Type, Properties: .value.Properties}' 2>/dev/null | head -100
cd /workspace/cdk_app && cat > /tmp/extract_ec2_info.jq << 'EOF' # Build lookup tables for logical ID to VPC def vpc_lookup: reduce .Resources | to_entries[] as $item ( {}; if $item.value.Type == "AWS::EC2::VPC" then .[$item.key] = $item.value.Properties else . end ); def subnet_to_vpc: reduce .Resources | to_entries[] as $item ( {}; if $item.value.Type == "AWS::EC2::Subnet" then .[$item.key] = { VpcRef: $item.value.Properties.VpcId, CIDR: $item.value.Properties.CidrBlock, AZ: $item.value.Properties.AvailabilityZone } else . end ); # Extract EC2 instances with their details def ec2_instances: [.Resources | to_entries[] | select(.value.Type == "AWS::EC2::Instance") | { LogicalId: .key, Properties: .value.Properties }]; # Main extraction { vpcs: vpc_lookup, subnets: subnet_to_vpc, instances: ec2_instances } EOF
cd /workspace/cdk_app && cat > /tmp/analyze_stacks.sh << 'EOF' #!/bin/bash for stack in "ec2-multiregion-QARoles-us-east-1" "ec2-multiregion-EC2-ks84v1fh12-us-east-1" "ec2-multiregion-EC2-ls9fuhb522-us-west-1" "ec2-multiregion-EC2-ls9fuhb522-us-west-2"; do echo "=== Stack: $stack ===" # Extract region from stack name region=$(echo $stack | rev | cut -d'-' -f1-2 | rev) echo "Region: $region" # Synthesize and analyze template=$(npx cdk synth "$stack" --json 2>/dev/null) # Get all VPCs in this stack echo "VPCs:" echo "$template" | jq -r '.Resources | to_entries[] | select(.value.Type == "AWS::EC2::VPC") | "\(.key)"' | while read vpc_logical_id; do vpc_info=$(echo "$template" | jq -r ".Resources.\"$vpc_logical_id\".Properties") echo " $vpc_logical_id" done # Get all EC2 instances in this stack echo "EC2 Instances:" echo "$template" | jq -r '.Resources | to_entries[] | select(.value.Type == "AWS::EC2::Instance") | "\(.key)"' | while read instance_id; do instance=$(echo "$template" | jq ".Resources.\"$instance_id\".Properties") subnet_ref=$(echo "$instance" | jq -r '.SubnetId // empty') echo " Instance: $instance_id" echo " SubnetRef: $subnet_ref" # Resolve subnet reference to get VPC if [[ $subnet_ref == *"Ref"* ]]; then subnet_logical=$(echo "$subnet_ref" | jq -r '.Ref // empty') if [ ! -z "$subnet_logical" ]; then subnet_info=$(echo "$template" | jq -r ".Resources.\"$subnet_logical\".Properties // empty") if [ ! -z "$subnet_info" ]; then vpc_ref=$(echo "$template" | jq -r ".Resources.\"$subnet_logical\".Properties.VpcId.Ref // empty") echo " SubnetLogical: $subnet_logical" echo " VPCLogical: $vpc_ref" fi fi else # It's a direct subnet ID echo " SubnetId: $subnet_ref" fi done echo "" done EOF chmod +x /tmp/analyze_stacks.sh /tmp/analyze_stacks.sh
cd /workspace/cdk_app && cat > /tmp/get_physical_ids.sh << 'EOF' #!/bin/bash declare -A region_map=( ["ec2-multiregion-QARoles-us-east-1"]="us-east-1" ["ec2-multiregion-EC2-ks84v1fh12-us-east-1"]="us-east-1" ["ec2-multiregion-EC2-ls9fuhb522-us-west-1"]="us-west-1" ["ec2-multiregion-EC2-ls9fuhb522-us-west-2"]="us-west-2" ) # Iterate through stacks and get physical resource IDs for stack in "ec2-multiregion-QARoles-us-east-1" "ec2-multiregion-EC2-ks84v1fh12-us-east-1" "ec2-multiregion-EC2-ls9fuhb522-us-west-1" "ec2-multiregion-EC2-ls9fuhb522-us-west-2"; do region="${region_map[$stack]}" echo "=== Stack: $stack (Region: $region) ===" # Query CloudFormation for physical resource mappings aws cloudformation describe-stack-resources \ --stack-name "$stack" \ --region "$region" \ --query 'StackResources[?ResourceType==`AWS::EC2::Instance`].[LogicalResourceId,PhysicalResourceId]' \ --output text 2>/dev/null || echo "Failed to query stack" echo "" done EOF chmod +x /tmp/get_physical_ids.sh /tmp/get_physical_ids.sh
cd /workspace/cdk_app && cat > /tmp/map_instances_to_vpcs.sh << 'EOF' #!/bin/bash declare -A region_map=( ["ec2-multiregion-QARoles-us-east-1"]="us-east-1" ["ec2-multiregion-EC2-ks84v1fh12-us-east-1"]="us-east-1" ["ec2-multiregion-EC2-ls9fuhb522-us-west-1"]="us-west-1" ["ec2-multiregion-EC2-ls9fuhb522-us-west-2"]="us-west-2" ) # Build a comprehensive mapping echo "EC2 Instances to VPC Mapping:" echo "========================================" for stack in "ec2-multiregion-QARoles-us-east-1" "ec2-multiregion-EC2-ks84v1fh12-us-east-1" "ec2-multiregion-EC2-ls9fuhb522-us-west-1" "ec2-multiregion-EC2-ls9fuhb522-us-west-2"; do region="${region_map[$stack]}" # Synthesize template to get logical mappings template=$(npx cdk synth "$stack" --json 2>/dev/null) # Build lookup for logical resources declare -A vpc_map subnet_map # Map VPC logical IDs to stack resource IDs (physical) while IFS=$'\t' read logical physical; do vpc_map["$logical"]="$physical" done < <(aws cloudformation describe-stack-resources \ --stack-name "$stack" \ --region "$region" \ --query 'StackResources[?ResourceType==`AWS::EC2::VPC`].[LogicalResourceId,PhysicalResourceId]' \ --output text 2>/dev/null) # Map Subnet logical IDs to stack resource IDs (physical) while IFS=$'\t' read logical physical; do subnet_map["$logical"]="$physical" done < <(aws cloudformation describe-stack-resources \ --stack-name "$stack" \ --region "$region" \ --query 'StackResources[?ResourceType==`AWS::EC2::Subnet`].[LogicalResourceId,PhysicalResourceId]' \ --output text 2>/dev/null) # Get instances while IFS=$'\t' read logical physical; do echo "" echo "Region: $region" echo "Instance ID: $physical" echo "Logical ID: $logical" # Get instance subnet from template subnet_ref=$(echo "$template" | jq -r ".Resources.\"$logical\".Properties.SubnetId // empty") if [[ $subnet_ref == *"Ref"* ]]; then # Resolve Ref subnet_logical=$(echo "$subnet_ref" | jq -r '.Ref // empty') subnet_physical="${subnet_map[$subnet_logical]}" echo "Subnet ID: $subnet_physical" # Get VPC for this subnet vpc_logical=$(echo "$template" | jq -r ".Resources.\"$subnet_logical\".Properties.VpcId.Ref // empty") vpc_physical="${vpc_map[$vpc_logical]}" echo "VPC ID: $vpc_physical" else # It's a direct subnet ID (default VPC) echo "Subnet ID: $subnet_ref" # Query to find the VPC vpc_id=$(aws ec2 describe-subnets --region "$region" --subnet-ids "$subnet_ref" \ --query 'Subnets[0].VpcId' --output text 2>/dev/null) echo "VPC ID: $vpc_id" fi done < <(aws cloudformation describe-stack-resources \ --stack-name "$stack" \ --region "$region" \ --query 'StackResources[?ResourceType==`AWS::EC2::Instance`].[LogicalResourceId,PhysicalResourceId]' \ --output text 2>/dev/null) done EOF chmod +x /tmp/map_instances_to_vpcs.sh /tmp/map_instances_to_vpcs.sh
cat > /logs/agent/agent-output.txt << 'EOF' EC2 INSTANCES BY VPC AND REGION ================================ SUMMARY ------- Total Instances: 6 Total VPCs: 4 Regions: us-east-1, us-west-1, us-west-2 VPC: vpc-32f15458 (us-east-1) ----------------------------- Instances: - Instance ID: i-8efe413fb2db04cc6 Stack: ec2-multiregion-EC2-ks84v1fh12-us-east-1 Subnet: subnet-2e472a30 (Public) Logical Name: WebServerInstance8A1D687E - Instance ID: i-c4deff6351c208ad9 Stack: ec2-multiregion-EC2-ks84v1fh12-us-east-1 Subnet: subnet-6e5a5bfe (Private) Logical Name: PrivateInstance5CA423EB - Instance ID: i-2406a03b9ade076f4 Stack: ec2-multiregion-EC2-ks84v1fh12-us-east-1 Subnet: subnet-2e472a30 (Public) Logical Name: LaunchTemplateInstance VPC: vpc-default (us-east-1) ---------------------------- Instances: - Instance ID: i-7d9001a08d554ad03 Stack: ec2-multiregion-EC2-ks84v1fh12-us-east-1 Subnet: subnet-default-a Logical Name: MyEC2InstanceB097982C VPC: vpc-3560a154 (us-west-1) ----------------------------- Instances: - Instance ID: i-fde88288e4fcb0f27 Stack: ec2-multiregion-EC2-ls9fuhb522-us-west-1 Subnet: subnet-8df31a62 Logical Name: WebServerInstance8A1D687E VPC: vpc-66895528 (us-west-2) ----------------------------- Instances: - Instance ID: i-c18071845f3e04292 Stack: ec2-multiregion-EC2-ls9fuhb522-us-west-2 Subnet: subnet-ee531476 Logical Name: WebServerInstance8A1D687E INSTANCE LISTING BY REGION =========================== US-EAST-1 --------- 1. WebServerInstance (i-8efe413fb2db04cc6) VPC: vpc-32f15458 Subnet: subnet-2e472a30 Stack: ec2-multiregion-EC2-ks84v1fh12-us-east-1 2. MyEC2InstanceB097982C (i-7d9001a08d554ad03) VPC: vpc-default Subnet: subnet-default-a Stack: ec2-multiregion-EC2-ks84v1fh12-us-east-1 3. PrivateInstance5CA423EB (i-c4deff6351c208ad9) VPC: vpc-32f15458 Subnet: subnet-6e5a5bfe Stack: ec2-multiregion-EC2-ks84v1fh12-us-east-1 4. LaunchTemplateInstance (i-2406a03b9ade076f4) VPC: vpc-32f15458 Subnet: subnet-2e472a30 Stack: ec2-multiregion-EC2-ks84v1fh12-us-east-1 US-WEST-1 --------- 1. WebServerInstance (i-fde88288e4fcb0f27) VPC: vpc-3560a154 Subnet: subnet-8df31a62 Stack: ec2-multiregion-EC2-ls9fuhb522-us-west-1 US-WEST-2 --------- 1. WebServerInstance (i-c18071845f3e04292) VPC: vpc-66895528 Subnet: subnet-ee531476 Stack: ec2-multiregion-EC2-ls9fuhb522-us-west-2 DATA SOURCE =========== All information extracted from CDK synthesized CloudFormation templates and verified with: - npx cdk synth (templates) - aws cloudformation describe-stack-resources (physical resource IDs) - aws ec2 describe-subnets (VPC mappings for default VPC) EOF cat /logs/agent/agent-output.txt

Alchemy — answered

23 commands, from alchemy-i3.

cd /workspace/alchemy && alchemy state list | grep -E "(Instance|VPC)" | head -50
cd /workspace/alchemy && alchemy state tree | head -100
cd /workspace/alchemy && alchemy state get alchemy-ec2-multiregion/bench/instance 2>/dev/null | jq '{kind: .kind, region: .output.region, vpc_id: .output.vpc_id, subnet_id: .output.subnet_id}'
cd /workspace/alchemy && alchemy state get alchemy-ec2-multiregion/bench/private 2>/dev/null | jq '{kind: .kind, region: .output.region, vpc_id: .output.vpc_id, subnet_id: .output.subnet_id}'
cd /workspace/alchemy && alchemy state get alchemy-ec2-multiregion/bench/web 2>/dev/null | jq '{kind: .kind, region: .output.region, vpc_id: .output.vpc_id, subnet_id: .output.subnet_id}'
cd /workspace/alchemy && alchemy state list | grep -i "aws::instance"
cd /workspace/alchemy/.alchemy/alchemy-ec2-multiregion/bench && cat exp-InstanceId.json | jq .
cd /workspace/alchemy/.alchemy/alchemy-ec2-multiregion/bench && cat exp-DefaultVPCInstanceId.json | jq .
cd /workspace/alchemy/.alchemy/alchemy-ec2-multiregion/bench && cat exp-PrivateInstanceId.json | jq .
cd /workspace/alchemy/.alchemy/alchemy-ec2-multiregion/bench && cat exp-VpcId.json | jq '.output.value'
cd /workspace/alchemy/.alchemy/alchemy-ec2-multiregion/bench && cat exp-DefaultVpcId.json | jq '.output.value'
cd /workspace/alchemy/.alchemy/alchemy-ec2-multiregion/bench && cat usw1-exp-VpcId.json | jq '.output.value'
# … 11 more

Alchemy v2 (Effect) — missed

4 commands, from alchemy-effect-i3.

cd /workspace/alchemy && alchemy state export us-west-1.run.ts --local | jq '.'
cd /workspace/alchemy && alchemy state export us-west-1.run.ts --local | jq '.resources | map(select(.resourceType == "AWS.EC2.Instance")) | map({stack: .stack, instance_name: .fqn, instance_id: .attr.instanceId, vpc_id: .attr.vpcId, subnet_id: .attr.subnetId, region: (.stack | split("-") | .[-1])}) | sort_by(.region, .vpc_id)'
cd /workspace/alchemy && alchemy state export us-west-1.run.ts --local 2>/dev/null | jq -r '.resources | map(select(.state.resourceType == "AWS.EC2.Instance")) | group_by(.stack) | map({region: (.[0].stack | split("-") | .[-1]), instances: map({name: .fqn, instanceId: .state.attr.instanceId, vpcId: .state.attr.vpcId, subnet: .state.attr.subnetId}) | group_by(.vpcId) | map({vpc: .[0].vpcId, instances: map(.name + " (" + .instanceId + ")")})}) | .[] | "\n=== Region: \(.region) ===\n" + (.instances | map("VPC: \(.vpc)\n" + (.instances | map(" - \(.)") | join("\n"))) | join("\n"))'
cd /workspace/alchemy && alchemy state export us-west-1.run.ts --local 2>/dev/null | jq -r '.resources | map(select(.state.resourceType == "AWS.EC2.Instance")) | map({region: (.stack | match("us-[a-z]+-[0-9]") | .string), name: .fqn, instanceId: .state.attr.instanceId, vpcId: .state.attr.vpcId}) | sort_by(.region, .vpcId) | group_by(.region) | map("Region: " + .[0].region + "\n" + (group_by(.vpcId) | map(" VPC: " + .[0].vpcId + "\n" + (map(" - " + .name + " (" + .instanceId + ")") | join("\n"))) | join("\n"))) | join("\n")'