【问题标题】:Must provide an explicit region in the builder or setup environment to supply a region必须在构建器或设置环境中提供显式区域以提供区域
【发布时间】:2018-10-30 12:22:30
【问题描述】:

我尝试这样设置用户:

aws configure --profile MyUser

并通过以下方式激活它:

export AWS_PROFILE=MyUser

但是,我不断收到以下异常:

2018 年 5 月 20 日下午 3:09:02 com.amazonaws.auth.profile.internal.BasicProfileConfigLoader 加载配置文件

警告:旧的配置文件格式要求配置文件名称前有“配置文件”前缀。最新的代码不需要这样的前缀,并将其视为配置文件名称的一部分。如果您看到此警告,请删除前缀。

线程“main”com.amazonaws.SdkClientException 中的异常:无法通过区域提供程序链找到区域。必须在构建器或设置环境中提供明确的区域以提供区域。

奇怪的是,如果我用默认用户配置它,那么一切正常:

aws configure

为什么上面没有特定用户名的配置不起作用?


我也知道我们可以在 SOSO 这样的代码中配置凭据。

AmazonS3 amazonS3 = AmazonS3Client.builder()
    .withRegion("us-east-1")
    .withCredentials(new AWSStaticCredentialsProvider(creds))
    .build();

这行得通,但我只是认为将凭据放入源代码并使用 git 签入是个坏主意。


另外,从错误消息来看,我似乎使用了前缀名称中带有 profile 的旧格式(如本 SO 中所述。我已经仔细检查了 aws-cli 版本并确保它是最新的还仔细检查了我的配置文件名称中没有前缀。

这里是关于版本的:

aws --version
aws-cli/1.11.129 Python/3.6.2 Darwin/17.5.0 botocore/1.5.92

这是配置文件:

cat ~/.aws/credentials             
[default]
aws_access_key_id = A***
aws_secret_access_key = I***
[MyUser]
aws_access_key_id = A***
aws_secret_access_key = D***

【问题讨论】:

    标签: amazon-web-services aws-cli


    【解决方案1】:

    找出问题所在。使用aws configure --profile MyUser 生成了两个文件。

    • ~/.aws/config
    • ~/.aws/凭据

    我注意到生成的配置文件确实有 profile 前缀

    $ cat ~/.aws/config 
    [default]
    region = us-east-1
    output = json
    [profile MyUser]
    region = us-west-1
    output = json
    

    删除后,一切正常:

    [MyUser]
    region = us-west-1
    output = json
    

    或者,我们可以明确指定凭证配置文件和用户。例如,在 Scala 中:

    private lazy val credential =
        new ProfileCredentialsProvider("/Users/yuchen/.aws/credentials", "MyUser")
    
    private lazy val lambda = AWSLambdaClientBuilder.standard()
        .withCredentials(credential)
        .withRegion(Regions.US_WEST_1)
        .build()
    

    【讨论】:

    • 这个aws命令错误地配置了配置文件,这很奇怪。
    • 显然,是 AWS Java SDK 出错了,这种行为 will be fixed in V2 of the AWS Java SDK 以便正确处理 ~/.aws/config 内部的 [profile MyUser]
    猜你喜欢
    • 1970-01-01
    • 2020-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-05
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    相关资源
    最近更新 更多