Seleziona le tue preferenze relative ai cookie

Utilizziamo cookie essenziali e strumenti simili necessari per fornire il nostro sito e i nostri servizi. Utilizziamo i cookie prestazionali per raccogliere statistiche anonime in modo da poter capire come i clienti utilizzano il nostro sito e apportare miglioramenti. I cookie essenziali non possono essere disattivati, ma puoi fare clic su \"Personalizza\" o \"Rifiuta\" per rifiutare i cookie prestazionali.

Se sei d'accordo, AWS e le terze parti approvate utilizzeranno i cookie anche per fornire utili funzionalità del sito, ricordare le tue preferenze e visualizzare contenuti pertinenti, inclusa la pubblicità pertinente. Per continuare senza accettare questi cookie, fai clic su \"Continua\" o \"Rifiuta\". Per effettuare scelte più dettagliate o saperne di più, fai clic su \"Personalizza\".

Use GetBucketWebsite with an AWS SDK or CLI - Amazon Simple Storage Service
Questa pagina non è tradotta nella tua lingua. Richiedi traduzione

Use GetBucketWebsite with an AWS SDK or CLI

The following code examples show how to use GetBucketWebsite.

.NET
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}");
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::S3::S3ClientConfiguration &clientConfig) { Aws::S3::S3Client s3Client(clientConfig); Aws::S3::Model::GetBucketWebsiteRequest request; request.SetBucket(bucketName); Aws::S3::Model::GetBucketWebsiteOutcome outcome = s3Client.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(); }
CLI
AWS CLI

The following command retrieves the static website configuration for a bucket named amzn-s3-demo-bucket:

aws s3api get-bucket-website --bucket amzn-s3-demo-bucket

Output:

{ "IndexDocument": { "Suffix": "index.html" }, "ErrorDocument": { "Key": "error.html" } }
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, S3ServiceException, } from "@aws-sdk/client-s3"; /** * Log the website configuration for a bucket. * @param {{ bucketName }} */ export const main = async ({ bucketName }) => { const client = new S3Client({}); try { const response = await client.send( new GetBucketWebsiteCommand({ Bucket: bucketName, }), ); console.log( `Your bucket is set up to host a website with the following configuration:\n${JSON.stringify(response, null, 2)}`, ); } catch (caught) { if ( caught instanceof S3ServiceException && caught.name === "NoSuchWebsiteConfiguration" ) { console.error( `Error from S3 while getting website configuration for ${bucketName}. The bucket isn't configured as a website.`, ); } else if (caught instanceof S3ServiceException) { console.error( `Error from S3 while getting website configuration for ${bucketName}. ${caught.name}: ${caught.message}`, ); } else { throw caught; } } };
  • 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 'amzn-s3-demo-bucket'
  • For API details, see GetBucketWebsite in AWS Tools for PowerShell Cmdlet Reference.

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 a complete list of AWS SDK developer guides and code examples, see Developing with Amazon S3 using the AWS SDKs. This topic also includes information about getting started and details about previous SDK versions.

Argomento successivo:

GetObject

Argomento precedente:

GetBucketVersioning
PrivacyCondizioni del sitoPreferenze cookie
© 2025, Amazon Web Services, Inc. o società affiliate. Tutti i diritti riservati.