AWS CLI cheat sheet
2023. 10. 10. 13:27ㆍAWS/AWS Command Line Interface
728x90
SMALL
- 개요
AWS CLI를 통해 리소스를 관리하고 리스트화 할 수 있는 스크립트를 정리했다. 대표적인 리소스를 테이블 또는 리스트로 관리할 수 있는 스크립들이다.
- AWS CLI
https://awscli.amazonaws.com/v2/documentation/api/latest/reference/index.html#cli-aws
- EC2
## runnung ec2 with Name, PrivateIP, PublicIP, Status, Instance Type, VpcId on table
aws ec2 describe-instances --query "Reservations[*].Instances[*].{PublicIP:PublicIpAddress,PrivateIP:PrivateIpAddress,Name:Tags[?Key=='Name']|[0].Value,Type:InstanceType,Status:State.Name,VpcId:VpcId}" --filters Name=instance-state-name,Values=running --output table
## runnung ec2 with Name, PublicIP, Status on table
aws ec2 describe-instances --query "Reservations[*].Instances[*].{PublicIP:PublicIpAddress,Name:Tags[?Key=='Name']|[0].Value,Status:State.Name}" --filters "Name=instance-state-name,Values=running" "Name=tag:Name,Values='*'" --output table
## runnung ec2 with Name with dev, PublicIP, Status on table
aws ec2 describe-instances --query "Reservations[*].Instances[*].{PublicIP:PublicIpAddress,Name:Tags[?Key=='Name']|[0].Value,Status:State.Name}" --filters "Name=instance-state-name,Values=running" "Name=tag:Name,Values='*dev*'" --output table
## runnung ec2 with Name with prod, PublicIP, Status on table
aws ec2 describe-instances --query "Reservations[*].Instances[*].{PublicIP:PublicIpAddress,Name:Tags[?Key=='Name']|[0].Value,Status:State.Name}" --filters "Name=instance-state-name,Values=running" "Name=tag:Name,Values='*prod*'" --output table
## runnung ec2 with Security Group, IamInstanceProfile, InstanceID, Name, PrivateIP, PublicIP, Status, VpcID on table
aws ec2 describe-instances --query "Reservations[*].Instances[*].{PublicIP:PublicIpAddress,PrivateIP:PrivateIpAddress,Name:Tags[?Key=='Name'].Value|[0],Status:State.Name,VpcId:VpcId,InstanceID:InstanceId,Groups:join(',',NetworkInterfaces[].Groups[].GroupId),IamInstanceProfile:IamInstanceProfile.Arn}" --filters "Name=instance-state-name,Values=running" --output table
- Network Interfaces
# Private IP addresses Table
aws ec2 describe-network-interfaces --query NetworkInterfaces[*].PrivateIpAddresses[].PrivateIpAddress --output table
# Public IP addresses Table
aws ec2 describe-network-interfaces --query NetworkInterfaces[*].PrivateIpAddresses[].Association[].PublicIp --output table
# IPv6 addresses Table
aws ec2 describe-network-interfaces --query 'NetworkInterfaces[*].{Ipv6Address:Ipv6Address}' --output table
# Private & Public & IPv6 IP addresses Table
aws ec2 describe-network-interfaces --query 'NetworkInterfaces[*].{PrivateIP:PrivateIpAddresses[].PrivateIpAddress|[0], PublicIP:PrivateIpAddresses[].Association.PublicIp|[0], Ipv6Address:Ipv6Address}' --output table
- EBS
## list all volumes
aws ec2 describe-volumes --query 'Volumes[*].{VolumeID:VolumeId,Size:Size,Type:VolumeType,AvailabilityZone:AvailabilityZone,State:State}' --output table
## list all volumes status available
aws ec2 describe-volumes --filter "Name=status,Values=available" --query 'Volumes[*].{VolumeID:VolumeId,Size:Size,Type:VolumeType,AvailabilityZone:AvailabilityZone,Status:State}' --output table
## list all volumes type gp3
aws ec2 describe-volumes --filter "Name=volume-type,Values=gp3" --query 'Volumes[*].{VolumeID:VolumeId,Size:Size,Type:VolumeType,AvailabilityZone:AvailabilityZone,Status:State}' --output table
## list all volumes type gp2
aws ec2 describe-volumes --filter "Name=volume-type,Values=gp2" --query 'Volumes[*].{VolumeID:VolumeId,Size:Size,Type:VolumeType,AvailabilityZone:AvailabilityZone,Status:State}' --output table
## list all volumes without name tag
aws ec2 describe-volumes --region ap-northeast-2 --query 'Volumes[?!not_null(Tags[])].[VolumeId]' --output table
- ECS
## list ecs clusters
aws ecs list-clusters
## enable container insights
aws ecs update-cluster-settings --cluster myCICluster --settings name=containerInsights,value=enabled
## ecs last event log
aws ecs describe-services --services <service> --region <region> --cluster <cluster> --query 'services[*].events[0]' --output text
## ecs service list per cluster
for ecscluster in $(aws ecs list-clusters --query 'clusterArns' --output text); do aws ecs list-services --cluster $ecscluster --output table; done
- VPC
## VpcId, CidrBlock, Name on table
aws ec2 describe-vpcs --query 'Vpcs[*].{VpcId:VpcId,Name:Tags[?Key==`Name`].Value|[0],CidrBlock:CidrBlock}' --output table
- Cloudwatch
## listing cloudwatch logs group
aws logs describe-log-groups --query logGroups[*].logGroupName
- S3
## largest file in S3 bucket
aws s3api list-objects-v2 --bucket bucket-name --query "sort_by(Contents, &Size)[-1:]"
- Codepipeline
## listing codepipeline
aws codepipeline list-pipelines --query "pipelines[].name"
## release change
aws codepipeline start-pipeline-execution --name MyFirstPipeline
- Cloudfront
## distributions list
aws cloudfront list-distributions
## OAI list
aws cloudfront list-distributions --query DistributionList.Items[].Origins[].Items[].OriginAccessControlId
## OAC list
aws cloudfront list-distributions --query DistributionList.Items[].Origins[].Items[].S3OriginConfig[].OriginAccessIdentity
728x90
LIST
'AWS > AWS Command Line Interface' 카테고리의 다른 글
AWS CLI 최신 버전 설치 또는 업데이트 하기 (0) | 2023.12.29 |
---|---|
AWS CLI output table as multi columns (0) | 2023.10.10 |
파일에서 aws access key와 secret key 추출 (0) | 2022.12.14 |
AWS Cli under ipv6 (0) | 2022.11.23 |
s3 파일 다운로드 없이 CLI로 간단히 보는 방법 (0) | 2022.10.12 |