How to Install AWS Cli :
- Windows Download and run the 64-bit or 32-bit Windows installer
- Mac et Linux Python 2.6.5 or later required. Installation via pip.
$ pip install awscli
Before you run any commands, set your default credentials, using command :
$ aws configure
AWS Access Key ID [None]: Your-AWS-Access-Key
AWS Secret Access Key [None]: Your-AWS-Secret-Access-Key
Default region name [None]: us-west-2
Default output format [None]: ENTER
To get Access Key go to AWS Console in section profile and create Access Key to get AWSAccessKeyId and AWSSecretKey
Run a command to verify that your credentials are configured correctly and that you can connect to AWS.
$ aws ec2 describe-regions --output table
Example 1 : Copy file from you Mac to S3 backet
Start by creating on AWS Console S3 service an S3 bucket named my-test-rcherara-backet
Now with command line we list show this backet and to copy from local station file in this s3 backet with the following commad :
$ aws s3 ls
$ aws s3 cp rcherara-file-to-copy-in-s3.txt s3://my-test-rcherara-backet/
$ aws s3 ls my-test-rcherara-backet
Result:
For more information about s3 command see this link.
Example 2 : Create Security Group :
$ aws ec2 create-security-group --group-name my-sg --description "My security group"
Let's see this group in AWS Console :
Example 3 : Create VPC
This example creates a VPC with the specified IPv4 CIDR block.
Command:
$ aws ec2 create-vpc --cidr-block 10.0.0.0/16
Let's see the result in AWS Console :
Example 4 : Create subnet
$ aws ec2 create-subnet --vpc-id vpc-a01106c2 --cidr-block 10.0.1.0/24
Example 5 : ec2
To Create a Key Pair use this command :
$ aws ec2 create-key-pair --key-name MyKeyPair --query 'KeyMaterial' --output text > MyKeyPair.pem
We use this Key Pair ( in my case is : rcherara-KeyPair-cli.pem ) to create our EC2 instances.
The following command launches a t2.micro
instance in the specified subnet:
$ aws ec2 run-instances --image-id ami-xxxxxxxx --count 1 --instance-type t2.micro --key-name MyKeyPair --security-group-ids sg-xxxxxxxx --subnet-id subnet-xxxxxxxx
aws ec2 run-instances --image-id ami-xxxxxxxx --count 1 --instance-type t2.micro --key-name rcherara-KeyPair-cli --security-group-ids sg-xxxxxxxx --subnet-id subnet-xxxxxxxx
$ aws ec2 run-instances --image-id ami-xxxxxxxx --count 1 --instance-type t2.micro --key-name MyKeyPair --security-group-ids sg-xxxxxxxx --subnet-id subnet-xxxxxxxx
{
"OwnerId": "123456789012",
"ReservationId": "r-5875ca20",
"Groups": [
{
"GroupName": "my-sg",
"GroupId": "sg-903004f8"
}
],
"Instances": [
{
"Monitoring": {
"State": "disabled"
},
"PublicDnsName": null,
"Platform": "windows",
"State": {
"Code": 0,
"Name": "pending"
},
"EbsOptimized": false,
"LaunchTime": "2013-07-19T02:42:39.000Z",
"PrivateIpAddress": "10.0.1.114",
"ProductCodes": [],
"VpcId": "vpc-1a2b3c4d",
"InstanceId": "i-5203422c",
"ImageId": "ami-173d747e",
"PrivateDnsName": ip-10-0-1-114.ec2.internal,
"KeyName": "MyKeyPair",
"SecurityGroups": [
{
"GroupName": "my-sg",
"GroupId": "sg-903004f8"
}
],
"ClientToken": null,
"SubnetId": "subnet-6e7f829e",
"InstanceType": "t2.micro",
"NetworkInterfaces": [
{
"Status": "in-use",
"SourceDestCheck": true,
"VpcId": "vpc-1a2b3c4d",
"Description": "Primary network interface",
"NetworkInterfaceId": "eni-a7edb1c9",
"PrivateIpAddresses": [
{
"PrivateDnsName": "ip-10-0-1-114.ec2.internal",
"Primary": true,
"PrivateIpAddress": "10.0.1.114"
}
],
"PrivateDnsName": "ip-10-0-1-114.ec2.internal",
"Attachment": {
"Status": "attached",
"DeviceIndex": 0,
"DeleteOnTermination": true,
"AttachmentId": "eni-attach-52193138",
"AttachTime": "2013-07-19T02:42:39.000Z"
},
"Groups": [
{
"GroupName": "my-sg",
"GroupId": "sg-903004f8"
}
],
"SubnetId": "subnet-6e7f829e",
"OwnerId": "123456789012",
"PrivateIpAddress": "10.0.1.114"
}
],
"SourceDestCheck": true,
"Placement": {
"Tenancy": "default",
"GroupName": null,
"AvailabilityZone": "us-west-2b"
},
"Hypervisor": "xen",
"BlockDeviceMappings": [
{
"DeviceName": "/dev/sda1",
"Ebs": {
"Status": "attached",
"DeleteOnTermination": true,
"VolumeId": "vol-877166c8",
"AttachTime": "2013-07-19T02:42:39.000Z"
}
}
],
"Architecture": "x86_64",
"StateReason": {
"Message": "pending",
"Code": "pending"
},
"RootDeviceName": "/dev/sda1",
"VirtualizationType": "hvm",
"RootDeviceType": "ebs",
"Tags": [
{
"Value": "MyInstance",
"Key": "Name"
}
],
"AmiLaunchIndex": 0
}
]
}