我可以指定默认的AWS配置配置文件吗? [英] Can I specify a default AWS configuration profile?
问题描述
在我的开发环境中,我定期在多个AWS访问密钥之间切换.因此,在我的~/.aws/credentials
文件中,我有几个配置文件.然后,通过指定--profile <name>
标志,可以将这些配置文件与aws-cli一起使用.
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.
我开发了几个使用Ruby AWS SDK的应用程序.它们被设置为从~/.aws/credentials
文件读取凭据(默认情况下,SDK会执行此操作,请参阅此
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).
问题在于,SDK始终从default
配置文件读取.我希望能够将其配置为从其他一些配置文件中读取.这可能吗?
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>
如配置AWS Command Line Interface ,但似乎仅适用于aws-cli,不适用于SDK.
as outlined in configuring the AWS Command Line Interface but it seems that only works with the aws-cli and not with the SDK.
推荐答案
对于SDK:
通过将AWS_PROFILE环境变量设置为您使用的配置文件 要使用.
By setting the AWS_PROFILE environment variable to the profile you want to use.
对于CLI: