Commanding the Cloud: Improve Automation by Setting up AWS CLI.

AWS Decoded, Your Ultimate Handbook for Cloud Mastery. Part-6.

·

4 min read

Commanding the Cloud: Improve Automation by Setting up AWS CLI.

About Me:

Hey Folks! I'm Vishwa, a DevOps and OpenSource enthusiast. I am currently doing LearnInPublic and BuildInPublic, where I'll be documenting my entire journey on LinkedIn and Twitter to be accountable and to connect with many like-minded people to seek knowledge from them and help each other. In this series, I'll delve deeper into cloud computing, with a specific focus on AWS. This journey enables effortless learning and experimentation. My goal is to simplify complex concepts for all. Without further delay, let's get into Part 6 of the series that's all about the AWS CLI.

What is AWS CLI & Why it is used?

- CLI is nothing but a command-line interface, where we use a bunch of commands to execute tasks. AWS has its own CLI; we need to install it in our system to use it.

- It is used to get quicker responses.
Example: Listing the S3 Buckets available.

Why go with CLI then UI?

- Using the user interface won't be automation-friendly, but we can do it with the help of the CLI.

Example: Creating an EC2 instance.

- Let's say we need to create ten EC2 instances. Doing it via the user interface will be a time-consuming process, but we can do it by running a command in the AWS CLI.

Here is the sample command for creating 10 EC2:
$ aws ec2 run-instances --image-id ami-xxxxxxxxxxxxxxxxx --instance-type t2.micro --key-name YourKeyPairName --subnet-id subnet-xxxxxxxxxxxxxxxxx --count 10

What really happening under the hood?

- Once the command is executed, the AWS CLI takes care of converting it into an API call, which is then sent to AWS for resource management.

- We don't want to worry about creating an API; AWS already has a Python application, and using that AWS CLI will help us achieve what we want to do.

Example: $ ./aws s3 ls

AWS CLI Installation:

- Navigate to the AWS CLI official documentation for installing it.

You can use the below link and install it as per your operating system, https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html.

- To confirm the installation, check the version of it by using the following command: $ aws --version

Output will be like:

Configuration:

- Now we need to configure our AWS CLI with our console. We need security credentials for this.

Step 1: Navigate to the AWS Management Console and look for security credentials under your account details.

Step 2:Once entered into the security credentials, look for the Create Access Key option.

Step 3: Click the Create access key option and choose the Command Line Tool option for accessing an AWS account.

Step 4: Give a tag to the access key and click the Create Access Key option.

Step 5: Now that it will be created, please note down the access key and the secret key. Follow the instructions mentioned under keys for best practices.

Step 6: Now use the command $ aws configure and provide the details to connect with our AWS account.

Kudos folks, Now it will be successfully configured.

Note: For passing arguments while executing tasks via the AWS CLI, please refer to the official docs.

Listing the S3 Buckets available though AWS CLI:

- Use command $ aws s3 ls

AWS Console:

AWS CLI Result:

Note: Please refer to the documents for the arguments for the tasks you want to perform.

Drawbacks of AWS CLI:

- We aren't able to use the CLI for complicated tasks. It's difficult to use it. That's where IAC tools like Terraform and CFT come into the picture.

- Even though we use commands, it's difficult because we mostly use the documents for reference, and running a big command like mentioning EC2+VPC is a big thing.

Example: aws ec2 run-instances --image-id ami-xxxxxxxxxxxxxxxxx --instance-type t2.micro --key-name YourKeyPairName --security-group-ids sg-xxxxxxxxxxxxxx --subnet-id subnet-xxxxxxxxxxxxxxxxx --associate-public-ip-address

Conclusion:

I am grateful to all those who have read it. I hope reading it was enjoyable for you. Please let me know if you found it useful by leaving a comment, giving it a like, and forwarding it to your friends. Lets explore about Iac using CFT in the upcomming part. I want to thank everyone again.

Did you find this article valuable?

Support VISHWA S's blog by becoming a sponsor. Any amount is appreciated!