从S3下载AWS错误对象,“配置文件不能为空”。 [英] AWS error downloading object from S3, "profile file cannot be null"

查看:306
本文介绍了从S3下载AWS错误对象,“配置文件不能为空”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到,但没有答案可以解释我的问题。我首先使用了此处(GetObject类)提供的示例,并且它可以立即在我的桌面上运行。但是,我的朋友无法使其在他的机器上运行,也无法在我们的EC2实例上运行。

I've already seen this, but there was no answer to explain my problem. I first used the sample provided here (GetObject class), and it worked immediately on my desktop. However, my friend could not get it to work on his machine, nor will it work on our EC2 instance.

有人提到要指定凭据文件,这很有意义,但是我从来没有这样做,并且可以肯定,默认权限已设置为允许访问

It was mentioned that there are to be credentials files specified, which makes sense, but I never had to do that and am pretty sure the default permissions were set to enable accessing this bucket.

这是堆栈跟踪:

Exception in thread "main" java.lang.IllegalArgumentException: profile file cannot be null
    at com.amazonaws.util.ValidationUtils.assertNotNull(ValidationUtils.java:37)
    at com.amazonaws.auth.profile.ProfilesConfigFile.<init>(ProfilesConfigFile.java:142)
    at com.amazonaws.auth.profile.ProfilesConfigFile.<init>(ProfilesConfigFile.java:133)
    at com.amazonaws.auth.profile.ProfilesConfigFile.<init>(ProfilesConfigFile.java:100)
    at com.amazonaws.auth.profile.ProfileCredentialsProvider.getCredentials(ProfileCredentialsProvider.java:135)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.getCredentialsFromContext(AmazonHttpClient.java:1029)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1049)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:949)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:662)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:636)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:619)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$300(AmazonHttpClient.java:587)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:574)
    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:446)
    at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:4035)
    at com.amazonaws.services.s3.AmazonS3Client.getBucketRegionViaHeadRequest(AmazonS3Client.java:4474)
    at com.amazonaws.services.s3.AmazonS3Client.fetchRegionFromCache(AmazonS3Client.java:4448)
    at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:4020)
    at com.amazonaws.services.s3.AmazonS3Client.getObject(AmazonS3Client.java:1307)
    at GetObject.main(GetObject.java:26)

我可以保证GetNameRequest中的bucketName和键参数都不为空。这里有什么差异?为什么只能在我的PC上成功?这是否与我必须补充aws-sdk jar应该已经存在的众多jar(杰克逊数据绑定,杰克逊核心,杰克逊注释,httpclient,httpcore,commons-logging和joda-时间)?似乎是类似的,但还有其他莫名其妙的错误(给出非空参数,aws-sdk中的某些内容表示它为空)。

I can guarantee that neither the bucketName nor the key params in the GetObjectRequest are null. What's the discrepancy here? Why might it succeed only on my PC? Is this at all related to the fact that I had to supplement numerous jars that the aws-sdk jar was supposed to have already (jackson-databind, jackson-core, jackson-annotations, httpclient, httpcore, commons-logging, and joda-time)? It seems similar, what with the otherwise inexplicable errors (giving non-null params, something in aws-sdk says it's null).

推荐答案

看来您在评论中解决了这个问题,但对此我感到非常沮丧,并希望为以后的读者留下一个更清晰的答案。要非常清楚,这里的问题与S3中的文件无关。此错误消息与硬盘驱动器上的文件或您尝试从S3推/拉文件无关。问题是您正在使用类似以下内容初始化S3:

It looks like you solved this in the comments, but I got burned on this and want to leave a clearer answer for future readers. To be super clear, the problem here has nothing to do with files in S3. This error message has nothing to do with the file on your hard drive nor the file that you're trying to push/pull from S3. The problem is that you're initializing S3 with something like:

AmazonS3 s3Client = new AmazonS3Client(new ProfileCredentialsProvider());

这样做时,它会在〜/ .aws / credentials中查找配置文件列表。这在您的计算机上可能效果很好,但是在通过IAM角色(例如Lambda,Docker,EC2实例等)获得AWS访问权限的任何地方都无法使用。解决方法是初始化AmazonS3Client,例如:

When you do that, it looks in ~/.aws/credentials for a list of profiles. This might work great on your computer but won't work anywhere that you're getting AWS access through an IAM role (ex. Lambda, Docker, EC2 instance, etc). The fix, is to initialize the AmazonS3Client like:

AmazonS3 s3Client = new AmazonS3Client();

如果您使用的代码需要某种凭据提供程序,则还可以执行以下操作:

If you're using code that requires some kind of credentials provider, you can also do:

AmazonS3 s3Client = new AmazonS3Client(DefaultAWSCredentialsProviderChain.getInstance());

希望对下一个人有所帮助。就我而言,我使用的是DynamoDB和SQS,但我有相同的错误。我最初忽略了这个问题,因为我认为您的问题与S3有关并且非常困惑。手腕打了巴掌。

Hopefully that helps the next person. In my case, I was using DynamoDB and SQS, but I had the same error. I originally ignored this question because I thought your problem was S3 related and was super confused. Wrist slapped.

这篇关于从S3下载AWS错误对象,“配置文件不能为空”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆