There are more AWS SDK examples available in the AWS Doc SDK Examples
Use GetBucketWebsite
with an AWS SDK or command line tool
The following code examples show how to use GetBucketWebsite
.
- .NET
-
- AWS SDK for .NET
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. // Get the website configuration. GetBucketWebsiteRequest getRequest = new GetBucketWebsiteRequest() { BucketName = bucketName, }; GetBucketWebsiteResponse getResponse = await client.GetBucketWebsiteAsync(getRequest); Console.WriteLine($"Index document: {getResponse.WebsiteConfiguration.IndexDocumentSuffix}"); Console.WriteLine($"Error document: {getResponse.WebsiteConfiguration.ErrorDocument}");
-
For API details, see GetBucketWebsite in AWS SDK for .NET API Reference.
-
- C++
-
- SDK for C++
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. bool AwsDoc::S3::GetWebsiteConfig(const Aws::String &bucketName, const Aws::Client::ClientConfiguration &clientConfig) { Aws::S3::S3Client s3_client(clientConfig); Aws::S3::Model::GetBucketWebsiteRequest request; request.SetBucket(bucketName); Aws::S3::Model::GetBucketWebsiteOutcome outcome = s3_client.GetBucketWebsite(request); if (!outcome.IsSuccess()) { const Aws::S3::S3Error &err = outcome.GetError(); std::cerr << "Error: GetBucketWebsite: " << err.GetMessage() << std::endl; } else { Aws::S3::Model::GetBucketWebsiteResult websiteResult = outcome.GetResult(); std::cout << "Success: GetBucketWebsite: " << std::endl << std::endl << "For bucket '" << bucketName << "':" << std::endl << "Index page : " << websiteResult.GetIndexDocument().GetSuffix() << std::endl << "Error page: " << websiteResult.GetErrorDocument().GetKey() << std::endl; } return outcome.IsSuccess(); }
-
For API details, see GetBucketWebsite in AWS SDK for C++ API Reference.
-
- CLI
-
- AWS CLI
-
The following command retrieves the static website configuration for a bucket named
my-bucket
:aws s3api get-bucket-website --bucket my-bucket
Output:
{ "IndexDocument": { "Suffix": "index.html" }, "ErrorDocument": { "Key": "error.html" } }
-
For API details, see GetBucketWebsite
in AWS CLI Command Reference.
-
- 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 AWS Code Examples Repository
. Get the website configuration.
import { GetBucketWebsiteCommand, S3Client } from "@aws-sdk/client-s3"; const client = new S3Client({}); export const main = async () => { const command = new GetBucketWebsiteCommand({ Bucket: "test-bucket", }); try { const { ErrorDocument, IndexDocument } = await client.send(command); console.log( `Your bucket is set up to host a website. It has an error document:`, `${ErrorDocument.Key}, and an index document: ${IndexDocument.Suffix}.`, ); } catch (err) { console.error(err); } };
-
For API details, see GetBucketWebsite in AWS SDK for JavaScript API Reference.
-
- PowerShell
-
- Tools for PowerShell
-
Example 1: This command returns the details of the static website configurations of the given S3 bucket.
Get-S3BucketWebsite -BucketName 's3testbucket'
-
For API details, see GetBucketWebsite in AWS Tools for PowerShell Cmdlet Reference.
-