How to configure AWS CLI tool on Linux and macOS

AWS Command Line Interface (CLI) tools allows you to manage your AWS services from the command line. For it to work you'll need to have an IAM user configured for programmatic access and with appropriate permission, and to configure the AWS CLI tools configured on your machines.

These steps specifically outline how to configure AWS CLI on Linux or any other UNIX-based operating systems such as macOS:

  1. Create a user with programmatic access and appropriate permissions from IAM on your AWS account.
  2. Get Access key ID and Secret access key for the user.
  3. Run aws command in the command line passing configure as argument.
    $ aws configure
    1. Enter AWS Access Key ID of the user.
      AWS Access Key ID [None]: AKIAJ3TE4LUDC4I6SQDQ
    2. Enter AWS Secret Access Key of the user.
      AWS Secret Access Key [None]: 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
    3. Enter Default region name to use the account.
      Default region name [None]:

      You could leave the field blank. The list of available regions are available in AWS online documentation.
      AWS Regions and Endpoints

    4. Enter Default output format.
      Default output format [None]:

      You could leave the field blank. Default value is json but you can also set it to text or table.

  4. The previous action will generate files to store your configuration which you can manually view and edit later.
    1. List generated files in the ~/.aws directory.
      $ ls .aws/
      config  credentials
    2. AWS Access Key ID and AWS Secret Access Key stored in ~/.aws/credentials
      $ cat .aws/credentials
      [default]
      aws_access_key_id = AKIAJ3TE4LUDC4I6SQDQ
      aws_secret_access_key = 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
    3. Default region name and Default output format are stored in ~/.aws/config.
      $ cat .aws/config
      [default]

      You could manually add the configuration later in the following format:

      default_region_name=your_preferred_region
      default_output_format=your_preferred_format
  5. You can now run the aws command to execute upon your AWS account wherever you have the correct permission for.
    $ aws s3 ls
    2018-12-29 13:58:51 simplified-guide