The AWS Command Line Interface (CLI) is a unified tool provided by Amazon Web Services (AWS) that allows us to manage and interact with our AWS services and resources from the command line. It provides a consistent interface for managing AWS services using simple commands, which can be incorporated into scripts for automation.
For us, Mulesoft Architects and Developers, it'll also be a useful tool to
install EKS clusters for our Runtime Fabric instances, create VPCs, Transit
Gateways...
This is a post to have it as a reference, to quickly understand (or remember)
how to install it and use it.
The AWS CLI will use a (programmatic) AWS user. Let's create first that user
and then we'll use it to connect our AWS CLI.
Create an IAM User
- Open the AWS Management Console
- Go to the IAM service and, under the Access Management section click on users and then Create User
- In Step 1 - Provide a name for your admin user (in our example it will be k8s-admin). No need to provide access to the management console. Click Next
- In Step 2 - Set Permissions choose the Attach policies directly option and select the AdministratorAccess policy. Click Next
- In Review and Create click on Create user
- Once the user is created, click on the user name on the list of users.
- Next, click on the Security credentials tab and scroll down to Access keys. Click on Create access key and then choose the Command Line Interface (CLI) option. You’ll have to tick the confirmation checkbox and then click Next.
- After that click on Create access key
- Lastly, take note of the Access key and Secret access key. We’ll use them in the next steps.
Install AWS CLI
- Open a terminal and check if there's an existing AWS CLI and the version installed:
aws --version
- If you don't have it installed or have a version older than v2, follow these steps to install it.
For Linux:
- Run the command
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
- Unzip the file:
unzip awscliv2.zip
For macOS
curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
sudo installer -pkg AWSCLIV2.pkg -target /
- See where the current AWS CLI is installed:
which aws
- It should be /usr/local/bin/aws
-
Append the install directory to the user's
$PATH
variable.
export PATH=$PATH:/usr/local/bin/aws
- Update it (if there was a previous version installed)
sudo ./aws/install --bin-dir /usr/bin --install-dir /usr/bin/aws-cli
--update
- Check the version of AWS CLI:
aws --version
- It should now be updated.
Connect your AWS CLI to your AWS account
- Once we've got the aws cli installed, we need to specify the credentials (access key) to identify our AWS account and the AWS region in which we want to work with the CLI. For that, run the command:
aws configure
you will be prompted to provide the following information:
- Access Key ID - key of the admin user we created earlier
- Secret Access Key - secret of the admin user we created earlier
- AWS Region - region where we'll be managing AWS resources
- Output format - json
With that we're ready to manage our AWS resources from our terminal.