aws

Master AWS CLI commands for efficient cloud management. Learn to configure, manage EC2 instances, S3 buckets, CloudFormation stacks, and more with this comprehensive guide.

AWS CLI Commands

AWS CLI Installation and Configuration

To begin managing your AWS resources from the command line, you first need to install and configure the AWS Command Line Interface (CLI). The installation is straightforward, often available through package managers. For Ubuntu 16.04 and later, pip install awscli is a common method. After installation, run aws configure to set up your AWS credentials and default region, which are essential for authenticating your commands.

Managing EC2 Instances with AWS CLI

The AWS CLI provides powerful tools for managing your Elastic Compute Cloud (EC2) instances. You can retrieve detailed information about your instances using aws ec2 describe-instances. To specifically list the public IP addresses of your running instances, a targeted query can be used: aws ec2 describe-instances --query "Reservations[*].Instances[*].PublicIpAddress" --output=text. Starting or stopping instances is also simplified; for example, to start an instance, use aws ec2 start-instances --instance-ids i-12345678c.

Working with Amazon S3 Buckets

Amazon Simple Storage Service (S3) is a key component of AWS for object storage. The AWS CLI facilitates easy interaction with S3 buckets. You can copy entire directories to an S3 bucket recursively with aws s3 cp ${directory} s3://${bucket}/${directory} --recursive. For more advanced synchronization, ensuring local and remote directories are identical, aws s3 sync ${directory} s3://${bucket}/${directory} --exclude *.tmp is highly effective, allowing you to exclude temporary files. Listing all your S3 buckets is as simple as aws s3 ls. Removing a bucket, if necessary, can be done with aws s3 rb --force s3://${bucket_name}. Retrieving bucket logging information is also possible via aws s3api get-bucket-logging --bucket ${bucket_name}.

Utilizing AWS CloudFormation

AWS CloudFormation allows you to model and provision your AWS infrastructure as code. The CLI can be used to manage your CloudFormation stacks. A common task is listing stacks based on their status, which can be achieved with aws cloudformation list-stacks --stack-status-filter [ CREATE_COMPLETE | UPDATE_COMPLETE | etc.. ]. This command helps in monitoring the state of your deployed infrastructure.

For a more extensive list of AWS CLI commands and their usage, refer to the official AWS CLI documentation and community resources.

Follow the below link for some other useful commands: AWS CLI Cheat Sheet