0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

boto3 初心者編

0
Last updated at Posted at 2026-05-01

EC2の情報をboto3で

参考

import boto3
ec2 = boto3.client('ec2')
ec2_data = ec2.describe_instances()
for ec2_reservation in ec2_data['Reservations']:
    for ec2_instance in ec2_reservation['Instances']:
        ec2_instance_id = ec2_instance['InstanceId']
        ec2_instance_type = ec2_instance['InstanceType']
        ec2_instance_state = ec2_instance['State']['Name']
        
        print(ec2_instance_id + ',' + ec2_instance_type + ',' + ec2_instance_state)

感想

aws cliでもboto3でも
取得するデータは同じ。

両方学習していくほうが
理解が深まる気ようなする。
※俺だけかも

VPCもboto3で

import boto3
ec2 = boto3.client('ec2')
ec2_data = ec2.describe_vpcs()
for ec2_Vpcs in ec2_data['Vpcs']:
        print(f"VPC ID: {ec2_Vpcs['VpcId']}, CIDR: {ec2_Vpcs['CidrBlock']}, Default: {ec2_Vpcs['IsDefault']}")
0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?