There are more AWS SDK examples available in the AWS Doc SDK Examples
Use RegisterStreamConsumer with an AWS SDK or CLI
The following code examples show how to use RegisterStreamConsumer.
Action examples are code excerpts from larger programs and must be run in context. You can see this action in context in the following code example:
- .NET
-
- SDK for .NET
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. using System; using System.Threading.Tasks; using Amazon.Kinesis; using Amazon.Kinesis.Model; /// <summary> /// This example shows how to register a consumer to an Amazon Kinesis /// stream. /// </summary> public class RegisterConsumer { public static async Task Main() { IAmazonKinesis client = new AmazonKinesisClient(); string consumerName = "NEW_CONSUMER_NAME"; string streamARN = "arn:aws:kinesis:us-east-2:000000000000:stream/AmazonKinesisStream"; var consumer = await RegisterConsumerAsync(client, consumerName, streamARN); if (consumer is not null) { Console.WriteLine($"{consumer.ConsumerName}"); } } /// <summary> /// Registers the consumer to a Kinesis stream. /// </summary> /// <param name="client">The initialized Kinesis client object.</param> /// <param name="consumerName">A string representing the consumer.</param> /// <param name="streamARN">The ARN of the stream.</param> /// <returns>A Consumer object that contains information about the consumer.</returns> public static async Task<Consumer> RegisterConsumerAsync(IAmazonKinesis client, string consumerName, string streamARN) { var request = new RegisterStreamConsumerRequest { ConsumerName = consumerName, StreamARN = streamARN, }; var response = await client.RegisterStreamConsumerAsync(request); return response.Consumer; } }-
For API details, see RegisterStreamConsumer in AWS SDK for .NET API Reference.
-
- CLI
-
- AWS CLI
-
To register a data stream consumer
The following
register-stream-consumerexample registers a consumer calledKinesisConsumerApplicationwith the specified data stream.aws kinesis register-stream-consumer \ --stream-arnarn:aws:kinesis:us-west-2:123456789012:stream/samplestream\ --consumer-nameKinesisConsumerApplicationOutput:
{ "Consumer": { "ConsumerName": "KinesisConsumerApplication", "ConsumerARN": "arn:aws:kinesis:us-west-2: 123456789012:stream/samplestream/consumer/KinesisConsumerApplication:1572383852", "ConsumerStatus": "CREATING", "ConsumerCreationTimestamp": 1572383852.0 } }For more information, see Developing Consumers with Enhanced Fan-Out Using the Kinesis Data Streams API in the Amazon Kinesis Data Streams Developer Guide.
-
For API details, see RegisterStreamConsumer
in AWS CLI Command Reference.
-
- Python
-
- SDK for Python (Boto3)
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. def register_stream_consumer(self, stream_arn, consumer_name): """ Registers an enhanced fan-out consumer with a Kinesis data stream. :param stream_arn: The ARN of the stream. :param consumer_name: The name for the consumer. :return: A dictionary containing consumer details. """ try: response = self.kinesis_client.register_stream_consumer( StreamARN=stream_arn, ConsumerName=consumer_name ) consumer = response.get("Consumer", dict()) logger.info( "Registered consumer '%s' with status '%s'.", consumer_name, consumer.get("ConsumerStatus", "UNKNOWN"), ) return consumer except ClientError as err: if err.response["Error"]["Code"] == "ResourceInUseException": logger.error( "Consumer '%s' already exists or stream is not available.", consumer_name, ) raise-
For API details, see RegisterStreamConsumer in AWS SDK for Python (Boto3) API Reference.
-
- SAP ABAP
-
- SDK for SAP ABAP
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. TRY. oo_result = lo_kns->registerstreamconsumer( " oo_result is returned for testing purposes. " iv_streamarn = iv_stream_arn iv_consumername = iv_consumer_name ). MESSAGE 'Stream consumer registered.' TYPE 'I'. CATCH /aws1/cx_knsinvalidargumentex. MESSAGE 'The specified argument was not valid.' TYPE 'E'. CATCH /aws1/cx_sgmresourcelimitexcd. MESSAGE 'You have reached the limit on the number of resources.' TYPE 'E'. CATCH /aws1/cx_sgmresourceinuse. MESSAGE 'Resource being accessed is in use.' TYPE 'E'. CATCH /aws1/cx_sgmresourcenotfound. MESSAGE 'Resource being accessed is not found.' TYPE 'E'. ENDTRY.-
For API details, see RegisterStreamConsumer in AWS SDK for SAP ABAP API reference.
-