En snabbreferens för vanliga administrationsuppgifter med det officiella kommandoradsverktyget AWS Command Line Interface (aws).
Installation & Konfiguration
# macOS (Homebrew)
brew install awscli
# Initiera autentiseringsuppgifter och standardregion
aws configure
# Konfigurera namngivna profiler
aws configure --profile staging
aws configure --profile production
Uppgifter och konfiguration lagras i ~/.aws/credentials och ~/.aws/config.
Amazon S3 (Simple Storage Service)
# Lista hinkar eller innehåll i en hink
aws s3 ls
aws s3 ls s3://my-bucket-name/prefix/
# Kopiera lokal fil till S3
aws s3 cp document.pdf s3://my-bucket-name/docs/
# Synkronisera lokal katalog med S3-hink (med undantag)
aws s3 sync ./build s3://my-bucket-name/web --delete --exclude "*.tmp"
# Ta bort katalog eller prefix rekursivt
aws s3 rm s3://my-bucket-name/temporary-files --recursive
Amazon EC2 (Elastic Compute Cloud)
# Beskriv aktiva instanser
aws ec2 describe-instances \
--filters "Name=instance-state-name,Values=running" \
--query "Reservations[*].Instances[*].[InstanceId,PublicIpAddress,Tags[?Key=='Name'].Value|[0]]" \
--output table
# Starta eller stoppa instanser
aws ec2 start-instances --instance-ids i-0123456789abcdef0
aws ec2 stop-instances --instance-ids i-0123456789abcdef0
# Terminera instans
aws ec2 terminate-instances --instance-ids i-0123456789abcdef0
Amazon ECS (Elastic Container Service)
# Lista kluster
aws ecs list-clusters
# Skapa ett kluster
aws ecs create-cluster --cluster-name production-cluster
# Lista aktiva uppgifter i klustret
aws ecs list-tasks --cluster production-cluster
AWS Elastic Beanstalk CLI (eb)
# Initiera Elastic Beanstalk-applikation
eb init
# Skapa miljö och driftsätt applikation
eb create production-env
eb deploy
# Öppna applikationen i webbläsaren
eb open
# Visa realtidsloggar för applikationen
eb logs
Användbara flaggor & frågor
--profile <name>: Kör kommandot under en specifik IAM-profil.--region <region>: Åsidosätt konfigurerad AWS-region.--output [json|text|table]: Ange CLI-utdataformat (json, text, table).--query '<JMESPath>': Filtrera och extrahera strukturerade attribut med JMESPath-uttryck.