A Beginner's Guide to Setting Up IAM Programmatic Access and AWS CLI

Urvish SuhagiyaUrvish Suhagiya
3 min read

Understanding IAM Programmatic Access

IAM Programmatic Access:

To interact with your AWS account from a terminal or system, you need programmatic access, which is achieved using AWS Access Keys. These keys allow you to perform AWS operations through scripts, automation tools, or command-line tools like AWS CLI.

Key Components:

  1. AWS Access Key ID: A unique identifier for your AWS account.

  2. AWS Secret Access Key: A secret key used to sign requests you make to AWS, ensuring they are secure and authenticated.

Setting Up AWS CLI

AWS CLI:

The AWS Command Line Interface (CLI) is a unified tool to manage your AWS services. It allows you to control multiple AWS services directly from the command line and automate them through scripts.

Key Features of AWS CLI v2:

  1. Improved installers and configuration options.

  2. Integration with AWS IAM Identity Center (successor to AWS SSO).

  3. Various interactive features for enhanced user experience.


Step-by-Step Guide to Setting Up IAM Programmatic Access and AWS CLI

Step 1: Create AWS Access Keys

  1. Log in to AWS Management Console:

  2. Navigate to IAM (Identity and Access Management):

    • From the Services menu, select "IAM."
  3. Create a New User:

    • Click on "Users" in the left-hand menu.

    • Click the "Add user" button.

    • Enter a user name.

    • Select "Programmatic access" under Access type.

    • Click "Next: Permissions."

  4. Attach Policies:

    • Attach the required policies (e.g., "AdministratorAccess" for full permissions).

    • Click "Next: Tags" (optional) and then "Next: Review."

  5. Create User and Get Access Keys:

    • Review the user details and click "Create user."

    • Copy the AWS Access Key ID and AWS Secret Access Key or download the .csv file containing these keys.

Step 2: Install and Configure AWS CLI

  1. Download and Install AWS CLI:

  2. Verify Installation:

    • Open a terminal or command prompt.

    • Run the command: aws --version

    • Ensure the CLI version is displayed correctly.

  3. Configure AWS CLI:

    • Run the command: aws configure

    • When prompted, enter the following:

      • AWS Access Key ID: Enter your access key ID.

      • AWS Secret Access Key: Enter your secret access key.

      • Default region name: Enter your preferred AWS region (e.g., us-east-1).

      • Default output format: Enter your preferred output format (e.g., json).

  4. Verify Configuration:

    • Run a test command to ensure AWS CLI is configured correctly. For example: aws s3 ls

    • If configured correctly, this command will list your S3 buckets.


Additional Information

IAM Best Practices:

  1. Limit Permissions:

    • Follow the principle of least privilege by granting only the necessary permissions.
  2. Use IAM Roles:

    • Use IAM roles instead of access keys for applications running on AWS services.
  3. Regularly Rotate Access Keys:

    • Rotate your access keys regularly and remove any unused keys.

Using AWS CLI:

  1. Automate Tasks:

    • Write scripts to automate repetitive tasks, such as starting and stopping instances.
  2. Manage Resources:

    • Easily manage AWS resources, including EC2, S3, RDS, and more.
  3. Interactive Features:

    • Take advantage of interactive features for configuration and troubleshooting.

By following this guide, youโ€™ve successfully set up programmatic access to your AWS account and configured AWS CLI. This setup enables you to manage your AWS services efficiently from the command line.

Happy Learning! ๐Ÿ˜Š

2
Subscribe to my newsletter

Read articles from Urvish Suhagiya directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Urvish Suhagiya
Urvish Suhagiya

Exploring the world of DevOps ๐ŸŒ.