1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

AWS CLIのスニペットを公開

Posted at

aws-cliは便利ですが、ちゃんと使うには些か慣れが入ります。これからaws-cliをばりばり使っていこうと思っている方向けに(&備忘録用に)普段自分が使っているaws-cilのスニペットを公開します。

EC2

  • 対象のEC2インスタンスの情報を取得
aws ec2 describe-instances --instance-ids ${INSTANCE_ID}
  • 最新のAmazon Linux2 AMI
aws ec2 describe-images --owners amazon --filters 'Name=name,Values=amzn2-ami-hvm-2.0.????????.?-x86_64-gp2' 'Name=state,Values=available' --query 'reverse(sort_by(Images, &CreationDate))[:1].ImageId' --output text
  • インスタンスタイプを一覧表示
aws ec2 describe-instance-types --query 'sort_by(InstanceTypes[].{InstanceType:InstanceType, Hypervisor:Hypervisor, Memory:MemoryInfo.SizeInMiB},&Memory)' --output table
  • インスタンスを一覧表示
aws ec2 describe-instances --query 'Reservations[].Instances[].{Name: Tags[?Key==`Name`].Value|[0], InstanceId: InstanceId, Status: State.Name, InstanceType:InstanceType}' --output table

Security Group

  • SecurityGroupを一覧表示
aws ec2 describe-security-groups --query 'SecurityGroups[].{Name:GroupName, GroupId:GroupId, VpcId: VpcId}' --output table

Cloudformation

  • スタックを一覧表示
aws cloudformation list-stacks --query 'StackSummaries[].StackName'
  • [スタックを指定]スタックのステータスを確認
aws cloudformation describe-stacks --stack-name ${STACK_NAME} --query 'Stacks[].{StackName: StackName, StackStatus: StackStatus}' --output table 

VPC

  • VPCを一覧表示
aws ec2 describe-vpcs --query 'Vpcs[].{Name: Tags[?Key==`Name`].Value|[0], VpcId:VpcId}' --output table
  • Subnetを一覧表示
aws ec2 describe-subnets --query 'Subnets[].{Name:Tags[?Key==`Name`].Value|[0], SubnetId:SubnetId}|sort_by(@,&Name)' --output table

IAM

  • インスタンスプロファイルを一覧表示
aws iam list-instance-profiles --query 'InstanceProfiles[].{Name: InstanceProfileName, Arn:Arn}' --output table

SSM

  • SSM接続可なインスタンスを一覧表示
aws ec2 describe-instances --query 'Reservations[].Instances[?State.Name==`running`][].{Name: Tags[?Key==`Name`].Value|[0], InstanceId: InstanceId}' --output text

ALB

  • ALB名とDNS名を一覧表示
aws elbv2 describe-load-balancers --query "LoadBalancers[].{Name: LoadBalancerName, DNSName:DNSName}" --output table
1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?