emr如何在用户定义的函数中访问aws凭据

时间:2014-08-14 10:37:46

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

如果我运行我的用户定义函数试图从aws中删除文件夹

private AmazonS3Client s3client = new AmazonS3Client();  

    @Override
    public void deleteObjectsInFolder(String bucketName, String folderPath) {
        for (S3ObjectSummary file : s3client.listObjects(bucketName, folderPath).getObjectSummaries()){           
            s3client.deleteObject(bucketName, file.getKey());
        }
    }
使用

./elastic-mapreduce --create  --bootstrap-action ...

它工作正常 但是当我想使用java sdk时,我会尝试删除文件

2014-08-14 10:03:43,548 [main] ERROR org.apache.pig.tools.grunt.Grunt - 
ERROR 2999: Unexpected internal error.
Status Code: 403, AWS Service: Amazon S3, AWS Request ID: 95440BF2091119A5,
AWS Error Code: AccessDenied, AWS Error Message: Access Denied

我需要添加到我的java代码中?

1 个答案:

答案 0 :(得分:0)

请使用以下代码

private static AmazonS3 s3=null

...

File s3credsFile = new File("AwsCredentials.properties");       
pc = new PropertiesCredentials(s3credsFile);
s3client = new AmazonS3Client(pc);
.....

AwsCredentials.properties这应该有你的访问密钥和秘密密钥。

然后只有s3client才能删除文件。