AWS AmazonS3 documentation change
Summary
Restructured Java SDK examples for deleting objects, consolidating versioned and non-versioned bucket scenarios into a single section and removing detailed code samples in favor of linking to API reference documentation.
Security assessment
The changes focus on documentation clarity and code example consolidation. While versioning impacts data recovery and deletion safety, there is no evidence this change addresses a specific security vulnerability or introduces new security guidance. The modifications are organizational and do not alter security implications of object deletion workflows.
Diff
diff --git a/AmazonS3/latest/userguide/delete-objects.md b/AmazonS3/latest/userguide/delete-objects.md index ee5deac28..15768d186 100644 --- a//AmazonS3/latest/userguide/delete-objects.md +++ b//AmazonS3/latest/userguide/delete-objects.md @@ -104 +104 @@ Java -###### Example 1: Deleting an object (non-versioned bucket) +To delete objects using the AWS SDK for Java, you can delete objects from both versioned and non-versioned buckets: @@ -106 +106 @@ Java -The following example assumes that the bucket is not versioning-enabled and the object doesn't have any version IDs. In the delete request, you specify only the object key and not a version ID. + * _Non-versioned bucket:_ In the delete request, you specify only the object key and not a version ID. @@ -108,50 +108 @@ The following example assumes that the bucket is not versioning-enabled and the -For instructions on creating and testing a working sample, see [Getting Started](https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/getting-started.html) in the AWS SDK for Java Developer Guide. - - - import com.amazonaws.AmazonServiceException; - import com.amazonaws.SdkClientException; - import com.amazonaws.auth.profile.ProfileCredentialsProvider; - import com.amazonaws.regions.Regions; - import com.amazonaws.services.s3.AmazonS3; - import com.amazonaws.services.s3.AmazonS3ClientBuilder; - import com.amazonaws.services.s3.model.DeleteObjectRequest; - - import java.io.IOException; - - public class DeleteObjectNonVersionedBucket { - - public static void main(String[] args) throws IOException { - Regions clientRegion = Regions.DEFAULT_REGION; - String bucketName = "*** Bucket name ***"; - String keyName = "*** Key name ****"; - - try { - AmazonS3 s3Client = AmazonS3ClientBuilder.standard() - .withCredentials(new ProfileCredentialsProvider()) - .withRegion(clientRegion) - .build(); - - s3Client.deleteObject(new DeleteObjectRequest(bucketName, keyName)); - } catch (AmazonServiceException e) { - // The call was transmitted successfully, but Amazon S3 couldn't process - // it, so it returned an error response. - e.printStackTrace(); - } catch (SdkClientException e) { - // Amazon S3 couldn't be contacted for a response, or the client - // couldn't parse the response from Amazon S3. - e.printStackTrace(); - } - } - } - - - -###### Example 2: Deleting an object (versioned bucket) - -The following example deletes an object from a versioned bucket. The example deletes a specific object version by specifying the object key name and version ID. - -The example does the following: - - 1. Adds a sample object to the bucket. Amazon S3 returns the version ID of the newly added object. The example uses this version ID in the delete request. - - 2. Deletes the object version by specifying both the object key name and a version ID. If there are no other versions of that object, Amazon S3 deletes the object entirely. Otherwise, Amazon S3 only deletes the specified version. + * _Versioned bucket:_ You can delete a specific object version by specifying both the object key name and version ID. If there are no other versions of that object, Amazon S3 deletes the object entirely. Otherwise, Amazon S3 only deletes the specified version. @@ -166,54 +117 @@ You can get the version IDs of an object by sending a `ListVersions` request. - - import com.amazonaws.AmazonServiceException; - import com.amazonaws.SdkClientException; - import com.amazonaws.auth.profile.ProfileCredentialsProvider; - import com.amazonaws.regions.Regions; - import com.amazonaws.services.s3.AmazonS3; - import com.amazonaws.services.s3.AmazonS3ClientBuilder; - import com.amazonaws.services.s3.model.BucketVersioningConfiguration; - import com.amazonaws.services.s3.model.DeleteVersionRequest; - import com.amazonaws.services.s3.model.PutObjectResult; - - import java.io.IOException; - - public class DeleteObjectVersionEnabledBucket { - - public static void main(String[] args) throws IOException { - Regions clientRegion = Regions.DEFAULT_REGION; - String bucketName = "*** Bucket name ***"; - String keyName = "*** Key name ****"; - - try { - AmazonS3 s3Client = AmazonS3ClientBuilder.standard() - .withCredentials(new ProfileCredentialsProvider()) - .withRegion(clientRegion) - .build(); - - // Check to ensure that the bucket is versioning-enabled. - String bucketVersionStatus = s3Client.getBucketVersioningConfiguration(bucketName).getStatus(); - if (!bucketVersionStatus.equals(BucketVersioningConfiguration.ENABLED)) { - System.out.printf("Bucket %s is not versioning-enabled.", bucketName); - } else { - // Add an object. - PutObjectResult putResult = s3Client.putObject(bucketName, keyName, - "Sample content for deletion example."); - System.out.printf("Object %s added to bucket %s\n", keyName, bucketName); - - // Delete the version of the object that we just created. - System.out.println("Deleting versioned object " + keyName); - s3Client.deleteVersion(new DeleteVersionRequest(bucketName, keyName, putResult.getVersionId())); - System.out.printf("Object %s, version %s deleted\n", keyName, putResult.getVersionId()); - } - } catch (AmazonServiceException e) { - // The call was transmitted successfully, but Amazon S3 couldn't process - // it, so it returned an error response. - e.printStackTrace(); - } catch (SdkClientException e) { - // Amazon S3 couldn't be contacted for a response, or the client - // couldn't parse the response from Amazon S3. - e.printStackTrace(); - } - } - } - - +For examples of how to delete a single object with the AWS SDK for Java, see [Delete an object](https://docs.aws.amazon.com/AmazonS3/latest/API/s3_example_s3_DeleteObject_section.html) in the _Amazon S3 API Reference_.