Created
November 1, 2023 14:19
-
-
Save L422Y/34186b77d73de59fee80f4535923cac5 to your computer and use it in GitHub Desktop.
Setup Amazon SES and DKIM verification with Route53
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# example: ./setup-ses-route53.sh <hosted-zone-id> <domain> | |
# Check if the correct number of arguments are provided | |
if [[ "$#" -ne 2 ]]; then | |
echo "Usage: $0 <hosted-zone-id> <domain>" | |
exit 1 | |
fi | |
HOSTED_ZONE_ID=$1 | |
DOMAIN=$2 | |
# Verify domain | |
aws ses verify-domain-identity --domain $DOMAIN | |
# Get DKIM setup information | |
DKIM_TOKENS=$(aws ses verify-domain-dkim --domain $DOMAIN --query 'DkimTokens' --output text) | |
# Iterate over the DKIM tokens and create CNAME records in Route 53 | |
for TOKEN in $DKIM_TOKENS; do | |
aws route53 change-resource-record-sets --hosted-zone-id $HOSTED_ZONE_ID --change-batch "{ | |
\"Changes\": [ | |
{ | |
\"Action\": \"UPSERT\", | |
\"ResourceRecordSet\": { | |
\"Name\": \"$TOKEN._domainkey.$DOMAIN\", | |
\"Type\": \"CNAME\", | |
\"TTL\": 300, | |
\"ResourceRecords\": [{\"Value\": \"$TOKEN.dkim.amazonses.com\"}] | |
} | |
} | |
] | |
}" | |
done | |
echo "Domain verification and DKIM setup complete." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment