AWS CLI credentials
Categories:
less than a minute
The Shared Credentials method involves using the AWS CLI’s credentials file, typically located at ~/.aws/credentials
(or C:\Users\USERNAME\.aws\credentials
on Windows). This method is useful when you’re already using AWS CLI and it helps you avoid hardcoding sensitive data in your scripts.
Example:
First, set up your credentials file using the AWS CLI. Open the command prompt and run the following command:
aws configure
Enter your AWS Access Key ID and Secret Access Key when prompted. The AWS CLI will save these credentials in a file.
Next, define the AWS provider in your Terraform script. Terraform will automatically source your credentials from the AWS CLI configuration files:
provider "aws" {
region = "us-west-2"
}
If you’ve set up multiple profiles for AWS CLI, you can specify which profile to use in your Terraform scripts like this:
provider "aws" {
region = "us-west-2"
profile = "customprofile"
}
In this example, replace "customprofile"
with the name of the profile you want to use from your AWS CLI configuration.
Feedback
Was this page helpful?
Glad to hear it!
Sorry to hear that.