@lumarseg

AWS CLI – 101

AWS CLI (AWS Command Line Interface) is an open-source tool that allows programmatically interacting with AWS services from the command line or in scripts. Here are some key points about AWS CLI:

  • It can be installed on Linux, macOS, and Windows to manage AWS resources from the terminal.
  • It supports most AWS services such as EC2, S3, DynamoDB, Lambda, etc.
  • It uses a command-line syntax similar to Unix to perform actions like creating, listing, modifying, and deleting resources.
  • It enables task automation through scripts rather than using the console.
  • It supports authentication via access key and secret key of an AWS account.
  • It can be configured to work with different AWS accounts/profiles.
  • It is constantly evolving with new features as AWS releases services.
  • It is open source, and its code is available on GitHub.
  • It has SDKs in different languages for programmatic interaction.

Some common use cases include deploying infrastructure, implementing applications, automating administrative tasks, etc. It is a very useful tool for AWS administration from the command line or in GUI-less environments.

AWS CLI Install

The AWS CLI has two main versions:

  • AWS CLI version 1: It’s the original version released in 2012. It uses the service name as a namespace for commands (e.g., aws ec2 describe-instances). It’s in maintenance mode but still supported.
  • AWS CLI version 2: It was released in 2020 with significant changes in syntax and command structure. It uses a more coherent and readable command model (e.g., aws ec2 describe-instances). It’s the currently recommended version.

Some key differences between the two versions:

  • Syntax: Version 2 uses a more standardized and readable syntax based on verbs/resources.
  • Parameters: Version 2 introduces positional parameters for clarity.
  • Services: Version 2 adds support for more recently launched services.
  • SDK: Version 2 is more aligned with the latest versions of AWS SDKs.
  • Documentation: Version 2 documentation is more comprehensive and user-friendly.
  • Compatibility: Version 1 will no longer be supported in the future, so migrating to version 2 is recommended.

Although both versions work, version 2 is the recommended current version of AWS CLI due to its improved syntax, greater compatibility, and long-term support.

For version 2, it is available in the following environments:

  • Windows
  • Mac OS
  • Linux

For Linux installation, you can follow the instructions available in the AWS documentation: https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html

 

AWS CLI Setup

For AWS CLI Setup, you can follow the instructions available in the AWS documentation:

https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html

The config and credentials files are organized into sections. Sections include profiles, sso-sessions, and services.

A section is a named collection of settings, and continues until another section definition line is encountered. Multiple profiles and sections can be stored in the config and credentials files.

There are several ways to view and set your configuration settings using commands. The common way is:

$ aws configure

Profiles

If no profile is explicitly defined, the default profile is used.

To use a named profile, add the –profile profile-name option to your command. The following example lists all of your Amazon EC2 instances using the credentials and settings defined in the user1 profile.

$ aws ec2 describe-instances –profile user1

To use a named profile for multiple commands, you can avoid specifying the profile in every command by setting the AWS_PROFILE environment variable as the default profile. You can override this setting by using the –profile parameter.

$ export AWS_PROFILE=user1

Useful commands

  • aws –version (ask AWS CLI Version)
  • aws sts get-caller-identity (It allows verifying the identity of the user accessing AWS resources.)