将 PutBucketAccelerateConfiguration
与 AWS SDK 或 CLI 配合使用
以下代码示例演示如何使用 PutBucketAccelerateConfiguration
。
- .NET
-
- AWS SDK for .NET
-
注意
查看 GitHub,了解更多信息。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 using System; using System.Threading.Tasks; using Amazon.S3; using Amazon.S3.Model; /// <summary> /// Amazon Simple Storage Service (Amazon S3) Transfer Acceleration is a /// bucket-level feature that enables you to perform faster data transfers /// to Amazon S3. This example shows how to configure Transfer /// Acceleration. /// </summary> public class TransferAcceleration { /// <summary> /// The main method initializes the client object and sets the /// Amazon Simple Storage Service (Amazon S3) bucket name before /// calling EnableAccelerationAsync. /// </summary> public static async Task Main() { var s3Client = new AmazonS3Client(); const string bucketName = "doc-example-bucket"; await EnableAccelerationAsync(s3Client, bucketName); } /// <summary> /// This method sets the configuration to enable transfer acceleration /// for the bucket referred to in the bucketName parameter. /// </summary> /// <param name="client">An Amazon S3 client used to enable the /// acceleration on an Amazon S3 bucket.</param> /// <param name="bucketName">The name of the Amazon S3 bucket for which the /// method will be enabling acceleration.</param> private static async Task EnableAccelerationAsync(AmazonS3Client client, string bucketName) { try { var putRequest = new PutBucketAccelerateConfigurationRequest { BucketName = bucketName, AccelerateConfiguration = new AccelerateConfiguration { Status = BucketAccelerateStatus.Enabled, }, }; await client.PutBucketAccelerateConfigurationAsync(putRequest); var getRequest = new GetBucketAccelerateConfigurationRequest { BucketName = bucketName, }; var response = await client.GetBucketAccelerateConfigurationAsync(getRequest); Console.WriteLine($"Acceleration state = '{response.Status}' "); } catch (AmazonS3Exception ex) { Console.WriteLine($"Error occurred. Message:'{ex.Message}' when setting transfer acceleration"); } } }
-
有关 API 详细信息,请参阅《AWS SDK for .NET API 参考》中的 PutBucketAccelerateConfiguration。
-
- CLI
-
- AWS CLI
-
设置存储桶的加速配置
以下
put-bucket-accelerate-configuration
示例启用指定存储桶的加速配置。aws s3api put-bucket-accelerate-configuration \ --bucket
my-bucket
\ --accelerate-configurationStatus=Enabled
此命令不生成任何输出。
-
有关 API 详细信息,请参阅《AWS CLI 命令参考》中的 PutBucketAccelerateConfiguration
。
-
- PowerShell
-
- 适用于 PowerShell 的工具
-
示例 1:此命令为给定 S3 存储桶启用传输加速。
$statusVal = New-Object Amazon.S3.BucketAccelerateStatus('Enabled') Write-S3BucketAccelerateConfiguration -BucketName 's3testbucket' -AccelerateConfiguration_Status $statusVal
-
有关 API 详细信息,请参阅《AWS Tools for PowerShell Cmdlet 参考》中的 PutBucketAccelerateConfiguration。
-
有关 AWS SDK 开发人员指南和代码示例的完整列表,请参阅 将此服务与 AWS SDK 结合使用。本主题还包括有关入门的信息以及有关先前的 SDK 版本的详细信息。
ListObjectsV2
PutBucketAcl