-
Notifications
You must be signed in to change notification settings - Fork 0
/
ses_identity.py
66 lines (57 loc) · 2.16 KB
/
ses_identity.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
def create_verify_domain(domain, sesv2, route53):
# Adds a domain to the list of identities for your Amazon SES account in the current AWS Region and attempts to verify it.
try:
domain_details = sesv2.create_email_identity(
EmailIdentity=domain,
)
tokens = domain_details["DkimAttributes"]["Tokens"]
response = create_resoruce_records(route53, domain, tokens)
return response
except:
response = {"status": "failed", "message": "Whoofps!! Domain already created."}
return response
def create_resoruce_records(route53, domain, tokens):
for toke in tokens:
response = route53.change_resource_record_sets(
HostedZoneId="hostedzone",
ChangeBatch={
"Changes": [
{
"Action": "CREATE",
"ResourceRecordSet": {
"Name": f"{toke}._domainkey.{domain}",
"ResourceRecords": [
{"Value": f"{toke}.dkim.amazonses.com"},
],
"TTL": 60,
"Type": "CNAME",
},
},
]
},
)
response = {"status": "success", "data": tokens}
return response
def delete_resource(route53, domain, tokens):
# del resourse record
for toke in tokens:
response = route53.change_resource_record_sets(
HostedZoneId="hostedzone",
ChangeBatch={
"Changes": [
{
"Action": "DELETE",
"ResourceRecordSet": {
"Name": f"{toke}._domainkey.{domain}",
"ResourceRecords": [
{"Value": f"{toke}.dkim.amazonses.com"},
],
"TTL": 60,
"Type": "CNAME",
},
},
]
},
)
def delete_identity(ses, domain):
ses.delete_identity(Identity=domain)