AWS 文檔 AWS SDK示例 GitHub 回購中有更多SDK示例
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
搭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 資料串流開發人員指南中的標記串流。
-
如需詳API細資訊,請參閱AWS CLI 指令參考AddTagsToStream
中的。
-
動作
CreateStream