how would you replicate what the Java code above is doing but in an S3 context
Essentially all you need to do is this:
AmazonS3Client client = ...;
String bucketName = "...";
ObjectMetadata meta = client.getObjectMetadata(bucketName, path);
The getObjectMetadata
call will fail if the path does not exist (throwing an Exception)