Best Python code snippet using localstack_python
test_ses_sns_boto3.py
Source:test_ses_sns_boto3.py
...10from moto.core import ACCOUNT_ID11@mock_ses12def test_enable_disable_ses_sns_communication():13 conn = boto3.client("ses", region_name="us-east-1")14 conn.set_identity_notification_topic(15 Identity="test.com", NotificationType="Bounce", SnsTopic="the-arn"16 )17 conn.set_identity_notification_topic(Identity="test.com", NotificationType="Bounce")18def __setup_feedback_env__(19 ses_conn, sns_conn, sqs_conn, domain, topic, queue, region, expected_msg20):21 """Setup the AWS environment to test the SES SNS Feedback"""22 # Environment setup23 # Create SQS queue24 sqs_conn.create_queue(QueueName=queue)25 # Create SNS topic26 create_topic_response = sns_conn.create_topic(Name=topic)27 topic_arn = create_topic_response["TopicArn"]28 # Subscribe the SNS topic to the SQS queue29 sns_conn.subscribe(30 TopicArn=topic_arn,31 Protocol="sqs",32 Endpoint="arn:aws:sqs:%s:%s:%s" % (region, ACCOUNT_ID, queue),33 )34 # Verify SES domain35 ses_conn.verify_domain_identity(Domain=domain)36 # Specify email address to allow for raw e-mails to be processed37 ses_conn.verify_email_identity(EmailAddress="test@example.com")38 # Setup SES notification topic39 if expected_msg is not None:40 ses_conn.set_identity_notification_topic(41 Identity=domain, NotificationType=expected_msg, SnsTopic=topic_arn42 )43def __test_sns_feedback__(addr, expected_msg, raw_email=False):44 region_name = "us-east-1"45 ses_conn = boto3.client("ses", region_name=region_name)46 sns_conn = boto3.client("sns", region_name=region_name)47 sqs_conn = boto3.resource("sqs", region_name=region_name)48 domain = "example.com"49 topic = "bounce-arn-feedback"50 queue = "feedback-test-queue"51 __setup_feedback_env__(52 ses_conn, sns_conn, sqs_conn, domain, topic, queue, region_name, expected_msg53 )54 # Send the message...
customResourceTest.py
Source:customResourceTest.py
...16 if event['RequestType'] == 'Create':17 LOGGER.info('Create custom resource: ' +identity+ " : " +snsTopicARN)18 # Create a new SES resource and specify a region.19 client = boto3.client('ses', region_name="us-east-1")20 client.set_identity_notification_topic(Identity=identity, NotificationType='Bounce', SnsTopic=snsTopicARN)21 client.set_identity_notification_topic(Identity=identity, NotificationType='Complaint', SnsTopic=snsTopicARN)22 client.set_identity_notification_topic(Identity=identity, NotificationType='Delivery', SnsTopic=snsTopicARN)23 send_response(event, context, "SUCCESS", { "Message": "Resource created" })24 25 elif event['RequestType'] == 'Update':26 LOGGER.info('Update custom resource')27 send_response(event, context, "SUCCESS", { "Message": "Resource updated" })28 29 elif event['RequestType'] == 'Delete':30 LOGGER.info('Delete custom resource')31 client = boto3.client('ses', region_name="us-east-1")32 client.set_identity_notification_topic(Identity=identity, NotificationType='Bounce') #Clear out the SNS usage33 client.set_identity_notification_topic(Identity=identity, NotificationType='Complaint')34 client.set_identity_notification_topic(Identity=identity, NotificationType='Delivery')35 send_response(event, context, "SUCCESS", { "Message": "Resource deleted" })36 37 else:38 LOGGER.info('Unexpected event request received from CFM')39 send_response(event, context, "FAILED", { "Message": "Unexpected event received from CFM" })40 41 except:42 LOGGER.error('Unexpected error during processing', exc_info=True)43 send_response(event, context, "FAILED", { "Message": "Exception during processing" })44def send_response(event, context, response_status, response_data):45 # Save the response in S3 using the responseURL46 try:47 response_body = json.dumps({48 "StackId": event['StackId'],...
set_sns_in_ses_metrics.py
Source:set_sns_in_ses_metrics.py
...11 # Enable Fowarding12 response = client.set_identity_feedback_forwarding_enabled(ForwardingEnabled=True, Identity=str(domain))13 14 # Set SNS in Bounce, Complaint, Delivery15 response = client.set_identity_notification_topic(Identity=str(domain), NotificationType='Bounce', SnsTopic=SNS_TOPIC)16 response = client.set_identity_notification_topic(Identity=str(domain), NotificationType='Complaint', SnsTopic=SNS_TOPIC)17 response = client.set_identity_notification_topic(Identity=str(domain), NotificationType='Delivery', SnsTopic=SNS_TOPIC)18 # Enable Headers19 response = client.set_identity_headers_in_notifications_enabled(Identity=str(domain), NotificationType='Bounce', Enabled=True)20 response = client.set_identity_headers_in_notifications_enabled(Identity=str(domain), NotificationType='Complaint', Enabled=True)21 response = client.set_identity_headers_in_notifications_enabled(Identity=str(domain), NotificationType='Delivery', Enabled=True)...
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!!