My Tweetcards

最近のTweet

print("hogehoge timer")
hogehoge timer
!which aws
!aws s3 -h
/usr/local/bin/aws
usage: aws [-h] [--profile PROFILE] [--debug]

optional arguments:
  -h, --help         show this help message and exit
  --profile PROFILE
  --debug
%pip install boto3
%pip install pandas
Requirement already satisfied: boto3 in /opt/conda/lib/python3.9/site-packages (1.23.3)
Requirement already satisfied: botocore<1.27.0,>=1.26.3 in /opt/conda/lib/python3.9/site-packages (from boto3) (1.26.3)
Requirement already satisfied: jmespath<2.0.0,>=0.7.1 in /opt/conda/lib/python3.9/site-packages (from boto3) (1.0.0)
Requirement already satisfied: s3transfer<0.6.0,>=0.5.0 in /opt/conda/lib/python3.9/site-packages (from boto3) (0.5.2)
Requirement already satisfied: urllib3<1.27,>=1.25.4 in /opt/conda/lib/python3.9/site-packages (from botocore<1.27.0,>=1.26.3->boto3) (1.26.9)
Requirement already satisfied: python-dateutil<3.0.0,>=2.1 in /opt/conda/lib/python3.9/site-packages (from botocore<1.27.0,>=1.26.3->boto3) (2.8.2)
Requirement already satisfied: six>=1.5 in /opt/conda/lib/python3.9/site-packages (from python-dateutil<3.0.0,>=2.1->botocore<1.27.0,>=1.26.3->boto3) (1.16.0)
Note: you may need to restart the kernel to use updated packages.
Requirement already satisfied: pandas in /opt/conda/lib/python3.9/site-packages (1.4.2)
Requirement already satisfied: numpy>=1.18.5 in /opt/conda/lib/python3.9/site-packages (from pandas) (1.22.3)
Requirement already satisfied: pytz>=2020.1 in /opt/conda/lib/python3.9/site-packages (from pandas) (2022.1)
Requirement already satisfied: python-dateutil>=2.8.1 in /opt/conda/lib/python3.9/site-packages (from pandas) (2.8.2)
Requirement already satisfied: six>=1.5 in /opt/conda/lib/python3.9/site-packages (from python-dateutil>=2.8.1->pandas) (1.16.0)
Note: you may need to restart the kernel to use updated packages.
import os
import boto3
import pandas as pd

os.environ['AWS_DEFAULT_REGION'] = 'ap-northeast-1'
client = boto3.client('iam')
client.list_users()

ec2_client = boto3.client('ec2')
vpcs = ec2_client.describe_vpcs()['Vpcs']
data = []
for vpc in vpcs:
    # Name タグの取得
    tags_filter = [t.get('Value') for t in vpc['Tags'] if t.get('Key') == "Name"]
    name = tags_filter[0] if tags_filter else ''
    # Cidr 取得と buffer 格納
    for assoc in vpc['CidrBlockAssociationSet']:
        # data.append([
        #     name,
        #     vpc['VpcId'],
        #     assoc['CidrBlock'],
        #     vpc['InstanceTenancy'],
        #     vpc['IsDefault']
        # ])
        data.append([
            vpc['InstanceTenancy'],
            vpc['IsDefault']
        ])
df_vpcs = pd.DataFrame(data,  columns=["Tenancy", "IsDefault"])
df_vpcs
Tenancy IsDefault
0 default False
1 default False
rtbs = ec2_client.describe_route_tables()['RouteTables']
df_rtbs = pd.DataFrame(rtbs,  columns=["SubnetId"])
df_rtbs
SubnetId
0 NaN
1 NaN
2 NaN
3 NaN
4 NaN

ノブの画像貼ってみる

LGTM