6 - Aws Cli
6 - 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.
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:
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:
● 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.
● 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.
● 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
● Describe RDS instances using aws rds describe-db-instances. This command provides
details about your RDS database instances.
CloudWatch Monitoring:
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.