文档 AWS SDK 示例 GitHub 存储库中还有更多 S AWS DK 示例
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
AddTagsToStream
与 AWS SDK 或 CLI 配合使用
以下代码示例演示如何使用 AddTagsToStream
。
- .NET
-
- AWS SDK for .NET
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 using System; using System.Collections.Generic; using System.Threading.Tasks; using Amazon.Kinesis; using Amazon.Kinesis.Model; /// <summary> /// This example shows how to apply key/value pairs to an Amazon Kinesis /// stream. /// </summary> public class TagStream { public static async Task Main() { IAmazonKinesis client = new AmazonKinesisClient(); string streamName = "AmazonKinesisStream"; var tags = new Dictionary<string, string> { { "Project", "Sample Kinesis Project" }, { "Application", "Sample Kinesis App" }, }; var success = await ApplyTagsToStreamAsync(client, streamName, tags); if (success) { Console.WriteLine($"Taggs successfully added to {streamName}."); } else { Console.WriteLine("Tags were not added to the stream."); } } /// <summary> /// Applies the set of tags to the named Kinesis stream. /// </summary> /// <param name="client">The initialized Kinesis client.</param> /// <param name="streamName">The name of the Kinesis stream to which /// the tags will be attached.</param> /// <param name="tags">A sictionary containing key/value pairs which /// will be used to create the Kinesis tags.</param> /// <returns>A Boolean value which represents the success or failure /// of AddTagsToStreamAsync.</returns> public static async Task<bool> ApplyTagsToStreamAsync( IAmazonKinesis client, string streamName, Dictionary<string, string> tags) { var request = new AddTagsToStreamRequest { StreamName = streamName, Tags = tags, }; var response = await client.AddTagsToStreamAsync(request); return response.HttpStatusCode == System.Net.HttpStatusCode.OK; } }
-
有关 API 的详细信息,请参阅 AWS SDK for .NET API 参考AddTagsToStream中的。
-
- CLI
-
- AWS CLI
-
为数据流添加标签
以下
add-tags-to-stream
示例将键为samplekey
且值为example
的标签分配给指定流。aws kinesis add-tags-to-stream \ --stream-name
samplestream
\ --tagssamplekey=example
此命令不生成任何输出。
有关更多信息,请参阅《Amazon Kinesis Data Streams 开发人员指南》中的标记流。
-
有关 API 的详细信息,请参阅AWS CLI 命令参考AddTagsToStream
中的。
-
操作
CreateStream