DEV Community

John  Ajera
John Ajera

Posted on

How to Configure AWS CLI on Linux

How to Configure AWS CLI on Linux

The AWS Command Line Interface (CLI) is a powerful tool that lets you interact with AWS services using commands in your terminal. This guide walks you through the process of installing and configuring the AWS CLI on a Linux system.


Why Use AWS CLI?

AWS CLI offers:

  • A quick and efficient way to interact with AWS services.
  • Automation capabilities for AWS resource management.
  • Flexibility to script complex operations.

Step 1: Install AWS CLI

To install AWS CLI on your Linux system, follow these steps:

  1. Download the installation script:
   curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
Enter fullscreen mode Exit fullscreen mode
  1. Ensure unzip is installed:

    • For Ubuntu/Debian:
     sudo apt update && sudo apt install unzip -y
    
  • For Fedora/RHEL:

     sudo dnf install unzip -y
    
  1. Extract the ZIP file:
   unzip awscliv2.zip
Enter fullscreen mode Exit fullscreen mode
  1. Run the installer:
   sudo ./aws/install
Enter fullscreen mode Exit fullscreen mode
  1. Verify the installation:
   aws --version
Enter fullscreen mode Exit fullscreen mode

The output should display the installed version of AWS CLI.

  1. Clean up temporary files:
   rm awscliv2.zip
   rm -r aws/
Enter fullscreen mode Exit fullscreen mode

Step 2: Configure AWS CLI

After installation, configure AWS CLI with your credentials and default settings.

  1. Run the configure command:
   aws configure
Enter fullscreen mode Exit fullscreen mode
  1. Provide the required information:

    • AWS Access Key ID (e.g., AKIAIOSFODNN7EXAMPLE)
    • AWS Secret Access Key (e.g., wJalrXUtnFEMI/K7MDENG/bPxRfiCYzEXAMPLEKEY)
    • Default region (e.g., ap-southeast-2)
    • Output format (e.g., json)
  2. Test the configuration:

   aws s3 ls
Enter fullscreen mode Exit fullscreen mode

This command lists all your S3 buckets, confirming that AWS CLI is configured correctly.


Step 3: Advanced Configuration

Setting Multiple Profiles

You can configure multiple AWS profiles for different accounts or environments.

  1. Create a new profile:
   aws configure --profile <profile-name>
Enter fullscreen mode Exit fullscreen mode
  1. Use a profile:
   aws s3 ls --profile <profile-name>
Enter fullscreen mode Exit fullscreen mode

Using Environment Variables

Environment variables can override default configuration settings.

  1. Set environment variables:
   export AWS_ACCESS_KEY_ID=<your-access-key-id>
   export AWS_SECRET_ACCESS_KEY=<your-secret-access-key>
   export AWS_DEFAULT_REGION=ap-southeast-2
Enter fullscreen mode Exit fullscreen mode
  1. Test the configuration:
   aws ec2 describe-instances
Enter fullscreen mode Exit fullscreen mode

Step 4: Automate AWS CLI Commands

Create shell scripts to automate AWS operations. For example:

#!/bin/bash
# Script to list S3 buckets
aws s3 ls
Enter fullscreen mode Exit fullscreen mode

Make the script executable:

chmod +x list_buckets.sh
Enter fullscreen mode Exit fullscreen mode

Run the script:

./list_buckets.sh
Enter fullscreen mode Exit fullscreen mode

Conclusion

The AWS CLI is an essential tool for any AWS user. By following this guide, you can quickly set up and start using AWS CLI to manage your cloud resources effectively. Happy coding! 🚀

Image of Docusign

Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

đź‘‹ Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay