0% found this document useful (0 votes)
28 views3 pages

6 - Aws Cli

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views3 pages

6 - Aws Cli

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Module 6: AWS CLI (Command Line Interface)

Introduction to AWS CLI

The AWS Command Line Interface (CLI) is a powerful tool that allows you to interact with AWS services
directly from your command line. It enables you to manage your AWS infrastructure and services through
simple commands, making it ideal for automation, scripting, and efficient resource management across
Windows, macOS, and Linux environments.

Benefits of AWS CLI:

● Automation: Easily automate tasks by scripting AWS CLI commands.


● Simplicity: Perform complex operations with simple commands.
● Consistency: Manage AWS services consistently across different environments.
● Efficiency: Streamline tasks without needing to navigate through the AWS Management
Console.

Installation and Configuration

To install the AWS CLI, visit the official AWS CLI installation page. The page provides detailed
instructions for installing the AWS CLI on various operating systems.

After installing, you’ll need to configure the AWS CLI with your AWS credentials:

1. Open your command line terminal.


2. Run aws configure.
3. Enter your AWS Access Key ID, Secret Access Key, default region, and preferred output format.

Your configuration settings are stored in the ~/.aws/credentials and ~/.aws/config files.

You can also set configuration values using environment variables for scenarios like CI/CD pipelines:

export AWS_ACCESS_KEY_ID=your-access-key-id
export AWS_SECRET_ACCESS_KEY=your-secret-access-key
export AWS_DEFAULT_REGION=us-west-2
export AWS_DEFAULT_OUTPUT=json

Basic Commands

Once the AWS CLI is configured, you can start managing AWS resources using various commands.

S3 Bucket Management:

● List S3 Buckets: Use aws s3 ls to list all S3 buckets in your account.


● Create a Bucket: Use aws s3 mb s3://my-new-bucket to create a new S3 bucket.
● Upload a File: Use aws s3 cp myfile.txt s3://my-new-bucket/ to upload a file to an
S3 bucket.
● Download a File: Use aws s3 cp s3://my-new-bucket/myfile.txt ./ to download a
file from an S3 bucket.
EC2 Instance Management:

● Describe Instances: Use aws ec2 describe-instances to get details about all EC2
instances.
● Start an Instance: Use aws ec2 start-instances --instance-ids i-
1234567890abcdef0 to start an EC2 instance.
● Stop an Instance: Use aws ec2 stop-instances --instance-ids i-
1234567890abcdef0 to stop an EC2 instance.
● Terminate an Instance: Use aws ec2 terminate-instances --instance-ids i-
1234567890abcdef0 to terminate an EC2 instance.

IAM User Management:

● List IAM Users: Use aws iam list-users to list all IAM users.
● Create an IAM User: Use aws iam create-user --user-name newuser to create a new
IAM user.
● Attach a Policy to a User: Use aws iam attach-user-policy --user-name newuser
--policy-arn arn:aws:iam::aws:policy/AmazonS3FullAccess to attach a policy to a
user.
● Delete an IAM User: Use aws iam delete-user --user-name newuser to delete an IAM
user.

Lambda Function Management:

● List Lambda Functions: Use aws lambda list-functions to list all Lambda functions.
● Invoke a Lambda Function: Use aws lambda invoke --function-name
myLambdaFunction output.txt to invoke a Lambda function and save the output to a file.
● Create a Lambda Function: Use aws lambda create-function with appropriate
parameters to create a new Lambda function.

Additional Examples

CloudFormation Stack Management:

● Deploy a stack using aws cloudformation deploy --template-file template.yaml


--stack-name mystack. This command helps you manage your infrastructure as code.

RDS Instance Management:

● Describe RDS instances using aws rds describe-db-instances. This command provides
details about your RDS database instances.

CloudWatch Monitoring:

● Get metrics data using aws cloudwatch get-metric-data --metric-name


CPUUtilization --namespace AWS/EC2 --start-time 2023-01-01T00:00:00Z --
end-time 2023-01-02T00:00:00Z --period 60. This command helps you monitor and
analyze metrics from your AWS resources.

Conclusion
The AWS CLI is an essential tool for anyone managing AWS resources, offering a consistent and efficient
way to interact with AWS services. By mastering basic commands and understanding how to configure
the CLI, you can automate tasks, streamline workflows, and manage your AWS environment with greater
control and flexibility. Whether you’re managing S3 buckets, EC2 instances, IAM users, or Lambda
functions, the AWS CLI provides the tools you need to perform these tasks directly from your command
line.

You might also like