- AWS CLI version 2 is the latest version of CLI with latest features. So here, we are installing CLI with version 2 (blog date: May 08, 2020).
- Here, I will be describing only the CLI commands executed on my linux envt.
Courtesy: https://docs.aws.amazon.com/cli/
------------------------------
- CLI v2 installation:
- curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
- unzip awscliv2.zip
- sudo ./aws/install
- This will default install the aws cli at /usr/local/bin
- If you want to change the installation dir and copy installation files at other place, you can specify it using
--install-diror-i
------------------------------
- To know the current AWS Version
- aws --version
- You may need to go to your local dir before running above command, or you can run it like the following from any location :
- /usr/local/bin/aws --version
- Output:
- aws-cli/2.0.12 Python/3.7.3 Linux/3.10.0-1127.el7.x86_64 botocore/2.0.0dev16
- Also, you can know the current location of AWS installation:
- which aws
------------------------------
- Configuring AWS CLI
aws configureAWS Access Key ID [None]:AWS Secret Access Key [None]:AKIAIJFIEHWYUWBYCAFDefault region name [None]:wTkrvWGfvRQYS/H4NQSCA/xOqTdufkSAMPLEKEYDefault output format [None]:us-east-1json- This above command will create an AWS profile 'default' for you.
- You can find the credentials and configuration details under ~/.aws/credentials and ~/.aws/config on your linux envt.
- After configuring this, you have logged in with your profile with the access and secret key.
- If you want to reset or remove your profile, just clear the details entered under the ~/.aws/credentials and ~/.aws/config files and save it.
- When you run any command like the following without specifying any --profile attribute, it will read the details/credentials from the ~/.aws/credentials file.
- aws s3 ls
- But if you want specific user login or profile to login with, you can specify at run time:
- aws s3 ls --profile alf_user
------------------------------
- Set / Get Region
aws configure get region --profile default- You can get the region name set in your 'default' profile by the above cmd. Same way, you can specify the profile name instead of 'default' whose region name you want
- Same way, you can set it:
- aws configure set region
us-east-1--profilealf_user
------------------------------
- If you are unable to locate the credentials file, you can check with:
- aws configure list
- It will give output as:
- Name Value Type Location
- ---- ----- ---- --------
- profile <not set> None None
- access_key **************** shared-credentials-file
- secret_key **************** shared-credentials-file
- region config-file ~/.aws/config
------------------------------
- Once you are logged in with a profile, and have the appropriate access (to this profile), you can fire the commands below as follows.
- But if you don't have appropriate access, then you will see AccessDenied exception:
- Assuming that your profile has appropriate rights, you can go ahead and fire the commands ahead.
- AWS SQS
- Assuming you have a created queue in AWS SQS, then you can receive message from queue by passing the url url and region name as:
- aws sqs receive-message --region us-east-1 --queue-url https://sqs.us-east-1.amazonaws.com/7**********/Queue_Name_ABC --max-number-of-messages 20 --visibility-timeout 30 --wait-time-seconds 20
- Same way for sending message to queue:
- aws sqs send-message help //and after getting help, passing params as below:
- aws sqs send-message --queue-url https://sqs.us-east-1.amazonaws.com/7*********/Queue_Name_XYZ --region us-east-1 --message-body test-message
- List queues:
- aws sqs list-queues --region us-east-1
- Any help regarding aws sqs:
- aws sqs help