AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
与 AWS SDK或GetBucketWebsite
一起使用 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}");
-
有关API详细信息,请参阅 “AWS SDK for .NET API参考 GetBucketWebsite” 中的。
-
- C++
-
- SDK对于 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(); }
-
有关API详细信息,请参阅 “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详细信息,请参阅 “GetBucketWebsite AWS CLI
命令参考”。
-
- JavaScript
-
- SDK对于 JavaScript (v3)
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 获取网站配置。
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; } } };
-
有关API详细信息,请参阅 “AWS SDK for JavaScript API参考 GetBucketWebsite” 中的。
-
- PowerShell
-
- 用于 PowerShell
-
示例 1:此命令返回给定 S3 存储桶的静态网站配置的详细信息。
Get-S3BucketWebsite -BucketName 'amzn-s3-demo-bucket'
-
有关API详细信息,请参阅 AWS Tools for PowerShell Cmdlet 参考GetBucketWebsite中的。
-
GetBucketVersioning
GetObject