Advertisement
Guest User

code

a guest
Apr 10th, 2014
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using Newtonsoft.Json;
  8.  
  9.  
  10.  
  11. using Amazon;
  12. using Amazon.EC2;
  13. using Amazon.EC2.Model;
  14. using Amazon.Kinesis;
  15. using Amazon.Kinesis.Model;
  16. using Amazon.SimpleDB;
  17. using Amazon.SimpleDB.Model;
  18. using Amazon.S3;
  19. using Amazon.S3.Model;
  20.  
  21. namespace AwsConsoleApp1
  22. {
  23.     class Program
  24.     {
  25.         public static void Main(string[] args)
  26.         {
  27.             string input;
  28.             Console.WriteLine("Type a value to be sent to the cloud");
  29.             input = Console.ReadLine();
  30.             Console.Write(GetServiceOutput(input));
  31.             Console.Read();
  32.         }
  33.  
  34.         public static string GetServiceOutput(string input)
  35.         {
  36.             string output;
  37.  
  38.             string text = input;
  39.  
  40.             byte[] oByte = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(text));
  41.  
  42.             using (MemoryStream ms = new MemoryStream(oByte))
  43.             {
  44.                 //create config that points to AWS region
  45.                 AmazonKinesisConfig config = new AmazonKinesisConfig();
  46.                 config.RegionEndpoint = Amazon.RegionEndpoint.USEast1;
  47.  
  48.                 //create client that pulls creds from web.config and takes in Kinesis config
  49.                 AmazonKinesisClient client = new AmazonKinesisClient(config);
  50.  
  51.                 //create put request
  52.                 PutRecordRequest requestRecord = new PutRecordRequest();
  53.                 //list name of Kinesis stream
  54.                 requestRecord.StreamName = "TestStream";
  55.                 //give partition key that is used to place record in particular shard
  56.                 requestRecord.PartitionKey = "testkey";
  57.                 //add record as memorystream
  58.                 requestRecord.Data = ms;
  59.  
  60.                 //PUT the record to Kinesis
  61.                 PutRecordResponse responseRecord = client.PutRecord(requestRecord);
  62.  
  63.                 //show shard ID and sequence number to user
  64.                 output = "Shard ID: " + responseRecord.ShardId;
  65.                 output = output + "Sequence #:" + responseRecord.SequenceNumber;
  66.                 return output;
  67.             }
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement