Skip to content

Latest commit

 

History

History
83 lines (51 loc) · 3.96 KB

Configuring-our-AWS-CLI-(CDK-and-SAM)-Credentials.md

File metadata and controls

83 lines (51 loc) · 3.96 KB

The following has been extracted from AWS Docs (with added info for more clarity and context): CLI Configure profiles

Prerequisite Steps

New User

  1. Create an IAM user with Programmatic Access

image

  1. Specify permissions and tags (keep in mind the permissions will control the CLI commands you can run)
  2. Download the CSV file with the User Credentials and store it locally.

image

  1. You will use the Access Key ID and Secret Access Key in the following sections.

Existing User

  1. Open the AWS Console and navigate to the IAM service.
  2. Click Users and select the existing User
  3. On the User screen, click Security credentials

image

  1. Click Create Access Key button in the Access Keys section

image

  1. Download the CSV file with the User credentials and store it locally

image

  1. You will use the Access Key ID and Secret Access Key in the following sections.

Named Profiles

A named profile is a collection of settings and credentials that you can apply to a AWS CLI command (also used for CDK and SAM, as they leverage CloudFormation). When you specify a profile to run a command, the settings and credentials are used to run that command. Multiple named profiles can be stored in the config and credentials files.

You can specify one default profile that is used when no profile is explicitly referenced. Other profiles have names that you can specify as >a parameter on the command line for individual commands. Alternatively, you can specify a profile in the AWS_PROFILE environment variable which overrides the default profile for >commands that run in that session.

Creating Named Profiles

You can configure additional profiles by using aws configure with the --profile option, or by manually adding entries to the config and credentials files. For more information on the config and credentials files, see Configuration and credential file settings.

Credentials Profile

The following example shows a credentials file with two profiles. The first [default] is used when you run a AWS CLI command with no profile. The second is used when you run a AWS CLI command with the --profile user1 parameter.

The credentials file uses a different naming format than the AWS CLI config file for named profiles. Do not use the word profile when creating an entry in the credentials file.

~/.aws/credentials (Linux & Mac) or %USERPROFILE%\.aws\credentials (Windows)

[default]
aws_access_key_id=AKIAIOSFODNN7EXAMPLE
aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

[user1]
aws_access_key_id=AKIAI44QH8DHBEXAMPLE
aws_secret_access_key=je7MtGbClwBF/2Zp9Utk/h3yCo8nvbEXAMPLEKEY

Config Profile

Each profile can specify different credentials—perhaps from different IAM users—and can also specify different AWS Regions and output formats. When naming the profile in a config file, include the prefix word "profile".

The following example specifies Region and output information for the default and user1 profiles.

~/.aws/config (Linux & Mac) or %USERPROFILE%\.aws\config (Windows)

[default]
region=us-west-2
output=json

[profile user1]
region=us-east-1
output=text