Best Python code snippet using localstack_python
34076_dynamodb_listener.py
Source:34076_dynamodb_listener.py
...94 record['eventName'] = 'REMOVE'95 record['dynamodb']['Keys'] = data['Key']96 elif action == '%s.CreateTable' % ACTION_PREFIX:97 if 'StreamSpecification' in data:98 create_dynamodb_stream(data)99 event_publisher.fire_event(event_publisher.EVENT_DYNAMODB_CREATE_TABLE,100 payload={'n': event_publisher.get_hash(data['TableName'])})101 return102 elif action == '%s.DeleteTable' % ACTION_PREFIX:103 event_publisher.fire_event(event_publisher.EVENT_DYNAMODB_DELETE_TABLE,104 payload={'n': event_publisher.get_hash(data['TableName'])})105 return106 elif action == '%s.UpdateTable' % ACTION_PREFIX:107 if 'StreamSpecification' in data:108 create_dynamodb_stream(data)109 return110 else:111 # nothing to do112 return113 if 'TableName' in data:114 record['eventSourceARN'] = aws_stack.dynamodb_table_arn(data['TableName'])115 forward_to_lambda(records)116 forward_to_ddb_stream(records)117# instantiate listener118UPDATE_DYNAMODB = ProxyListenerDynamoDB()119def calculate_crc32(response):120 return crc32(to_bytes(response.content)) & 0xffffffff121def create_dynamodb_stream(data):122 stream = data['StreamSpecification']123 enabled = stream.get('StreamEnabled')124 if enabled not in [False, 'False']:125 table_name = data['TableName']126 view_type = stream['StreamViewType']127 dynamodbstreams_api.add_dynamodb_stream(table_name=table_name,128 view_type=view_type, enabled=enabled)129def forward_to_lambda(records):130 for record in records:131 sources = lambda_api.get_event_sources(source_arn=record['eventSourceARN'])132 event = {133 'Records': [record]134 }135 for src in sources:...
dynamodb_listener.py
Source:dynamodb_listener.py
...94 record['eventName'] = 'REMOVE'95 record['dynamodb']['Keys'] = data['Key']96 elif action == '%s.CreateTable' % ACTION_PREFIX:97 if 'StreamSpecification' in data:98 create_dynamodb_stream(data)99 event_publisher.fire_event(event_publisher.EVENT_DYNAMODB_CREATE_TABLE,100 payload={'n': event_publisher.get_hash(data['TableName'])})101 return102 elif action == '%s.DeleteTable' % ACTION_PREFIX:103 event_publisher.fire_event(event_publisher.EVENT_DYNAMODB_DELETE_TABLE,104 payload={'n': event_publisher.get_hash(data['TableName'])})105 return106 elif action == '%s.UpdateTable' % ACTION_PREFIX:107 if 'StreamSpecification' in data:108 create_dynamodb_stream(data)109 return110 else:111 # nothing to do112 return113 if 'TableName' in data:114 record['eventSourceARN'] = aws_stack.dynamodb_table_arn(data['TableName'])115 forward_to_lambda(records)116 forward_to_ddb_stream(records)117# instantiate listener118UPDATE_DYNAMODB = ProxyListenerDynamoDB()119def calculate_crc32(response):120 return crc32(to_bytes(response.content)) & 0xffffffff121def create_dynamodb_stream(data):122 stream = data['StreamSpecification']123 enabled = stream.get('StreamEnabled')124 if enabled not in [False, 'False']:125 table_name = data['TableName']126 view_type = stream['StreamViewType']127 dynamodbstreams_api.add_dynamodb_stream(table_name=table_name,128 view_type=view_type, enabled=enabled)129def forward_to_lambda(records):130 for record in records:131 sources = lambda_api.get_event_sources(source_arn=record['eventSourceARN'])132 event = {133 'Records': [record]134 }135 for src in sources:...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!