我最近在使用不带版本的键从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");
}
}
我仔细检查了访问键,但没问题。
有人知道这个“用户密钥”是什么,如何指定它?
谢谢!
答案 0 :(得分:0)
我尝试删除的键之一是null
。问题解决了:)