将 GetBucketWebsite
与 AWS SDK 或 CLI 配合使用
以下代码示例演示如何使用 GetBucketWebsite
。
- .NET
-
- AWS SDK for .NET
-
注意
查看 GitHub,了解更多信息。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 // 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}");
-
有关更多信息,请参阅《AWS SDK for .NET API 参考》中的 GetBucketWebsite。
-
- C++
-
- SDK for C++
-
注意
查看 GitHub,了解更多信息。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 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(); }
-
有关更多信息,请参阅《AWS SDK for C++ API 参考》中的 GetBucketWebsite。
-
- CLI
-
- AWS CLI
-
以下命令检索名为
my-bucket
的存储桶的静态网站配置:aws s3api get-bucket-website --bucket
my-bucket
输出:
{ "IndexDocument": { "Suffix": "index.html" }, "ErrorDocument": { "Key": "error.html" } }
-
有关 API 详细信息,请参阅《AWS CLI 命令参考》中的 GetBucketWebsite
。
-
- JavaScript
-
- SDK for JavaScript (v3)
-
注意
查看 GitHub,了解更多信息。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 获取网站配置。
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); } };
-
有关更多信息,请参阅《AWS SDK for JavaScript API 参考》中的 GetBucketWebsite。
-
- PowerShell
-
- 适用于 PowerShell 的工具
-
示例 1:此命令返回给定 S3 存储桶的静态网站配置的详细信息。
Get-S3BucketWebsite -BucketName 's3testbucket'
-
有关 API 详细信息,请参阅《AWS Tools for PowerShell Cmdlet 参考》中的 GetBucketWebsite。
-
有关 AWS SDK 开发人员指南和代码示例的完整列表,请参阅 将此服务与 AWS SDK 结合使用。本主题还包括有关入门的信息以及有关先前的 SDK 版本的详细信息。
GetBucketVersioning
GetObject