Java AWS Amazon s3 GetObjectRequest(InvalidAccessKeyId)

时间:2018-08-01 11:07:00

标签: java amazon-web-services amazon-s3

我正在尝试在Amazon S3存储库上获取文件。我从亚马逊收到消息“ InvalidAccessKeyId”

  

您提供的AWS Access Key ID在我们的记录中不存在。   (服务:Amazon S3;状态代码:403;错误代码:InvalidAccessKeyId;   请求ID:62781C914754D8ED; S3扩展请求ID:   + fhv2t247XoEK99IZ6 / f8lcWUz7IWlGybGfb2HRNrWpCG + EbeSupSREmcseyBcJQ3VybXizwVTg =)

评论服务器未授予我listBucket权限,因此我将路径作为backet(我也尝试将存储桶和路径放入键String bucketName =“ my_bucket”键中; 字符串键=“ folder / folder1 / example.xml”; ):

String accesKey= "my_access_key";
String secretKey= "my_secret_key";
String bucketName= "my_bucket/folder/folder1/";
String key= "example.xml";

BasicAWSCredentials creds = new BasicAWSCredentials(accesKey, secretKey); 
AmazonS3 s3 = AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(creds)).withRegion(Regions.EU_WEST_1).build();
s3.getObject(new GetObjectRequest(bucketName, key)

2 个答案:

答案 0 :(得分:1)

似乎有多个问题
问题1:

bucketName : only a bucket name
keyName: will have dir structure/filename

问题2:
带有secreat / access键的问题 Refer how api looks for credentials

答案 1 :(得分:0)

存储桶名称应仅为my_bucket。密钥将是folder / folder1 / example.xml

也可以尝试

AmazonS3Client aws3 = new AmazonS3Client(accesKey, secretKey, 
RegionEndpoint.your_region_endpoint);

string content = null;
        var response = aws3.GetObjectAsync(new GetObjectRequest
        {
            BucketName = bucketName,
            Key = key,
        }).Result;
        using (var s = new StreamReader(response.ResponseStream))
        {
            content = s.ReadToEnd();
        }