AWS object presence check
HighAn object existence check is performed manually. Use built-in operations instead.
Noncompliant example
public boolean checkS3ObjectNoncompliant(AmazonS3 s3Client, String bucketName, String key) {
// Noncompliant: implements an object existence check from scratch instead of using doesObjectExist.
try {
s3Client.getObjectMetadata(bucketName, key);
return true;
} catch (Exception e) {
return false;
}
}
Compliant example
public boolean checkS3ObjectCompliant(AmazonS3 s3Client, String bucketName, String key) {
// Compliant: uses doesObjectExist instead of implementing it from scratch.
try {
return s3Client.doesObjectExist(bucketName, key);
} catch (Exception e) {
return false;
}
}