Configuration for accessing Amazon Kinesis service
Inheritance: Amazon.Runtime.ClientConfig
コード例 #1
0
        public async Task<IHttpActionResult> Post()
        {
            var o = new
            {
                Message = "Hello World",
                Author = "David Judd"
            };

            //convert to byte array in prep for adding to stream
            byte[] oByte = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(o));

            //create config that points to AWS region
            var config = new AmazonKinesisConfig();
            config.RegionEndpoint = Amazon.RegionEndpoint.USEast1;

            //create client that pulls creds from web.config and takes in Kinesis config
            var client = new AmazonKinesisClient(config);

            using (MemoryStream ms = new MemoryStream(oByte))
            {
                //create put request
                PutRecordRequest requestRecord = new PutRecordRequest();
                //list name of Kinesis stream
                requestRecord.StreamName = "shomi_dev";
                //give partition key that is used to place record in particular shard
                requestRecord.PartitionKey = DateTime.Now.Ticks.ToString();
                //add record as memorystream
                requestRecord.Data = ms;

                //PUT the record to Kinesis
                var response = await client.PutRecordAsync(requestRecord);
                return Ok(new
                {
                    seq = response.SequenceNumber
                });
            }
        }
コード例 #2
0
 /// <summary>
 /// Constructs AmazonKinesisClient with AWS Credentials and an
 /// AmazonKinesisClient Configuration object.
 /// </summary>
 /// <param name="credentials">AWS Credentials</param>
 /// <param name="clientConfig">The AmazonKinesisClient Configuration Object</param>
 public AmazonKinesisClient(AWSCredentials credentials, AmazonKinesisConfig clientConfig)
     : base(credentials, clientConfig, AuthenticationTypes.User | AuthenticationTypes.Session)
 {
 }
コード例 #3
0
 /// <summary>
 /// Constructs AmazonKinesisClient with AWS Access Key ID, AWS Secret Key and an
 /// AmazonKinesisClient Configuration object. If the config object's
 /// UseSecureStringForAwsSecretKey is false, the AWS Secret Key
 /// is stored as a clear-text string. Please use this option only
 /// if the application environment doesn't allow the use of SecureStrings.
 /// </summary>
 /// <param name="awsAccessKeyId">AWS Access Key ID</param>
 /// <param name="awsSecretAccessKey">AWS Secret Access Key</param>
 /// <param name="awsSessionToken">AWS Session Token</param>
 /// <param name="clientConfig">The AmazonKinesisClient Configuration Object</param>
 public AmazonKinesisClient(string awsAccessKeyId, string awsSecretAccessKey, string awsSessionToken, AmazonKinesisConfig clientConfig)
     : base(awsAccessKeyId, awsSecretAccessKey, awsSessionToken, clientConfig, AuthenticationTypes.User | AuthenticationTypes.Session)
 {
 }
コード例 #4
0
 /// <summary>
 /// Constructs AmazonKinesisClient with AWS Credentials and an
 /// AmazonKinesisClient Configuration object.
 /// </summary>
 /// <param name="credentials">AWS Credentials</param>
 /// <param name="clientConfig">The AmazonKinesisClient Configuration Object</param>
 public AmazonKinesisClient(AWSCredentials credentials, AmazonKinesisConfig clientConfig)
     : base(credentials, clientConfig)
 {
 }
コード例 #5
0
 /// <summary>
 /// Constructs AmazonKinesisClient with AWS Access Key ID, AWS Secret Key and an
 /// AmazonKinesisClient Configuration object. 
 /// </summary>
 /// <param name="awsAccessKeyId">AWS Access Key ID</param>
 /// <param name="awsSecretAccessKey">AWS Secret Access Key</param>
 /// <param name="awsSessionToken">AWS Session Token</param>
 /// <param name="clientConfig">The AmazonKinesisClient Configuration Object</param>
 public AmazonKinesisClient(string awsAccessKeyId, string awsSecretAccessKey, string awsSessionToken, AmazonKinesisConfig clientConfig)
     : base(awsAccessKeyId, awsSecretAccessKey, awsSessionToken, clientConfig)
 {
 }
コード例 #6
0
 /// <summary>
 /// Constructs AmazonKinesisClient with the credentials loaded from the application's
 /// default configuration, and if unsuccessful from the Instance Profile service on an EC2 instance.
 /// 
 /// Example App.config with credentials set. 
 /// <code>
 /// &lt;?xml version="1.0" encoding="utf-8" ?&gt;
 /// &lt;configuration&gt;
 ///     &lt;appSettings&gt;
 ///         &lt;add key="AWSProfileName" value="AWS Default"/&gt;
 ///     &lt;/appSettings&gt;
 /// &lt;/configuration&gt;
 /// </code>
 ///
 /// </summary>
 /// <param name="config">The AmazonKinesisClient Configuration Object</param>
 public AmazonKinesisClient(AmazonKinesisConfig config)
     : base(FallbackCredentialsFactory.GetCredentials(), config) { }
コード例 #7
0
 /// <summary>
 /// Constructs AmazonKinesisClient with the credentials loaded from the application's
 /// default configuration, and if unsuccessful from the Instance Profile service on an EC2 instance.
 /// 
 /// Example App.config with credentials set. 
 /// <code>
 /// &lt;?xml version="1.0" encoding="utf-8" ?&gt;
 /// &lt;configuration&gt;
 ///     &lt;appSettings&gt;
 ///         &lt;add key="AWSProfileName" value="AWS Default"/&gt;
 ///     &lt;/appSettings&gt;
 /// &lt;/configuration&gt;
 /// </code>
 ///
 /// </summary>
 /// <param name="config">The AmazonKinesis Configuration Object</param>
 public AmazonKinesisClient(AmazonKinesisConfig config)
     : base(FallbackCredentialsFactory.GetCredentials(), config, AuthenticationTypes.User | AuthenticationTypes.Session) { }
コード例 #8
0
 /// <summary>
 /// Constructs AmazonKinesisClient with AWS Credentials and an
 /// AmazonKinesisClient Configuration object.
 /// </summary>
 /// <param name="credentials">AWS Credentials</param>
 /// <param name="clientConfig">The AmazonKinesisClient Configuration Object</param>
 public AmazonKinesisClient(AWSCredentials credentials, AmazonKinesisConfig clientConfig)
     : base(credentials, clientConfig, AuthenticationTypes.User | AuthenticationTypes.Session)
 {
 }
コード例 #9
0
 /// <summary>
 /// Constructs AmazonKinesisClient with AWS Credentials and an
 /// AmazonKinesisClient Configuration object.
 /// </summary>
 /// <param name="credentials">AWS Credentials</param>
 /// <param name="clientConfig">The AmazonKinesisClient Configuration Object</param>
 public AmazonKinesisClient(AWSCredentials credentials, AmazonKinesisConfig clientConfig)
     : base(credentials, clientConfig)
 {
 }
コード例 #10
0
 /// <summary>
 /// Constructs AmazonKinesisClient with the credentials loaded from the application's
 /// default configuration, and if unsuccessful from the Instance Profile service on an EC2 instance.
 ///
 /// Example App.config with credentials set.
 /// <code>
 /// &lt;?xml version="1.0" encoding="utf-8" ?&gt;
 /// &lt;configuration&gt;
 ///     &lt;appSettings&gt;
 ///         &lt;add key="AWSProfileName" value="AWS Default"/&gt;
 ///     &lt;/appSettings&gt;
 /// &lt;/configuration&gt;
 /// </code>
 ///
 /// </summary>
 /// <param name="config">The AmazonKinesis Configuration Object</param>
 public AmazonKinesisClient(AmazonKinesisConfig config)
     : base(FallbackCredentialsFactory.GetCredentials(), config, AuthenticationTypes.User | AuthenticationTypes.Session)
 {
 }
コード例 #11
0
 /// <summary>
 /// Constructs AmazonKinesisClient with AWS Access Key ID, AWS Secret Key and an
 /// AmazonKinesisClient Configuration object.
 /// </summary>
 /// <param name="awsAccessKeyId">AWS Access Key ID</param>
 /// <param name="awsSecretAccessKey">AWS Secret Access Key</param>
 /// <param name="awsSessionToken">AWS Session Token</param>
 /// <param name="clientConfig">The AmazonKinesisClient Configuration Object</param>
 public AmazonKinesisClient(string awsAccessKeyId, string awsSecretAccessKey, string awsSessionToken, AmazonKinesisConfig clientConfig)
     : base(awsAccessKeyId, awsSecretAccessKey, awsSessionToken, clientConfig)
 {
 }
コード例 #12
0
 /// <summary>
 /// Create a client for the Amazon Kinesis Service with the credentials loaded from the application's
 /// default configuration, and if unsuccessful from the Instance Profile service on an EC2 instance.
 /// 
 /// Example App.config with credentials set. 
 /// <code>
 /// &lt;?xml version="1.0" encoding="utf-8" ?&gt;
 /// &lt;configuration&gt;
 ///     &lt;appSettings&gt;
 ///         &lt;add key="AWSProfileName" value="AWS Default"/&gt;
 ///     &lt;/appSettings&gt;
 /// &lt;/configuration&gt;
 /// </code>
 /// </summary>
 /// <param name="config">Configuration options for the service like HTTP Proxy, # of connections, etc</param>
 /// <returns>An Amazon Kinesis client</returns>
 public static IAmazonKinesis CreateAmazonKinesisClient(AmazonKinesisConfig config)
 {
     return new AmazonKinesisClient(config);
 }
コード例 #13
0
 /// <summary>
 /// Constructs AmazonKinesisClient with the credentials loaded from the application's
 /// default configuration, and if unsuccessful from the Instance Profile service on an EC2 instance.
 ///
 /// Example App.config with credentials set.
 /// <code>
 /// &lt;?xml version="1.0" encoding="utf-8" ?&gt;
 /// &lt;configuration&gt;
 ///     &lt;appSettings&gt;
 ///         &lt;add key="AWSProfileName" value="AWS Default"/&gt;
 ///     &lt;/appSettings&gt;
 /// &lt;/configuration&gt;
 /// </code>
 ///
 /// </summary>
 /// <param name="config">The AmazonKinesisClient Configuration Object</param>
 public AmazonKinesisClient(AmazonKinesisConfig config)
     : base(FallbackCredentialsFactory.GetCredentials(), config)
 {
 }
コード例 #14
0
 /// <summary>
 /// Create a client for the Amazon Kinesis Service with the specified configuration
 /// </summary>
 /// <param name="awsAccessKey">The AWS Access Key associated with the account</param>
 /// <param name="awsSecretAccessKey">The AWS Secret Access Key associated with the account</param>
 /// <param name="config">Configuration options for the service like HTTP Proxy, # of connections, etc
 /// </param>
 /// <returns>An Amazon Kinesis client</returns>
 /// <remarks>
 /// </remarks>
 public static IAmazonKinesis CreateAmazonKinesisClient(
     string awsAccessKey,
     string awsSecretAccessKey, AmazonKinesisConfig config
     )
 {
     return new AmazonKinesisClient(awsAccessKey, awsSecretAccessKey, config);
 }
コード例 #15
0
 /// <summary>
 /// Constructs AmazonKinesisClient with AWS Access Key ID, AWS Secret Key and an
 /// AmazonKinesisClient Configuration object.
 /// </summary>
 /// <param name="awsAccessKeyId">AWS Access Key ID</param>
 /// <param name="awsSecretAccessKey">AWS Secret Access Key</param>
 /// <param name="awsSessionToken">AWS Session Token</param>
 /// <param name="clientConfig">The AmazonKinesisClient Configuration Object</param>
 public AmazonKinesisClient(string awsAccessKeyId, string awsSecretAccessKey, string awsSessionToken, AmazonKinesisConfig clientConfig)
     : base(awsAccessKeyId, awsSecretAccessKey, awsSessionToken, clientConfig, AuthenticationTypes.User | AuthenticationTypes.Session)
 {
 }
コード例 #16
0
 /// <summary>
 /// Create a client for the Amazon Kinesis Service with AWSCredentials and an AmazonKinesis Configuration object.
 /// </summary>
 /// <param name="credentials">AWS Credentials</param>
 /// <param name="config">Configuration options for the service like HTTP Proxy, # of connections, etc</param>
 /// <returns>An Amazon Kinesis client</returns>
 /// <remarks>
 /// </remarks>
 public static IAmazonKinesis CreateAmazonKinesisClient(AWSCredentials credentials, AmazonKinesisConfig config)
 {
     return new AmazonKinesisClient(credentials, config);
 }
コード例 #17
0
ファイル: Program.cs プロジェクト: Dave76/kinesis-dotnet
        static void Main(string[] args)
        {
            var o = new
            {
                Message = "Hello World",
                Author = "David Judd"
            };

            //convert to byte array in prep for adding to stream
            byte[] oByte = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(o));

            //create config that points to AWS region
            var config = new AmazonKinesisConfig();
            config.RegionEndpoint = Amazon.RegionEndpoint.USEast1;

            //create client that pulls creds from web.config and takes in Kinesis config
            var client = new AmazonKinesisClient(config);

            var sw = Stopwatch.StartNew();
            Stopwatch sw2 = null;

            var tasks = new List<Task<PutRecordResponse>>();

            int count = int.Parse(ConfigurationManager.AppSettings["Count"]);
            Console.WriteLine("Sending {0} records... One at a time...", count);
            sw.Restart();
            for (int i = 0; i < count; i++)
            {
                //System.Threading.Thread.Sleep(10);
                //sw2 = Stopwatch.StartNew();
                //create stream object to add to Kinesis request
                using (MemoryStream ms = new MemoryStream(oByte))
                {
                    //create put request
                    PutRecordRequest requestRecord = new PutRecordRequest();
                    //list name of Kinesis stream
                    requestRecord.StreamName = "shomi_dev";
                    //give partition key that is used to place record in particular shard
                    requestRecord.PartitionKey = i.ToString();
                    //add record as memorystream
                    requestRecord.Data = ms;

                    //PUT the record to Kinesis
                    var task = client.PutRecordAsync(requestRecord);
                    tasks.Add(task);

                }
                //sw2.Stop();
                ///Console.WriteLine("Async latency is {0}", sw2.ElapsedMilliseconds);
            }

            Console.WriteLine("{0} records sent... Waiting for tasks to complete...", count);
            Task.WaitAll(tasks.ToArray(), -1);
            sw.Stop();
            foreach (var t in tasks)
            {
                if (t.Result.HttpStatusCode != System.Net.HttpStatusCode.OK)
                {
                    Console.WriteLine(t.Result.HttpStatusCode);
                }
            }

            double actionsPerSec = (double)count * 1000 / (double)sw.ElapsedMilliseconds;
            Console.WriteLine("{0} requests in {1} ms. {2:0.00} requests/sec.", count, sw.ElapsedMilliseconds, actionsPerSec);
        }