AWS S3-删除多个对象时出现UserKeyMustBeSpecified错误

时间:2019-01-08 14:30:23

标签: java amazon-s3 aws-lambda aws-sdk

我最近在使用不带版本的键从s3中删除多个对象时遇到了UserKeyMustBeSpecified错误。

该操作在Java lambda函数中执行,该函数使用以下代码:

public class S3Dao {

    private final AmazonS3 s3;
    private Logger logger;

    public S3Dao() {
        BasicAWSCredentials creds = new BasicAWSCredentials(accessKey, secretKey);
        ClientConfiguration config = new ClientConfiguration();
        config.setConnectionTimeout(220_000);
        config.setClientExecutionTimeout(220_000);
        this.s3 = AmazonS3ClientBuilder.standard()
                .withClientConfiguration(config)
                .withCredentials(new AWSStaticCredentialsProvider(creds))
                .build();
    }

    public void deleteKeys(Collection<String> s3keysToDelete) {
        logger.log("Deleting S3 " + s3keysToDelete.size() + " keys");
        if (s3keysToDelete.isEmpty()) {
            return;
        }
        DeleteObjectsRequest deleteRequest = new DeleteObjectsRequest(bucketName)
                .withKeys(s3keysToDelete.toArray(new String[] {}));
        DeleteObjectsResult deleteObjectsResult = s3.deleteObjects(deleteRequest);
        logger.log("Deleted " + deleteObjectsResult.getDeletedObjects().size() + " s3 objects");
    }
}

我仔细检查了访问键,但没问题。

有人知道这个“用户密钥”是什么,如何指定它?

谢谢!

1 个答案:

答案 0 :(得分:0)

我尝试删除的键之一是null。问题解决了:)