How to use describe_receipt_rule_set method in localstack

Best Python code snippet using localstack_python

ses_receipt_handler.py

Source:ses_receipt_handler.py Github

copy

Full Screen

...147 rule_name, recipients, bucket_name)148 except ClientError:149 logger.exception("Couldn't create rule %s.", rule_name)150 raise151 def describe_receipt_rule_set(self, rule_set_name):152 """153 Gets data about a rule set.154 :param rule_set_name: The name of the rule set to retrieve.155 :return: Data about the rule set.156 """157 try:158 response = self.ses_client.describe_receipt_rule_set(159 RuleSetName=rule_set_name)160 logger.info("Got data for rule set %s.", rule_set_name)161 except ClientError:162 logger.exception("Couldn't get data for rule set %s.", rule_set_name)163 raise164 else:165 return response166 def delete_receipt_rule(self, rule_set_name, rule_name):167 """168 Deletes a rule.169 :param rule_set_name: The rule set that contains the rule to delete.170 :param rule_name: The rule to delete.171 """172 try:173 self.ses_client.delete_receipt_rule(174 RuleSetName=rule_set_name, RuleName=rule_name)175 logger.info("Removed rule %s from rule set %s.", rule_name, rule_set_name)176 except ClientError:177 logger.exception(178 "Couldn't remove rule %s from rule set %s.", rule_name, rule_set_name)179 raise180 def delete_receipt_rule_set(self, rule_set_name):181 """182 Deletes a rule set. When a rule set is deleted, all of the rules it contains183 are also deleted.184 :param rule_set_name: The name of the rule set to delete.185 """186 try:187 self.ses_client.delete_receipt_rule_set(RuleSetName=rule_set_name)188 logger.info("Deleted rule set %s.", rule_set_name)189 except ClientError:190 logger.exception("Couldn't delete rule set %s.", rule_set_name)191 raise192def usage_demo():193 print('-'*88)194 print("Welcome to the Amazon Simple Email Service (Amazon SES) receipt rules "195 "and filters demo!")196 print('-'*88)197 logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s')198 ses_receipt = SesReceiptHandler(boto3.client('ses'), boto3.resource('s3'))199 filter_name = 'block-self'200 rule_set_name = 'doc-example-rule-set'201 rule_name = 'copy-mail-to-bucket'202 email = 'example@example.org'203 bucket_name = f'doc-example-bucket-{time.time_ns()}'204 prefix = 'example-emails/'205 current_ip_address = request.urlopen(206 'http://checkip.amazonaws.com').read().decode('utf-8').strip()207 print(f"Adding a filter to block email from the current IP address "208 f"{current_ip_address}.")209 ses_receipt.create_receipt_filter(filter_name, current_ip_address, False)210 filters = ses_receipt.list_receipt_filters()211 print("Current filters now in effect are:")212 print(*filters, sep='\n')213 print("Removing filter.")214 ses_receipt.delete_receipt_filter(filter_name)215 print(f"Creating a rule set and adding a rule to copy all emails received by "216 f"{email} to Amazon S3 bucket {bucket_name}.")217 print(f"Creating bucket {bucket_name} to hold emails.")218 bucket = ses_receipt.create_bucket_for_copy(bucket_name)219 ses_receipt.create_receipt_rule_set(rule_set_name)220 ses_receipt.create_s3_copy_rule(221 rule_set_name, rule_name, [email], bucket.name, prefix)222 rule_set = ses_receipt.describe_receipt_rule_set(rule_set_name)223 print(f"Rule set {rule_set_name} looks like this:")224 pprint(rule_set)225 print(f"Deleting rule {rule_name} and rule set {rule_set_name}.")226 ses_receipt.delete_receipt_rule(rule_set_name, rule_name)227 ses_receipt.delete_receipt_rule_set(rule_set_name)228 print(f"Emptying and deleting bucket {bucket_name}.")229 bucket.objects.delete()230 bucket.delete()231 print("Thanks for watching!")232 print('-'*88)233if __name__ == '__main__':...

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