Best Python code snippet using localstack_python
dead_letter_queue.py
Source:dead_letter_queue.py
...16 return17 target_arn = policy.get('deadLetterTargetArn')18 if not target_arn:19 return20 return _send_to_dead_letter_queue('SQS', queue_arn, target_arn, event, error)21def sns_error_to_dead_letter_queue(sns_subscriber_arn, event, error):22 client = aws_stack.connect_to_service('sns')23 attrs = client.get_subscription_attributes(SubscriptionArn=sns_subscriber_arn)24 attrs = attrs.get('Attributes', {})25 policy = json.loads(attrs.get('RedrivePolicy') or '{}')26 target_arn = policy.get('deadLetterTargetArn')27 if not target_arn:28 return29 return _send_to_dead_letter_queue('SQS', sns_subscriber_arn, target_arn, event, error)30def lambda_error_to_dead_letter_queue(func_details, event, error):31 dlq_arn = (func_details.dead_letter_config or {}).get('TargetArn')32 source_arn = func_details.id33 return _send_to_dead_letter_queue('Lambda', source_arn, dlq_arn, event, error)34def _send_to_dead_letter_queue(source_type, source_arn, dlq_arn, event, error):35 if not dlq_arn:36 return37 LOG.info('Sending failed execution %s to dead letter queue %s' % (source_arn, dlq_arn))38 message = json.dumps(event)39 message_attrs = {40 'RequestID': {'DataType': 'String', 'StringValue': str(uuid.uuid4())},41 'ErrorCode': {'DataType': 'String', 'StringValue': '200'},42 'ErrorMessage': {'DataType': 'String', 'StringValue': str(error)}43 }44 if ':sqs:' in dlq_arn:45 queue_url = aws_stack.get_sqs_queue_url(dlq_arn)46 sqs_client = aws_stack.connect_to_service('sqs')47 error = None48 result_code = None...
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!!