Delete the website configuration from an Amazon S3 bucket using an Amazon SDK - Amazon Simple Storage Service
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China.

Delete the website configuration from an Amazon S3 bucket using an Amazon SDK

The following code examples show how to delete the website configuration from an S3 bucket.

C++
SDK for C++
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository.

bool AwsDoc::S3::DeleteBucketWebsite(const Aws::String &bucketName, const Aws::Client::ClientConfiguration &clientConfig) { Aws::S3::S3Client client(clientConfig); Aws::S3::Model::DeleteBucketWebsiteRequest request; request.SetBucket(bucketName); Aws::S3::Model::DeleteBucketWebsiteOutcome outcome = client.DeleteBucketWebsite(request); if (!outcome.IsSuccess()) { auto err = outcome.GetError(); std::cerr << "Error: DeleteBucketWebsite: " << err.GetExceptionName() << ": " << err.GetMessage() << std::endl; } else { std::cout << "Website configuration was removed." << std::endl; } return outcome.IsSuccess(); }
Java
SDK for Java 2.x
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository.

public static void deleteBucketWebsiteConfig(S3Client s3,String bucketName ) { DeleteBucketWebsiteRequest delReq = DeleteBucketWebsiteRequest.builder() .bucket(bucketName) .build(); try { s3.deleteBucketWebsite(delReq); } catch (S3Exception e) { System.err.println(e.awsErrorDetails().errorMessage()); System.out.println("Failed to delete website configuration!"); System.exit(1); } }
JavaScript
SDK for JavaScript V3
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository.

Create the client.

// Create service client module using ES6 syntax. import { S3Client } from "@aws-sdk/client-s3"; // Set the AWS Region. const REGION = "us-east-1"; // Create an Amazon S3 service client object. const s3Client = new S3Client({ region: REGION }); export { s3Client };

Delete the website configuration from the bucket.

// Import required AWS SDK clients and commands for Node.js. import { DeleteBucketWebsiteCommand } from "@aws-sdk/client-s3"; import { s3Client } from "./libs/s3Client.js"; // Helper function that creates an Amazon S3 service client module. // Create the parameters for calling export const bucketParams = { Bucket: "BUCKET_NAME" }; export const run = async () => { try { const data = await s3Client.send(new DeleteBucketWebsiteCommand(bucketParams)); return data; // For unit tests. console.log("Success", data); } catch (err) { console.log("Error", err); } }; run();

For a complete list of Amazon SDK developer guides and code examples, see Using this service with an Amazon SDK. This topic also includes information about getting started and details about previous SDK versions.