Close

2023-04-09

Unleash the Power of AWS CLI: A Beginner’s Guide to Cloud Automation

Unleash the Power of AWS CLI: A Beginner's Guide to Cloud Automation

You can use the AWS Command Line Interface (CLI) on macOS by following these steps:

Install the AWS CLI: You can install the AWS CLI on macOS using pip, the Python package installer. Open the Terminal application on your macOS and enter the following command:

sudo pip install awscli

This will install the AWS CLI on your system.

Configure the AWS CLI: Once installed, you must configure it with your AWS credentials. You can do this by entering the following command in the Terminal application:

aws configure

This will prompt you to enter your AWS Access Key ID, AWS Secret Access Key, default region, and default output format.

Test the AWS CLI: Once you have configured it, you can test it by entering a command in the Terminal application. For example, you can enter the following command to list all the S3 buckets in your AWS account:


aws s3 ls


This should return a list of all the S3 buckets in your account.

That’s it! You can now use the AWS CLI on macOS to manage your AWS resources from the command line. You can find more information on how to use the AWS CLI in the AWS CLI documentation.

Here are some examples of AWS CLI commands

#AWS CLI Examples
#List all S3 buckets:
aws s3 ls
#This command lists all the S3 buckets in your AWS account.
#Create an S3 bucket:
aws s3 mb s3://my-bucket
#This command creates a new S3 bucket named "my-bucket".
#Upload a file to an S3 bucket:
aws s3 cp file.txt s3://my-bucket/file.txt
#This command uploads a file named "file.txt" to the "my-bucket" S3 bucket.
#Download a file from an S3 bucket:
aws s3 cp s3://my-bucket/file.txt file.txt
#This command downloads the "file.txt" file from the "my-bucket" S3 bucket and saves it to your local machine.
#List EC2 instances:
aws ec2 describe-instances
#This command lists all the EC2 instances in your AWS account.
#Create an EC2 instance:
aws ec2 run-instances –image-id ami-0c94855ba95c71c99 –count 1 –instance-type t2.micro –key-name my-key-pair –security-group-ids sg-12345678
#This command creates a new EC2 instance with the specified parameters.
#Create an EC2 instance:
aws ec2 run-instances –image-id ami-1234567890abcdef0 –count 1 –instance-type t2.micro –key-name my-key-pair –security-group-ids sg-12345678
#This command creates a new EC2 instance with the specified parameters.
#Stop an EC2 instance:
aws ec2 stop-instances –instance-ids i-1234567890abcdef0
#This command stops the EC2 instance with the specified ID.
#Start an EC2 instance:
aws ec2 start-instances –instance-ids i-1234567890abcdef0
#This command starts the EC2 instance with the specified ID.
#Terminate an EC2 instance:
aws ec2 terminate-instances –instance-ids i-1234567890abcdef0
#This command terminates the EC2 instance with the specified ID.
#List all EC2 instances:
aws ec2 describe-instances
#This command lists all the EC2 instances in your AWS account.
#List all available EC2 instance types:
aws ec2 describe-instance-types
#This command lists all the available EC2 instance types in your AWS account.
#Create a new security group:
aws ec2 create-security-group –group-name my-security-group –description "My security group"
#This command creates a new security group with the specified name and description.
#Add a rule to a security group:
aws ec2 authorize-security-group-ingress –group-id sg-12345678 –protocol tcp –port 22 –cidr 0.0.0.0/0
#This command adds a rule to the specified security group that allows incoming SSH traffic from any IP address.
#List all available Amazon Machine Images (AMIs):
aws ec2 describe-images –owners amazon
#This command lists all the available AMIs in your AWS account.
#List all running EC2 instances:
aws ec2 describe-instances –filters "Name=instance-state-name,Values=running"
#This command lists all the running EC2 instances in your AWS account.
#List all running RDS instances:
aws rds describe-db-instances –filters "Name=db-instance-status,Values=available"
#This command lists all the running RDS instances in your AWS account.
#List all running Elastic Beanstalk environments:
aws elasticbeanstalk describe-environments –environment-ids $(aws elasticbeanstalk list-environments –query "Environments[?Status=='Ready'].EnvironmentId" –output text)
#This command lists all the running Elastic Beanstalk environments in your AWS account.
#List all running ECS clusters:
aws ecs list-clusters
#This command lists all the ECS clusters in your AWS account, including the running ones.
#List all running Lambda functions:
aws lambda list-functions –query "Functions[?State=='Active']"
#This command lists all the running Lambda functions in your AWS account.
#Create an RDS instance:
aws rds create-db-instance –db-instance-identifier mydbinstance –engine mysql –db-instance-class db.t2.micro –master-username myusername –master-user-password mypassword –allocated-storage 20
#This command creates a new RDS instance with the specified parameters.
#Stop an RDS instance:
aws rds stop-db-instance –db-instance-identifier mydbinstance
#This command stops the RDS instance with the specified identifier.
#Start an RDS instance:
aws rds start-db-instance –db-instance-identifier mydbinstance
#This command starts the RDS instance with the specified identifier.
#Modify an RDS instance:
aws rds modify-db-instance –db-instance-identifier mydbinstance –allocated-storage 30 –db-instance-class db.m5.large
#This command modifies the specified RDS instance by changing its allocated storage and instance class.
#List all RDS instances:
aws rds describe-db-instances
#This command lists all the RDS instances in your AWS account.
#Delete an RDS instance:
aws rds delete-db-instance –db-instance-identifier mydbinstance –skip-final-snapshot
#This command deletes the specified RDS instance and skips the final snapshot.
#Create an RDS snapshot:
aws rds create-db-snapshot –db-instance-identifier mydbinstance –db-snapshot-identifier mysnapshot
#This command creates a new snapshot of the specified RDS instance.
#List all available RDS snapshots:
aws rds describe-db-snapshots
#This command lists all the available RDS snapshots in your AWS account.

These are just a few examples of the many AWS services you can list with the AWS CLI. In the AWS CLI documentation, you can find more information on using the AWS CLI to manage and list services.