in python/example_code/ses/ses_replicate_identities.py [0:0]
def replicate(source_client, destination_client, route53_client):
logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s')
print('-'*88)
print(f"Replicating Amazon SES identities and other configuration from "
f"{source_client.meta.region_name} to {destination_client.meta.region_name}.")
print('-'*88)
print(f"Retrieving identities from {source_client.meta.region_name}.")
source_emails, source_domains = get_identities(source_client)
print("Email addresses found:")
print(*source_emails)
print("Domains found:")
print(*source_domains)
print("Starting verification for email identities.")
dest_emails = verify_emails(source_emails, destination_client)
print("Getting domain tokens for domain identities.")
dest_domain_tokens = verify_domains(source_domains, destination_client)
# Get Route 53 hosted zones and match them with Amazon SES domains.
answer = input(
"Is the DNS configuration for your domains managed by Amazon Route 53 (y/n)? ")
use_route53 = answer.lower() == 'y'
hosted_zones = get_hosted_zones(route53_client) if use_route53 else []
if use_route53:
print("Adding or updating Route 53 TXT records for your domains.")
domain_zones = find_domain_zone_matches(dest_domain_tokens.keys(), hosted_zones)
for domain in domain_zones:
add_route53_verification_record(
domain, dest_domain_tokens[domain], domain_zones[domain],
route53_client)
else:
print("Use these verification tokens to create TXT records through your DNS "
"provider:")
pprint(dest_domain_tokens)
answer = input("Do you want to configure DKIM signing for your identities (y/n)? ")
if answer.lower() == 'y':
# Build a set of unique domains from email and domain identities.
domains = {email.split('@')[1] for email in dest_emails}
domains.update(dest_domain_tokens)
domain_zones = find_domain_zone_matches(domains, hosted_zones)
for domain, zone in domain_zones.items():
answer = input(
f"Do you want to configure DKIM signing for {domain} (y/n)? ")
if answer.lower() == 'y':
dkim_tokens = generate_dkim_tokens(domain, destination_client)
if use_route53 and zone is not None:
add_dkim_domain_tokens(zone, domain, dkim_tokens, route53_client)
else:
print(
"Add the following DKIM tokens as CNAME records through your "
"DNS provider:")
print(*dkim_tokens, sep='\n')
answer = input(
"Do you want to configure Amazon SNS notifications for your identities (y/n)? ")
if answer.lower() == 'y':
for identity in dest_emails + list(dest_domain_tokens.keys()):
answer = input(
f"Do you want to configure Amazon SNS topics for {identity} (y/n)? ")
if answer.lower() == 'y':
configure_sns_topics(
identity, ['Bounce', 'Delivery', 'Complaint'], destination_client)
print(f"Replication complete for {destination_client.meta.region_name}.")
print('-'*88)