AWS CLI: Conheça alguns comandos e dicas que vão te ajudar no dia a dia

SDK’s
$ aws <command> <subcommand> [options and parameters]
root@amaury:~# aws ec2 start-instances --instance-ids i-082f3d641e2c07a80 i-0e17198ccef021229 i-0e709937096f6f554
{
"StartingInstances": [
{
"InstanceId": "i-0e709937096f6f554",
"CurrentState": {
"Code": 0,
"Name": "pending"
},
"PreviousState": {
"Code": 80,
"Name": "stopped"
}
},
{
"InstanceId": "i-0e17198ccef021229",
"CurrentState": {
"Code": 0,
"Name": "pending"
},
"PreviousState": {
"Code": 80,
"Name": "stopped"
}
},
{
"InstanceId": "i-082f3d641e2c07a80",
"CurrentState": {
"Code": 0,
"Name": "pending"
},
"PreviousState": {
"Code": 80,
"Name": "stopped"
}
}
]
}
root@amaury:~# aws ec2 stop-instances --instance-ids i-082f3d641e2c07a80 i-0e17198ccef021229 i-0e709937096f6f554 --output table
---------------------------
| StopInstances |
+-------------------------+
|| StoppingInstances ||
|+-----------------------+|
|| InstanceId ||
|+-----------------------+|
|| i-0e709937096f6f554 ||
|+-----------------------+|
||| CurrentState |||
||+-------+-------------+||
||| Code | Name |||
||+-------+-------------+||
||| 64 | stopping |||
||+-------+-------------+||
||| PreviousState |||
||+--------+------------+||
||| Code | Name |||
||+--------+------------+||
||| 16 | running |||
||+--------+------------+||
|| StoppingInstances ||
|+-----------------------+|
|| InstanceId ||
|+-----------------------+|
|| i-0e17198ccef021229 ||
|+-----------------------+|
||| CurrentState |||
||+-------+-------------+||
||| Code | Name |||
||+-------+-------------+||
||| 64 | stopping |||
||+-------+-------------+||
||| PreviousState |||
||+--------+------------+||
||| Code | Name |||
||+--------+------------+||
||| 16 | running |||
||+--------+------------+||
|| StoppingInstances ||
|+-----------------------+|
|| InstanceId ||
|+-----------------------+|
|| i-082f3d641e2c07a80 ||
|+-----------------------+|
||| CurrentState |||
||+-------+-------------+||
||| Code | Name |||
||+-------+-------------+||
||| 64 | stopping |||
||+-------+-------------+||
||| PreviousState |||
||+--------+------------+||
||| Code | Name |||
||+--------+------------+||
||| 16 | running |||
||+--------+------------+||
$ pip3 --version
$ python --version
$ pip3 install awscli --upgrade --user
aws --version
aws-cli/1.17.9 Python/2.7.17 Linux/5.3.0-29-generic botocore/1.14.9
$ aws configure
AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: us-west-2
Default output format [None]: json
$ aws ec2 describe-instances --query "Reservations[*].Instances[*].InstanceId"
[
[
"i-02f5aa06af8838f8a",
"i-01cb845d279218c20",
"i-00835abcb71700b5e"
],
[
"i-082f3d641e2c07a50",
"i-0e709937096f6f525",
"i-0e17198ccef02124f"
]
]
$ aws ec2 describe-instances --query "Reservations[*].Instances[*].VpcId"
[
[
"vpc-2f0bb010",
"vpc-2f0bb010",
"vpc-2f0bb010"
],
[
"vpc-2f0bb010",
"vpc-2f0bb010",
"vpc-2f0bb010"
]
]
$ aws ec2 describe-instances | grep running
"Name": "running"
"Name": "running"
"Name": "running"
$ aws ec2 describe-instances | grep -i "us-east"
"AvailabilityZone": "us-east-1d"
$ aws ec2 create-volume --availability-zone us-east-1d --size 1 --volume-type gp2
{
"AvailabilityZone": "us-east-1d",
"Tags": [],
"Encrypted": false,
"VolumeType": "gp2",
"VolumeId": "vol-021ef80f1a46be24r",
"State": "creating",
"Iops": 100,
"SnapshotId": "",
"CreateTime": "2020-01-30T10:50:35.000Z",
"Size": 1
}
$ aws ec2 attach-volume --device "/dev/xvdb" --volume-id vol-021ef80f1a46be24r --instance-id i-03761bc1d46c42560
{
"AttachTime": "2020-01-30T10:56:59.384Z",
"InstanceId": "i-03761bc1d46c42560",
"VolumeId": "vol-021ef80f1a46be24r",
"State": "attaching",
"Device": "/dev/xvdb"
}

Senior Linux Administrator @IBM

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store