Updated March 2, 2023
Introduction to AWS Commands
AWS commands are used in AWS CLI that is the AWS Command-line interface, which is a tool to manage the AWS services. It helps in configuring the services and able to control the multiple services to automate them through scripting. AWS CLI can be installed and configure easily, and some of the commands that are mainly used are listed below.
Basic AWS Commands
Given below are the basic AWS commands:
1. To Install and Configure AWS CLI, use the below commands –
Syntax/ example:
sudo apt-get install -y python-dev python-pip
sudo pip install awscli
The syntax for configure:
aws configure
2. To check the output of the file, the command is –
Syntax/ example:
cat <file>
3. To print the second column per line, use the below command –
Syntax/ example:
cut –f 2
4. For data sorting, the command used is –
Syntax/ example:
Sort
5. To print the last five-line, the command is –
Syntax/ example:
tail –n 5
6. To print the first five lines, the command is –
Syntax/ example:
head –n 5
7. To print the 5th line in a file, the command is –
Syntax/ example:
sed –n ‘5{p;q}’
8. To list all the trails, the command is –
Syntax/ example:
aws cloudtrail describe-trails
9. To list the names of all trails, the command is –
Syntax/ example:
aws cloud trail describe-trails –output text | cut –f 8
To delete the trail, the command is –
Syntax/ example:
aws cloud trail delete—trail
Intermediate AWS Commands
Given below are the intermediate AWS commands:
1. To add the tags to the trail, the command is –
Syntax/ example:
awscliaws cloudtrail add-tags \
--resource-id awslog \
--tags-list "Key=log-type,Value=all"
2. To list all the tags of the trail, the command is –
Syntax/ example:
aws cloudtrail list-tags\ --resource-id-list
3. To remove the tag from a trail –
Syntax/ example:
aws cloudtrail remove-tags \
--resource-id awslog \
--tags-list "Key=log-type,Value=all"
4. To list all the user’s info and creating the new user, the commands are –
Syntax/ example:
aws iam list-users
New user: aws iam create-user \
--user-name aws-admin1
5. To create multiple users from the file, the command is –
Syntax/ example:
allUsers=$(cat ./user-names.txt)
for userName in $allUsers; do
aws iam create-user \
--user-name $userName
Done
6. To delete multiple users from the file, the command is –
Syntax/ example:
allUsers=$(cat ./user-names.txt)
for userName in $allUsers; do
aws iam delete-user \
--user-name $userName
Done
7. To get the specific user information, the command is –
Syntax/ example:
aws iam get-user \
--user-name aws-admin1
8. To list the password policy, the command is –
Syntax/ example:
aws iam get-account-password-policy
9. To set the policy for a password, the command is –
Syntax/ example:
aws iam update-account-password-policy \
--minimum-password-length 12 \
--require-symbols \
--require-numbers \
--require-uppercase-characters \
--require-lowercase-characters \
--allow-users-to-change-password
10. To delete the password policy, the command is –
Syntax/ example:
aws iam delete-account-password-policy
Advanced AWS Commands
Given below are the advanced AWS commands:
1. To get the list of the last access time of the access key, the command is –
Syntax/ example:
aws iam get-access-key-last-used \
--access-key-id ABCDEFGH123456EXAMPLE
2. To deactivate the access key, the command is –
Syntax/ example:
aws iam update-access-key \
--access-key-id ABCDEFGH123456EXAMPLE\
--status Inactive \
--user-name aws-admin1
3. To delete the access key, the command is –
Syntax/ example:
aws iam delete-access-key \
--access-key-id ABCDEFGH123456EXAMPLE\
--user-name aws-admin1
4. To create a security group, the command is –
Syntax/ example:
aws ec2 create-security-group \
--vpc-id vpc-1a2b3c4d \
--group-name web-access \
--description "web access"
5. To open the port 80 for everyone to access, the command is –
Syntax/example:
aws ec2 authorize-security-group-ingress \
--group-id sg-0000000 \
--protocol tcp \
--port 80 \
--cidr 0.0.0.0/24
6. To remove the firewall from the group, the command is –
Syntax/ example:
aws ec2 revoke-security-group-ingress \
--group-id sg-0000000 \
--protocol tcp \
--port 80 \
--cidr 0.0.0.0/24
7. To delete the security group, the command is –
Syntax/ example:
aws ec2 delete-security-group \
--group-id sg-00000000
8. To create the instance, the command is –
Syntax/ example:
aws ec2 run-instances \
--image-id ami-f0e7d19a \
--instance-type t2.micro \
--security-group-ids sg-00000000 \
--dry-run
9. To create the log stream, the command is –
Syntax/ example:
aws logs create-log-stream \
--log-group-name "DefaultGroup" \
--log-stream-name "syslog"
10. To delete the log stream, the command is –
Syntax/ example:
aws logs delete-log-stream \
--log-group-name "DefaultGroup" \
--log-stream-name "Default Stream"
Tips and Tricks to Use AWS Commands
- Command completion.
- Filter out the results of the requests on the server-side.
- Filter out the output on the client-side.
- Search through collections.
- Extract the data that you really required.
Conclusion
AWS commands are used to provide efficient, secure, and reliable connectivity to AWS services, and it is being used with the help of AWS CLI. AWS cloud is most popular in the market and rated above the other cloud platforms like AWS, Azure, and Google cloud. It is being widely used across the globe and has many opportunities to offer for entry-level, mid-level, and senior-level positions. AWS is the next career path that offers a good salary and positions to engineers and cloud professionals. It also helps the customer as they don’t need to move the application from one server to other and need not take the physical infrastructure that reduces the lot of cost from the customer. Commands are above listed from the different sections which are commonly used in a production environment.
Recommended Articles
This has been a guide to AWS Commands. Here we have discussed basic, intermediate, and advanced AWS commands. You may also look at the following article to learn more –