How to use subscribe_to_shard method in localstack

Best Python code snippet using localstack_python

consume_stream_data.py

Source:consume_stream_data.py Github

copy

Full Screen

...57 time.sleep(5)58def fetch_records(stream_name, stream_arn, shard_id, consumer_name, consumer_arn):59 # get dynamodb table to be inserted60 table = get_dynamodb_table('SensorNetworkData')61 response = client.subscribe_to_shard(62 ConsumerARN=consumer_arn,63 ShardId=shard_id,64 StartingPosition={'Type': 'TRIM_HORIZON'}65 )66 shard_iterator = client.get_shard_iterator(StreamName=stream_name,67 ShardId=shard_id,68 ShardIteratorType='TRIM_HORIZON')['ShardIterator']69 counter = 070 while(True and counter < 10000):71 response = client.get_records(ShardIterator=shard_iterator)72 shard_iterator = response['NextShardIterator']73 if len(response['Records']) > 0:74 data = json.loads(response['Records'][0]['Data'], parse_float=Decimal)75 print('Processing sensor: %s', data['sensor_uuid'])76 data_fix = remove_empty_string(data)77 try:78 '''79 table.put_item(80 Item=data_fix81 )82 '''83 print(data_fix)84 counter += 185 except:86 print('ERROR : ')87 else:88 print('Waiting..')89 time.sleep(5)90if __name__ == '__main__':91 stream_name = 'DataStream'92 consumer_name = 'StreamConsumer3'93 # setup dynamodb94 dynamodb = boto3.resource('dynamodb')95 table = dynamodb.Table('DataStream')96 # setup kinesis97 client = boto3.client('kinesis')98 # get stream details99 response = client.describe_stream(StreamName=stream_name)100 stream_arn = response['StreamDescription']['StreamARN']101 shard_id = response['StreamDescription']['Shards'][2]['ShardId']102 # get consumer details103 response = client.describe_stream_consumer(104 StreamARN=stream_arn,105 ConsumerName=consumer_name106 )107 consumer_arn = response['ConsumerDescription']['ConsumerARN']108 # subscribe to shard109 response = client.subscribe_to_shard(110 ConsumerARN=consumer_arn,111 ShardId=shard_id,112 StartingPosition={'Type': 'TRIM_HORIZON'}113 )114 # iterate event stream115 for event in response['EventStream']:116 print(event)117 if len(event['SubscribeToShardEvent']['Records']) > 0:118 # if records are not empty119 for record in event['SubscribeToShardEvent']['Records']:120 data = remove_empty_string(json.loads(record['Data'], parse_float=Decimal))121 print(data)...

Full Screen

Full Screen

test_eventstreams.py

Source:test_eventstreams.py Github

copy

Full Screen

...49 ] == 'CREATING':50 print("Waiting for stream consumer creation")51 await asyncio.sleep(1)52 starting_position = {'Type': 'LATEST'}53 subscribe_response = await kinesis_client.subscribe_to_shard(54 ConsumerARN=consumer_arn,55 ShardId=shard_id,56 StartingPosition=starting_position,57 )58 async for event in subscribe_response['EventStream']:59 assert event['SubscribeToShardEvent']['Records'] == []60 break61 finally:62 if consumer_arn:63 await kinesis_client.deregister_stream_consumer(64 StreamARN=stream_arn,65 ConsumerName=consumer_name,66 ConsumerARN=consumer_arn,67 )...

Full Screen

Full Screen

consumer_service.py

Source:consumer_service.py Github

copy

Full Screen

...23 ConsumerName='Consumer'24 )25 print(register_response)26 shardList = cls.consumer.list_shards(StreamName=cls.STREAM_NAME)27 result = cls.consumer.subscribe_to_shard(28 ConsumerARN=register_response.Consumer.ConsumerARN,29 ShardId=shardList[0].ShardId,30 StartingPosition={31 'Type': 'AT_SEQUENCE_NUMBER'32 }33 )34 print(result)35 cls.consumer.deregister_stream_consumer(36 StreamARN=cls.AWS_ARN,37 ConsumerName='Consumer',38 ConsumerARN=register_response.ConsumerARN...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful