Okay, we saw how in Part 3 > Getting Started > 3 how you start a CLI session by opening the terminal app and then entering the aws configure and adding in all the parameters.
Let me tell you that gets old very quickly and show you why Profiles will speed up the process.
AWS CLI profiles let you save sets of credentials and settings for individual profiles. So when you’re uploading files, you can specify which profile to use directly in the command, avoiding all that messing about and making everything much faster and easier. It also helps keep things secure as you can limit the credentials to the specific task at hand.
What is an AWS CLI Profile?
An AWS CLI profile allows you to store and manage multiple sets of AWS credentials and configuration settings. Each profile can have its own:
AWS Access Key ID
AWS Secret Access Key
Default region
Output format
Profiles are stored in the AWS CLI configuration files (~/.aws/config and ~/.aws/credentials).
Advantages of Using AWS CLI Profiles
Manage Multiple Accounts: You can easily switch between different AWS accounts or roles without having to reconfigure your credentials each time.
Isolation of Environments: Profiles help isolate different environments (e.g., development, staging, production) by using separate credentials and settings for each.
Simplified Credential Management: Profiles make it easier to manage and organize your AWS credentials, reducing the risk of using the wrong credentials for a task.
Convenience: You can specify a profile in your AWS CLI commands, making it convenient to run commands against different AWS accounts or regions without changing the default configuration.
Security: By using profiles, you can limit the scope of credentials to specific tasks or environments, enhancing security.
Start by Creating an IAM User:
1. Log in to the AWS Management Console.
2. Navigate to the IAM (Identity and Access Management) dashboard (figure #1)
Figure #1: IAM Dashboard
4. In the IAM sidebar click on Users and then “Create user” (figure #2)
Figure #2: Create user
6. In the Specify User Details enter the following;
A username for the new IAM user
Check “Provide user access to the AWS Management Console”
Check “I want to create an IAM user”
Check “Autogenerated password”
Uncheck “Users must create a new password at next sign-in - Recommended”
7. Click on “Next” (figure #3)
Figure #3: Specific user details
8. Check “Attach policies directly”
9. Search for Administrator
10. Check AdministratorAcces (full access to AWS)
11. Click on “Next” (figure #4)
Figure #4: Set Permissions
12. Review the settings and then click on “Create User” (figure #5)
Figure #5: Review & Create User
13. Note: Important- Copy the password & click on “Download .cxv file”
14. Click on “Return to users” (figure #6)
Figure #6: Retrieve password
14. The new user is shown in the User name list (figure #7)
Figure #7: New user has been created
Generate Access Keys:
1. Click on the new User name to see the information of the user
2. Click on “Create access key” (figure #8)
Figure #8: Create access key
3. Check “Command Line Interface (CLI)”
4. Check “Confirmation”
5. Click “Next” (figure #9)
Figure #9: Command Line Interface keys
6. Skip “Set description tag” and click “Create access key” (figure #10)
Note: This will generate a new access key ID and secret access key. Make sure to save these keys securely, as the secret access key will only be displayed once. If you lose the secret access key, you will need to create a new access key pair
Figure #10: Create access key
7. Copy and Save the Access and Secret Access Key or download the .csv file
18. Click “Done” (figure #11)
Figure #11: Retrieve access keys
Configure the AWS CLI:
Open your terminal or command prompt.
Use the aws configure
command with the --profile
option to create a new profile.
aws configure --profile your-profile-name
Replace your-profile-name
with the name you want to give your profile. (in this example our profile name will be “your-profile-name”
Run the aws configure command and enter the access key ID, secret access key, default region, and output format (json) when prompted. This will store the credentials in the ~/.aws/credentials file.
Use the Access Keys:
You can now use the AWS CLI via the CLI command, “export AWS_PROFILE=your-profile-name” with the configured credentials to interact with AWS services.