com.amazonaws.services.s3.model.AmazonS3Exception:必须指定用户密钥 [英] com.amazonaws.services.s3.model.AmazonS3Exception: User key must be specified

查看:284
本文介绍了com.amazonaws.services.s3.model.AmazonS3Exception:必须指定用户密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

com.amazonaws.services.s3.model.AmazonS3Exception: User key must be specified. (Service: Amazon S3; Status Code: 400;
       at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:1160)
       at com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpClient.java:748)
       at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:467)
       at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:302)
       at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3769)
       at com.amazonaws.services.s3.AmazonS3Client.deleteObjects(AmazonS3Client.java:1841)

代码如下:

client.deleteObjects(new DeleteObjectsRequest(bucketName).withKeys(keys.toArray(new String[urls.length]))

访问/保密键设置正确.

access/secret keys are set up properly.

什么是用户密钥?

推荐答案

什么是用户密钥?

回答:

用户密钥是用户可以用来获取凭据的密钥. It verifies who you are and whether you have permission to access the resources that you are requesting.用户安全凭证具有Access Key IDSecret Access Key.

User Key is a key by which user can get credentials. It verifies who you are and whether you have permission to access the resources that you are requesting. User security credentials have Access Key ID and Secret Access Key.

您必须将密钥存储在安全的位置.您的秘密密钥不会 可通过AWS管理控制台获得更长的时间;你将会有 唯一的副本.对其保密,以保护您的帐户, 从不通过电子邮件发送.即使在组织外也不要共享 查询似乎来自AWS或Amazon.com.没有人合法地 代表Amazon会问您您的密钥.

You must store the keys in secure location. Your secret key will no longer be available through the AWS Management Console; you will have the only copy. Keep it confidential in order to protect your account, and never email it. Do not share it outside your organization, even if an inquiry appears to come from AWS or Amazon.com. No one who legitimately represents Amazon will ever ask you for your secret key.

有关更多信息: http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSGettingStartedGuide/AWSCredentials.html

您的client.deleteObjects(....);方法具有使用数组处理的键.但是,下面使用ArrayList删除具有proper exception handling的对象.

Your client.deleteObjects(....); methods have keys which are processing using array. But ArrayList is used below for deleting objects with proper exception handling.

删除多个对象(启用版本的存储桶)

Deleting Multiple Objects (Version-Enabled Bucket)

  1. 创建AmazonS3Client类的实例.
  2. 创建DeleteObjectsRequest类的实例并提供一个 list of objects keys和对象的版本ID(可选) 您要删除的.

  1. Create an instance of the AmazonS3Client class.
  2. Create an instance of the DeleteObjectsRequest class and provide a list of objects keys and optionally the version IDs of the objects that you want to delete.

如果指定要删除的对象的版本ID,请按Amazon S3 deletes the specific object version.如果未指定要删除的对象的版本ID,请Amazon S3 adds a delete marker.有关更多信息,请参阅每个请求删除一个对象.

If you specify the version ID of the object that you want to delete, Amazon S3 deletes the specific object version. If you don't specify the version ID of the object that you want to delete, Amazon S3 adds a delete marker. For more information, see Deleting One Object Per Request.

以下Java代码示例演示了上述步骤.

The following Java code sample demonstrates the preceding steps.

List<KeyVersion> keys = new ArrayList<KeyVersion>();
// Provide a list of object keys and versions.

DeleteObjectsRequest multiObjectDeleteRequest = new DeleteObjectsRequest(bucketName)
.withKeys(keys);

try {
    DeleteObjectsResult delObjRes = s3Client.deleteObjects(multiObjectDeleteRequest);
    System.out.format("Successfully deleted all the %s items.\n", delObjRes.getDeletedObjects().size());

} catch (MultiObjectDeleteException e) {
    // Process exception.
}

对于多对象删除(非版本存储桶),可以​​使用此方法 也

For Multi-Object Delete (Non-Versioned Bucket) you can use this method also

static void multiObjectNonVersionedDelete(List<KeyVersion> keys) {

    // Multi-object delete by specifying only keys (no version ID).
    DeleteObjectsRequest multiObjectDeleteRequest = new DeleteObjectsRequest(
            bucketName).withQuiet(false);

    // Create request that include only object key names.
    List<KeyVersion> justKeys = new ArrayList<KeyVersion>();
    for (KeyVersion key : keys) {
        justKeys.add(new KeyVersion(key.getKey()));
    }
    multiObjectDeleteRequest.setKeys(justKeys);
    // Execute DeleteObjects - Amazon S3 add delete marker for each object
    // deletion. The objects no disappear from your bucket (verify).
    DeleteObjectsResult delObjRes = null;
    try {
        delObjRes = s3Client.deleteObjects(multiObjectDeleteRequest);
        System.out.format("Successfully deleted all the %s items.\n", delObjRes.getDeletedObjects().size());
    } catch (MultiObjectDeleteException mode) {
        printDeleteResults(mode);
    }
}

有关示例的详细信息,您可以按照教程进行操作

For details with example, you can follow the tutorials

  1. 使用适用于Java的AWS开发工具包删除多个对象
  2. 使用适用于Java的AWS开发工具包删除对象
  3. 删除对象
  1. Deleting Multiple Objects Using the AWS SDK for Java
  2. Deleting an Object Using the AWS SDK for Java
  3. Deleting Objects

这篇关于com.amazonaws.services.s3.model.AmazonS3Exception:必须指定用户密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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