↓ Skip to main content

Getting Started with the AWS CLI

·341 words·2 mins
Author
Sebin Thomas / 0xSebin
Offensive security, documented.
Table of Contents

AWS CLI Installation Guide
#

This guide walks you through installing and configuring the AWS Command Line Interface (CLI) on your system.

Prerequisites
#

Make sure you have:

  • Python (3.8 or later)
  • pip (the Python package installer)

Step 1: Installing the AWS CLI
#

To install the AWS CLI using pip, run:

python -m pip install awscli

For a system-wide installation, use:

sudo python -m pip install awscli

To install for your user only, use:

python -m pip install --user awscli

Alternative Installations: For macOS: Download and run the installer directly from AWS:

curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
sudo installer -pkg AWSCLIV2.pkg -target /

For Windows: Download the MSI installer from the AWS CLI website and follow the installation prompts.

For Linux:

sudo apt install awscli

Step 2: Verifying the Installation
#

To confirm that the AWS CLI is installed, run:

aws --version

This should display the version number of the AWS CLI installed on your system.

Step 3: Configuring the AWS CLI
#

Run the following command to set up your AWS credentials and default settings:

aws configure
AWS Access Key ID [****************766Q]: MYACCESSKEY
AWS Secret Access Key [****************DT9d]: MYSECRETKEY
Default region name [us-west-2]:
Default output format [None]:

Alternate Configuration Options You can also configure AWS credentials using environment variables or by editing the configuration files in ~/.aws/.

Environment Variables: Set credentials in the shell for temporary configuration:

export AWS_ACCESS_KEY_ID=<access_key>
export AWS_SECRET_ACCESS_KEY=<secret_key>

Shared Credentials File: You can store your AWS credentials in a shared credentials file. Create or edit the file located at ~/.aws/credentials, and format it as follows:

[default]
aws_access_key_id=MYACCESSKEY
aws_secret_access_key=MYSECRETKEY

To view the details of the Current IAM Identity
#

This command retrieves the AWS account ID, IAM user or role ID, and ARN for the currently authenticated identity.

aws sts get-caller-identity

If you have configured using –profile option to configure then

aws sts get-caller-identity --profile AWS

Our output will be something like this:

aws sts get-caller-identity --profile AWS
{
    "UserId": "AIDABCDEFGHIJKLMNO1234",
    "Account": "123456789012",
    "Arn": "arn:aws:iam::123456789012:user/myprofile-user"
}

Stay tuned for more write-ups on cloud security challenges from PwnedLabs!
#