AWS CLI Deep Dive

ยท

3 min read

AWS CLI Deep Dive

The AWS CLI Unveiled

The AWS CLI is a unified tool that provides a command-line interface to interact with AWS services. It is built on top of the AWS SDKs (Software Development Kits), allowing developers and administrators to manage and automate AWS resources without needing to access the AWS Management Console. With the CLI, users can perform a wide range of tasks, from provisioning resources to managing security settings, all from the comfort of their terminal.

What problem does Aws Cli solve?

Normally, we create the resources in AWS using UI (user interface) but it is not so cool while we are working in any company. Let's say the Deployment team needs 100 EC2 instances then you cannot create 100 instances one by one, it would be very tedious, and time-consuming but instead that you would write the script to create 100 instances and run that script. Now, your instances will be created within minutes. AWS CLI is used for automation purposes.

Some automation tool

  • Aws Cli

  • CFT

  • Terraform

If all these tools are solving the same problem then why so many tools and why does AWS cli cause it is very quick.If someone says hey list all the s3 bucket now, using the aws command to can get result very quickly which is not possible in other automation tool cause first you have to write the YAML file and after executing that file you will get a list of your bucket.

How AWS CLI works internally?

Whenever you run the script, the request is converted into an API call to Aws and now, aws make sure to create your Resource.

How to install AWS CLI and configure it?

Run the below command to install

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install

Once AWS CLI is installed then Run the below command to Authenticate the aws account

aws configure

Give your Credential, and you are good to go to use aws cli.\

Creating the ec2 using aws cli

Use the aws ec2 run-instances command to create your EC2 instance. Below is a basic example of the command with some parameters you need to provide:

aws ec2 run-instances \
    --image-id ami-xxxxxxxxxxxxxxxxx \   # Replace with your AMI ID
    --instance-type t2.micro \             # Replace with your desired instance type
    --key-name YourKeyName \               # Replace with your SSH key pair name
    --subnet-id subnet-xxxxxxxxxxxxxxxxx  # Replace with your subnet ID

Important command

  1. EC2 (Elastic Compute Cloud):

    • Create an EC2 instance:

        aws ec2 run-instances --image-id <AMI_ID> --instance-type <INSTANCE_TYPE> --key-name <KEY_PAIR_NAME>
      
    • List EC2 instances:

        aws ec2 describe-instances
      
    • Terminate an EC2 instance:

        aws ec2 terminate-instances --instance-ids <INSTANCE_ID>
      
  2. Lambda:

    • Create a new Lambda function:

        aws lambda create-function --function-name <FUNCTION_NAME> --runtime <RUNTIME> --handler <HANDLER_FUNCTION> --role <IAM_ROLE_ARN> --zip-file <ZIP_FILE>
      
    • List Lambda functions:

        aws lambda list-functions
      
    • Update a Lambda function code:

        aws lambda update-function-code --function-name <FUNCTION_NAME> --zip-file <ZIP_FILE>
      
  3. S3 (Simple Storage Service):

    • List objects in an S3 bucket:

        aws s3 ls s3://<BUCKET_NAME>
      

CONCLUSION

AWS CLI is a versatile tool that empowers developers, administrators, and cloud enthusiasts to manage AWS resources efficiently from the command line. By harnessing its capabilities, you can automate processes, streamline deployments, and interact with various AWS services seamlessly. As you embark on your AWS CLI journey, remember that practice and exploration will be your greatest allies in mastering this powerful interface to the cloud.

ย