Path: blob/master/code_examples/java_examples/S3Examples/DeleteObjectNonVersionedBucket.java
4084 views
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.1// SPDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-s3-developer-guide/blob/master/LICENSE-SAMPLECODE.)23import java.io.IOException;45import com.amazonaws.AmazonServiceException;6import com.amazonaws.SdkClientException;7import com.amazonaws.auth.profile.ProfileCredentialsProvider;8import com.amazonaws.services.s3.AmazonS3;9import com.amazonaws.services.s3.AmazonS3ClientBuilder;10import com.amazonaws.services.s3.model.DeleteObjectRequest;1112public class DeleteObjectNonVersionedBucket {1314public static void main(String[] args) throws IOException {15String clientRegion = "*** Client region ***";16String bucketName = "*** Bucket name ***";17String keyName = "*** Key name ****";1819try {20AmazonS3 s3Client = AmazonS3ClientBuilder.standard()21.withCredentials(new ProfileCredentialsProvider())22.withRegion(clientRegion)23.build();2425s3Client.deleteObject(new DeleteObjectRequest(bucketName, keyName));26}27catch(AmazonServiceException e) {28// The call was transmitted successfully, but Amazon S3 couldn't process29// it, so it returned an error response.30e.printStackTrace();31}32catch(SdkClientException e) {33// Amazon S3 couldn't be contacted for a response, or the client34// couldn't parse the response from Amazon S3.35e.printStackTrace();36}37}38}3940