AWS Cli

The AWS Command Line Interface (CLI) is a tool that allows you to interact with various AWS services from the command line. Here are some working examples of using the AWS CLI:

  1. Installing the AWS CLI: To install the AWS CLI on your local machine, you can follow the instructions provided in the AWS documentation. Here’s an example for installing the AWS CLI on Ubuntu:




sudo apt-get update
sudo apt-get install awscli
  1. Configuring the AWS CLI: Before you can use the AWS CLI, you need to configure it with your AWS credentials. Here’s an example of how to configure the AWS CLI:




aws configure

This command prompts you to enter your AWS access key ID, secret access key, default region name, and default output format. Once you’ve entered these values, the AWS CLI stores them in a configuration file located in the .aws directory in your home directory.

  1. Creating an S3 bucket: To create an S3 bucket using the AWS CLI, you can use the aws s3 mb command. Here’s an example:




aws s3 mb s3://my-bucket-name

This creates an S3 bucket with the name my-bucket-name. The mb command stands for “make bucket”.

  1. Uploading a file to an S3 bucket: To upload a file to an S3 bucket using the AWS CLI, you can use the aws s3 cp command. Here’s an example:




aws s3 cp myfile.txt s3://my-bucket-name/myfile.txt

This uploads the local file myfile.txt to the S3 bucket my-bucket-name with the same filename.

  1. Creating an EC2 instance: To create an EC2 instance using the AWS CLI, you can use the aws ec2 run-instances command. Here’s an example:




aws ec2 run-instances --image-id ami-123456 --count 1 --instance-type t2.micro --key-name my-keypair --security-group-ids sg-123456 --subnet-id subnet-123456

This creates a new EC2 instance with the specified AMI, instance type, and networking settings. The key-name parameter specifies the name of an existing key pair to use for SSH access, and the security-group-ids parameter specifies the ID of an existing security group to use.

  1. Listing EC2 instances: To list your EC2 instances using the AWS CLI, you can use the aws ec2 describe-instances command. Here’s an example:




aws ec2 describe-instances

This lists all EC2 instances in your AWS account.

These are just a few examples of the many things you can do with the AWS CLI. The AWS CLI provides a powerful and flexible way to manage your AWS resources from the command line.

Author: tonyhughes