Commande aws

Voir :

aws-shell

cloud-utils

Voir :

http://docs.aws.amazon.com/cli/latest/reference/ec2

Le système doit être à l'heure. Idéalement NTP doit être configuré.

Installation

pip install --user awscli

Générer ~/.aws/config et ~/.aws/credentials

aws configure --profile os1

~/.aws/config

[profile os1] region = eu-west-2 output = text

~/.bash_aliases

alias aws='aws --endpoint-url https://fcu.eu-west-2.outscale.com --profile os1'

Test

aws s3 ls aws ec2 describe-instances --output table

Auto completion

https://docs.aws.amazon.com/fr_fr/cli/latest/userguide/cli-command-completion.html

complete -C "$VIRTUAL_ENV/bin/aws_completer" aws

Exemple

Forcer l'arrêt

aws ec2 stop-instances --instance-ids i-39992709 --force

“Terminate” c'est-à-dire effacer la VM (Destruction de la machine !!!)

aws ec2 terminate-instances --instance-ids i-39992709

Rechercher par “tag”

aws ec2 describe-instances --filter Name=tag:Name,Values=plop

Plusieurs “Security Group” pour une seul VM

aws ec2 modify-instance-attribute --instance-id i-fae31a89 --groups sg-8569c41e sg-b25eb0d1

Get InstanceId from volume-id (attached)

aws ec2 describe-volumes --filters Name=volume-id,Values=vol-0a7d0ea2c73418623 --query 'Volumes[*].Attachments[0].InstanceId' --output text

describe-images

aws ec2 describe-images --owners self --output json | jq '.Images[] | select(.CreationDate<'$GET_AMI') | {ImageId}' | jq --raw-output '.ImageId')) aws ec2 describe-images --owners 679593333241 --filters 'Name=name,Values=debian-stretch-hvm-x86_64-gp2-*' 'Name=state,Values=available' aws ec2 describe-images --owners=self --filters 'Name=name,Values=packer*' --output text aws ec2 deregister-image --image-id ami-00f406c198ce29c37 aws ec2 describe-instances --filters 'Name=tag-value,Values=*App*' --output table aws ec2 describe-images --image-ids ami-01f3682deed220c2a aws ec2 describe-images --owners amazon --filters 'Name=name,Values=amzn2-ami-hvm-2.0.20190612-x86_64-gp2' 'Name=state,Values=available' 'Name=architecture,Values=x86_64' --output text

Debug

aws ec2 describe-regions --debug