简体   繁体   English

com.amazonaws.services.s3.model.AmazonS3Exception:必须指定用户密钥

[英]com.amazonaws.services.s3.model.AmazonS3Exception: User key must be specified

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)

The code looks like below: 代码如下所示:

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

access/secret keys are set up properly. 访问/密钥设置正确。

What is the user key ? 什么是用户密钥

What is User Key? 什么是用户密钥?

Ans: 答:

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 . 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 . 用户安全凭证具有Access Key IDSecret Access Key

You must store the keys in secure location. 您必须将密钥存储在安全的位置。 Your secret key will no longer be available through the AWS Management Console; 您的密钥将不再通过AWS管理控制台提供; 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. 即使查询似乎来自AWS或Amazon.com,也不要在您的组织外共享。 No one who legitimately represents Amazon will ever ask you for your secret key. 合法代表亚马逊的任何人都不会要求您提供密钥。

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

Your client.deleteObjects(....); 你的client.deleteObjects(....); methods have keys which are processing using array. 方法具有使用数组处理的键。 But ArrayList is used below for deleting objects with proper exception handling . 但是下面使用ArrayList来删除具有proper exception handling对象。

Deleting Multiple Objects (Version-Enabled Bucket) 删除多个对象(启用版本的存储桶)

  1. Create an instance of the AmazonS3Client class. 创建AmazonS3Client类的实例。
  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. 创建DeleteObjectsRequest类的实例,并提供list of objects keys以及可选择要删除的对象的版本ID。

    If you specify the version ID of the object that you want to delete, Amazon S3 deletes the specific object version . 如果指定要删除的对象的版本ID, 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 . 如果未指定要删除的对象的版本ID,则Amazon S3 adds a delete marker For more information, see Deleting One Object Per Request . 有关更多信息,请参阅删除每个请求一个对象

  3. Execute the AmazonS3Client.deleteObjects method. 执行AmazonS3Client.deleteObjects方法。

The following Java code sample demonstrates the preceding steps. 以下Java代码示例演示了上述步骤。

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. Deleting Multiple Objects Using the AWS SDK for Java 使用AWS SDK for Java删除多个对象
  2. Deleting an Object Using the AWS SDK for Java 使用AWS SDK for Java删除对象
  3. Deleting Objects 删除对象

If urls is longer than keys, you will submit an array that is longer than the size of keys with null entries which will probably lead to the exception (not tried myself). 如果url比key长,你将提交一个数组,该数组的长度大于带有空条目的键的大小,这可能会导致异常(我自己没试过)。

You'll probably want: 你可能想要:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 com.amazonaws.services.s3.model.AmazonS3Exception:访问被拒绝 - com.amazonaws.services.s3.model.AmazonS3Exception: Access Denied com.amazonaws.services.s3.model.PutObjectRequest的PutObjectRequest.putObject()方法抛出com.amazonaws.services.s3.model.AmazonS3Exception - PutObjectRequest.putObject() method of com.amazonaws.services.s3.model.PutObjectRequest throws com.amazonaws.services.s3.model.AmazonS3Exception com.amazonaws.services.s3.model.AmazonS3Exception:Forbidden(Service:Amazon S3; Status Code:403; Error Code:403 Forbidden; Request ID:XXXXXXXX) - com.amazonaws.services.s3.model.AmazonS3Exception: Forbidden (Service: Amazon S3; Status Code: 403; Error Code: 403 Forbidden; Request ID: XXXXXXXX) 导入 com.amazonaws.services.s3.AmazonS3ClientBuilder 无法解析 - The import com.amazonaws.services.s3.AmazonS3ClientBuilder cannot be resolved Maven 项目“AmazonS3ClientBuilder() 在 com.amazonaws.services.s3.AmazonS3ClientBuilder 中具有私有访问权限” - Maven project "AmazonS3ClientBuilder() has private access in com.amazonaws.services.s3.AmazonS3ClientBuilder" AWS Lambda Java 到 S3 - com.amazonaws.services.s3.AmazonS3ClientBuilder 上的 java.lang.ClassNotFoundException - AWS Lambda Java to S3 - java.lang.ClassNotFoundException on com.amazonaws.services.s3.AmazonS3ClientBuilder java.lang.NoClassDefFoundError:Spark中的com / amazonaws / services / s3 / AmazonS3Client - java.lang.NoClassDefFoundError: com/amazonaws/services/s3/AmazonS3Client in Spark java.lang.NoClassDefFoundError:com.amazonaws.services.s3.AmazonS3Client - java.lang.NoClassDefFoundError: com.amazonaws.services.s3.AmazonS3Client 错误ClassNotFoundException:com.amazonaws.services.s3.model.S3ObjectInputStream - Error ClassNotFoundException: com.amazonaws.services.s3.model.S3ObjectInputStream NoSuchMethodError:com.amazonaws.services.s3.model.S3ObjectInputStream.readAllBytes() - NoSuchMethodError: com.amazonaws.services.s3.model.S3ObjectInputStream.readAllBytes()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM