问题
In my development environment, I regularly switch between several AWS access keys. So in my ~/.aws/credentials
file, I have several profiles. I can then use these profiles with aws-cli by specifying the --profile <name>
flag.
I develop several apps that use the Ruby AWS SDK. They are setup to read credentials from the ~/.aws/credentials
file (the SDK does this by default, see this configuration article).
The problem is that the SDK always reads from the default
profile. I would like to be able to configure it to read from some of the other profiles. Is this possible?
I've tried setting the default profile in my environment with:
export AWS_DEFAULT_PROFILE=<profile name>
as outlined in configuring the AWS Command Line Interface but it seems that only works with the aws-cli and not with the SDK.
回答1:
For SDK:
By setting the AWS_PROFILE environment variable to the profile you want to use.
For CLI:
From: A New and Standardized Way to Manage Credentials in the AWS SDKs
"AWS_DEFAULT_PROFILE is correct for the AWS CLI. The AWS CLI respects AWS_PROFILE if it is set, but AWS_DEFAULT_PROFILE takes precedence."
来源:https://stackoverflow.com/questions/35660499/can-i-specify-a-default-aws-configuration-profile