Upgrade to Pro — share decks privately, control downloads, hide ads and more …

初心者だからこそ触りたい、AWS CLI ~ "躓きやすい"を無くしたい ~ #devio2020

初心者だからこそ触りたい、AWS CLI ~ "躓きやすい"を無くしたい ~ #devio2020

Developers.IO 2020 Connectでの登壇資料です。
初心者が苦手意識を持ちやすいAWS CLIですが、初心者だからこそ触ってみてよかったと思った点などをお話ししています。
ぜひみなさんもAWS CLIに入門されてはどうでしょうか。

Kana Kitagawa

June 16, 2020
Tweet

More Decks by Kana Kitagawa

Other Decks in Technology

Transcript

  1. ࡉ͔͘෼͚͍ͯ͘  aws ec2 create-route-table --vpc-id XXX aws ec2 create-route

    --route-table-id XXX —destination-cidr-block 0.0.0.0/0 —gateway-id XXX aws ec2 associate-route-table --subnet-id XXXXX —route-table-id XXX
  2. ࣮ࡍͷγΣϧεΫϦϓτ  #!/bin/bash VPC=`aws ec2 create-vpc --cidr-block $1 | jq

    '.Vpc | .VpcId' | tr -d '"'` echo $VPC SUBNET_PUB=`aws ec2 create-subnet --vpc-id $VPC --cidr-block $2 | jq '.Subnet | .SubnetId' | tr -d '"'` SUBNET_PRI=`aws ec2 create-subnet --vpc-id $VPC --cidr-block $3 | jq '.Subnet | .SubnetId' | tr -d '"'` echo $SUBNET_PUB echo $SUBNET_PRI IGW=`aws ec2 create-internet-gateway | jq '.InternetGateway | .InternetGatewayId' | tr -d '"'` aws ec2 attach-internet-gateway --internet-gateway-id $IGW --vpc-id $VPC RT=`aws ec2 create-route-table --vpc-id $VPC | jq '.RouteTable | .RouteTableId' | tr -d '"'` aws ec2 create-route --route-table-id $RT --destination-cidr-block 0.0.0.0/0 --gateway-id $IGW aws ec2 associate-route-table --subnet-id $SUBNET_PUB --route-table-id $RT | jq '.AssociationState' aws ec2 modify-subnet-attribute --subnet-id $SUBNET_PUB --map-public-ip-on-launch aws ec2 create-key-pair --key-name $4 --query 'KeyMaterial' --output text > ~/.ssh/$4.pem chmod 400 ~/.ssh/$4.pem SG=`aws ec2 create-security-group --group-name Test-SecurityG --description "Security group for SSH access Internet access" --vpc-id $VPC | jq .GroupId | tr -d '"'` MYIP=`curl -s ifconfig.me` MYIP="$MYIP/32" aws ec2 authorize-security-group-ingress --group-id $SG --protocol tcp --port 22 --cidr $MYIP aws ec2 authorize-security-group-ingress --group-id $SG --protocol tcp --port 80 --cidr $MYIP aws ec2 describe-security-groups --group-ids $SG | jq '.SecurityGroups[] | .IpPermissions[]' INSTANCE_ID=`aws ec2 run-instances --image-id ami-0f310fced6141e627 --count 1 --instance-type t2.nano --key-name $4 --security-group-ids $SG --subnet-id $SUBNET_PUB | jq '.Instances[] | .InstanceId' | tr -d '"'` aws ec2 describe-instances --instance-id $INSTANCE_ID | jq '.Reservations[] | .Instances[] | .KeyName, .PublicIpAddress'
  3. ࣮ࡍͷγΣϧεΫϦϓτ  #!/bin/bash VPC=`aws ec2 create-vpc --cidr-block $1 | jq

    '.Vpc | .VpcId' | tr -d '"'` echo $VPC SUBNET_PUB=`aws ec2 create-subnet --vpc-id $VPC --cidr-block $2 | jq '.Subnet | .SubnetId' | tr -d '"'` SUBNET_PRI=`aws ec2 create-subnet --vpc-id $VPC --cidr-block $3 | jq '.Subnet | .SubnetId' | tr -d '"'` echo $SUBNET_PUB echo $SUBNET_PRI IGW=`aws ec2 create-internet-gateway | jq '.InternetGateway | .InternetGatewayId' | tr -d '"'` aws ec2 attach-internet-gateway --internet-gateway-id $IGW --vpc-id $VPC RT=`aws ec2 create-route-table --vpc-id $VPC | jq '.RouteTable | .RouteTableId' | tr -d '"'` aws ec2 create-route --route-table-id $RT --destination-cidr-block 0.0.0.0/0 --gateway-id $IGW aws ec2 associate-route-table --subnet-id $SUBNET_PUB --route-table-id $RT | jq '.AssociationState' aws ec2 modify-subnet-attribute --subnet-id $SUBNET_PUB --map-public-ip-on-launch aws ec2 create-key-pair --key-name $4 --query 'KeyMaterial' --output text > ~/.ssh/$4.pem chmod 400 ~/.ssh/$4.pem SG=`aws ec2 create-security-group --group-name Test-SecurityG --description "Security group for SSH access Internet access" --vpc-id $VPC | jq .GroupId | tr -d '"'` MYIP=`curl -s ifconfig.me` MYIP="$MYIP/32" aws ec2 authorize-security-group-ingress --group-id $SG --protocol tcp --port 22 --cidr $MYIP aws ec2 authorize-security-group-ingress --group-id $SG --protocol tcp --port 80 --cidr $MYIP aws ec2 describe-security-groups --group-ids $SG | jq '.SecurityGroups[] | .IpPermissions[]' INSTANCE_ID=`aws ec2 run-instances --image-id ami-0f310fced6141e627 --count 1 --instance-type t2.nano --key-name $4 --security-group-ids $SG --subnet-id $SUBNET_PUB | jq '.Instances[] | .InstanceId' | tr -d '"'` aws ec2 describe-instances --instance-id $INSTANCE_ID | jq '.Reservations[] | .Instances[] | .KeyName, .PublicIpAddress'
  4. ࣮ࡍͷ࣮ߦ݁Ռ  VPC ID PUBLIC SUBNET ID PRIVATE SUBNET ID

    ϧʔτΛ࡞Ε͔ͨ ϧʔτςʔϒϧ͕ඥ͍͔ͮͨ ηΩϡϦςΟάϧʔϓͷத਎ Ωʔͷ໊લ ύϒϦοΫIP