Skip to content

Instantly share code, notes, and snippets.

@L422Y
Created November 1, 2023 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save L422Y/34186b77d73de59fee80f4535923cac5 to your computer and use it in GitHub Desktop.
Save L422Y/34186b77d73de59fee80f4535923cac5 to your computer and use it in GitHub Desktop.
Setup Amazon SES and DKIM verification with Route53
#!/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