Sending Template Emails with Amazon SES on AWS Emulator
You can create and send Amazon SES email templates locally with AWS Emulator, without an AWS account. This article shows how to test, in local development or testing, emails that insert a name or order number for each recipient, such as sign-up confirmation or order confirmation emails. It covers creating a template, checking the expanded form before sending, what happens when a value is missing, and bulk sending with different values per recipient. All commands and output are from my test environment.
The test environment is Ubuntu 24.04 (x86_64), AWS Emulator 1.0.624 (released November 26, 2026), AWS CLI 2.42.4, and Python 3.11. I did not use an AWS account or credentials, so I have not verified how this works on real SES, whether emails actually arrive, or the cost. Where the text touches real SES, it is based on the official documentation. I did not test inline templates (where the subject and body are written directly in the request), sending with the AWS SDK, or how HTML bodies look in email clients. Sending with the older API (aws ses) is not covered in this article.
- 1. Preparation: Start the Emulator and Register the Sender and Recipients
- 2. Create a Template
- 3. Check the Expanded Form Before Sending
- 4. Send Using a Template
- 5. If a Value Is Missing, Sending Succeeds but a Rendering Failure Comes Later
- 6. Send in Bulk with Different Values per Recipient
- 7. Templates Using each or if Cannot Be Sent in the Emulator
- 8. Update and Delete Templates
Preparation: Start the Emulator and Register the Sender and Recipients
How to install AWS Emulator is covered in a separate article, "How to Get Started with AWS Emulator on Ubuntu." In the test environment, I installed the Debian package from the Linux instructions after verifying its signature with gpg. The -t off option at startup turns off telemetry, which is usage data sent to AWS by default (telemetry).
$ aws-emulator -t off
In another terminal, set the environment variables from the official documentation and point the AWS CLI at the emulator.
export AWS_ENDPOINT_URL=https://127.0.0.1:9297
export AWS_SHARED_CREDENTIALS_FILE=~/.aws/emulator/9297/emulator_credentials
export AWS_CONFIG_FILE=~/.aws/emulator/9297/config
export AWS_CA_BUNDLE=~/.aws/emulator/9297/ca.pem
export AWS_EC2_METADATA_DISABLED=true
export AWS_DISABLE_HOST_PREFIX_INJECTION=true
export AWS_REGION=us-east-1
export AWS_DEFAULT_REGION=us-east-1
unset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN AWS_PROFILE
To send with SES, the sender address must be registered as an identity and verified. In the emulator, the status became SUCCESS after waiting, without opening the link in the confirmation email (all five addresses reached SUCCESS in 4 seconds). This flow and sending without templates are covered in detail in a separate article, "How to Try Sending Email with SES on AWS Emulator." In this article, I registered the sender sender@example.com and the recipients a@example.com through d@example.com.
$ aws sesv2 create-email-identity --email-identity sender@example.com --query IdentityType --output text
EMAIL_ADDRESS
(a@example.com〜d@example.com も同じように作成)
$ s=$(date +%s); for a in sender@example.com a@example.com b@example.com c@example.com d@example.com; do for i in $(seq 30); do st=$(aws sesv2 get-email-identity --email-identity $a --query VerificationStatus --output text); [ "$st" = SUCCESS ] && break; sleep 1; done; echo "$a $st"; done; echo "$(( $(date +%s) - s ))秒"
sender@example.com SUCCESS
a@example.com SUCCESS
b@example.com SUCCESS
c@example.com SUCCESS
d@example.com SUCCESS
4秒
Create a Template
A template contains a subject (Subject), a plain-text body (Text), and an HTML body (Html). As described in the official documentation on templates, you write placeholders such as {{name}} where values are inserted. This time I made a sign-up completion email that inserts a name and a plan.
$ cat welcome.json
{"Subject":"{{name}}さん、ようこそ","Text":"{{name}}さん、{{plan}}プランへの登録ありがとうございます。","Html":"<p>{{name}}さん、<b>{{plan}}</b>プランへの登録ありがとうございます。</p>"}
Creating a template with create-email-template shows nothing on success. You can read the saved content with get-email-template. Creating a template again with the same name returned AlreadyExistsException (to change the content, use update-email-template, described in a later section).
$ aws sesv2 create-email-template --template-name welcome --template-content file://welcome.json
$ aws sesv2 create-email-template --template-name welcome --template-content file://welcome.json
aws: [ERROR]: An error occurred (AlreadyExistsException) when calling the CreateEmailTemplate operation: Template welcome already exists for account id <12桁のアカウントID>
Check the Expanded Form Before Sending
If you pass the values to insert as JSON to test-render-email-template, it returns the form of the email that would be sent (a MIME message), as described in the TestRenderEmailTemplate API reference. You can check combinations of template and values without sending any email.
$ aws sesv2 test-render-email-template --template-name welcome --template-data '{"name":"ねこ","plan":"無料"}' --query RenderedTemplate --output text
Subject: =?UTF-8?B?44Gt44GT44GV44KT44CB44KI44GG44GT44Gd?=
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="----=_Part_d2071097-ee30-4ec4-9f27-4840cfb41980"
------=_Part_d2071097-ee30-4ec4-9f27-4840cfb41980
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
=E3=81=AD=E3=81=93=E3=81=95=E3=82=93=E3=80=81=E7=84=A1=E6=96=99=E3=83=97=E3=
(以下略)
Because I wrote both text and HTML, the result is in the multipart/alternative form, which bundles two bodies. Japanese text is converted, with the subject in Base64 and the body in quoted-printable, so the output is unreadable as is. I prepared a short script that re-reads it with Python's standard email library.
# decode.py: Reads a MIME message from standard input, then decodes and displays the subject and each part.
import sys, email
from email import policy
m = email.message_from_string(sys.stdin.read(), policy=policy.default)
print("Subject:", m["Subject"])
for p in m.walk():
if p.is_multipart(): continue
print("---", p.get_content_type())
print(p.get_content().rstrip("\n"))
When you pass the output to this script, you can see the name and plan inserted into the subject and both bodies.
$ aws sesv2 test-render-email-template --template-name welcome --template-data '{"name":"ねこ","plan":"無料"}' --query RenderedTemplate --output text | python3 decode.py
Subject: ねこさん、ようこそ
--- text/plain
ねこさん、無料プランへの登録ありがとうございます。
--- text/html
<p>ねこさん、<b>無料</b>プランへの登録ありがとうございます。</p>
Values containing <b> or & were also inserted into the HTML body as-is. The official documentation on advanced personalization also says that SES does not replace special characters (it does not escape them) when it renders an HTML template. When you insert text that a user typed, such as from an inquiry form, the sending program must escape it beforehand.
$ aws sesv2 test-render-email-template --template-name welcome --template-data '{"name":"<b>ねこ</b>","plan":"A&B"}' --query RenderedTemplate --output text | python3 decode.py
Subject: <b>ねこ</b>さん、ようこそ
--- text/plain
<b>ねこ</b>さん、A&Bプランへの登録ありがとうございます。
--- text/html
<p><b>ねこ</b>さん、<b>A&B</b>プランへの登録ありがとうございます。</p>
Send Using a Template
Put Template in the --content option of send-email, along with the template name and the values to insert. The values are passed not as raw JSON but as a string that contains the JSON, so the inner " characters become \". On success, a MessageId is returned. (The 12-digit sequence number in the middle of each MessageId has been replaced with a placeholder.)
$ aws sesv2 send-email --from-email-address sender@example.com --destination ToAddresses=a@example.com --content '{"Template":{"TemplateName":"welcome","TemplateData":"{\"name\":\"ねこ\",\"plan\":\"無料\"}"}}'
{
"MessageId": "010001a216a9e8c9-2d613b7b-53c9-e0b8-4c0b-<12桁の連番>-000000"
}
When the template name was wrong, or when the values JSON was broken, the call failed immediately with an error.
$ aws sesv2 send-email --from-email-address sender@example.com --destination ToAddresses=a@example.com --content '{"Template":{"TemplateName":"nope","TemplateData":"{}"}}'
aws: [ERROR]: An error occurred (NotFoundException) when calling the SendEmail operation: Template nope does not exist.
$ aws sesv2 send-email --from-email-address sender@example.com --destination ToAddresses=a@example.com --content '{"Template":{"TemplateName":"welcome","TemplateData":"{\"name\":}"}}'
aws: [ERROR]: An error occurred (BadRequestException) when calling the SendEmail operation: Template rendering data is invalid
If a Value Is Missing, Sending Succeeds but a Rendering Failure Comes Later
When one value to insert was missing, test-render-email-template and send-email gave different results. test-render-email-template returns an error that shows which value is missing.
$ aws sesv2 test-render-email-template --template-name welcome --template-data '{"name":"ねこ"}'
aws: [ERROR]: An error occurred (BadRequestException) when calling the TestRenderEmailTemplate operation: Attribute 'plan' is not present in the rendering data.
On the other hand, calling send-email with the same values did not return an error and returned a MessageId. The official template documentation says that an email whose inserted content is incorrect may not be delivered, even though SES accepted it. For that reason, the same page recommends receiving "Rendering Failure," one of the sending events, through a configuration set.
Preparing to Receive Events (SNS and SQS)
Event destinations are registered on a configuration set. In the test environment, I created an SNS topic and an SQS queue that subscribes to it. The 12-digit account IDs in the ARNs and the queue URL are masked with placeholders, so when you try this, use the values printed by create-topic and create-queue.
$ aws sns create-topic --name ses-events --query TopicArn --output text
arn:aws:sns:us-east-1:<12桁のアカウントID>:ses-events
$ aws sqs create-queue --queue-name ses-events --query QueueUrl --output text
https://127.0.0.1:9297/<12-digit account ID>/ses-events
To use them in the following commands, I stored the topic ARN in $T, the queue URL in $Q, and the queue ARN in $QA. The queue ARN is read with get-queue-attributes. Calling create-topic and create-queue again with the same names returned the same topic and queue.
$ T=$(aws sns create-topic --name ses-events --query TopicArn --output text)
$ Q=$(aws sqs create-queue --queue-name ses-events --query QueueUrl --output text)
$ QA=$(aws sqs get-queue-attributes --queue-url $Q --attribute-names QueueArn --query Attributes.QueueArn --output text)
Attach a policy to the queue that allows sends from this topic. The policy must be a JSON string placed in the Policy attribute, so I used Python to create attrs.json and passed it to set-queue-attributes.
$ python3 - "$T" "$QA" > attrs.json <<'PY'
import json, sys
t, q = sys.argv[1], sys.argv[2]
pol = {"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"Service":"sns.amazonaws.com"},"Action":"sqs:SendMessage","Resource":q,"Condition":{"ArnEquals":{"aws:SourceArn":t}}}]}
print(json.dumps({"Policy": json.dumps(pol)}))
PY
$ aws sqs set-queue-attributes --queue-url $Q --attributes file://attrs.json
For the subscription, I set RawMessageDelivery=true. As described in the SNS official documentation, this removes the SNS metadata, so the SES event JSON goes into the queue as-is. (The subscription ID at the end of the output has been masked.) Next, I created a configuration set and registered it to send the two event types SEND and RENDERING_FAILURE to the topic.
$ aws sns subscribe --topic-arn $T --protocol sqs --notification-endpoint $QA --attributes RawMessageDelivery=true --query SubscriptionArn --output text
arn:aws:sns:us-east-1:<12桁のアカウントID>:ses-events:<購読ID>
$ aws sesv2 create-configuration-set --configuration-set-name tpl-test
$ aws sesv2 create-configuration-set-event-destination --configuration-set-name tpl-test --event-destination-name to-sns --event-destination '{"Enabled":true,"MatchingEventTypes":["SEND","RENDERING_FAILURE"],"SnsDestination":{"TopicArn":"arn:aws:sns:us-east-1:<12桁のアカウントID>:ses-events"}}'
The following script (events.sh) receives the events that arrive in the queue. It shows each event on one line, in the order of type, recipient, MessageId, subject, and error message, and then deletes the received messages from the queue.
#!/bin/bash
# Receives all events that arrive in the SQS queue, displays each one on a single line, then deletes the received messages.
# If you add full as the second argument, Rendering Failure events show the entire JSON.
Q="$1"; MODE="$2"
while :; do
out=$(aws sqs receive-message --queue-url "$Q" --max-number-of-messages 10 --wait-time-seconds 3 --output json)
[ -z "$out" ] && break
echo "$out" | MODE="$MODE" python3 -c '
import sys, json, os
for m in json.load(sys.stdin)["Messages"]:
e = json.loads(m["Body"])
if os.environ["MODE"] == "full" and e["eventType"] == "Rendering Failure":
print(json.dumps(e, ensure_ascii=False, indent=2)); continue
subject = e["mail"]["commonHeaders"].get("subject", "(件名なし)")
error = e.get("failure", {}).get("errorMessage", "")
print(e["eventType"], e["mail"]["destination"][0], e["mail"]["messageId"], subject, error)
'
echo "$out" | python3 -c 'import sys, json; [print(m["ReceiptHandle"]) for m in json.load(sys.stdin)["Messages"]]' |
while read -r h; do aws sqs delete-message --queue-url "$Q" --receipt-handle "$h"; done
done
Events Delivered for a Send with a Missing Value
With --configuration-set-name tpl-test, I sent one email with all values present and one with plan missing.
$ aws sesv2 send-email --from-email-address sender@example.com --destination ToAddresses=a@example.com --configuration-set-name tpl-test --content '{"Template":{"TemplateName":"welcome","TemplateData":"{\"name\":\"ねこ\",\"plan\":\"無料\"}"}}'
{
"MessageId": "010001a216aa0d33-f400a844-2307-cf26-5760-<12桁の連番>-000000"
}
$ aws sesv2 send-email --from-email-address sender@example.com --destination ToAddresses=a@example.com --configuration-set-name tpl-test --content '{"Template":{"TemplateName":"welcome","TemplateData":"{\"name\":\"ねこ\"}"}}'
{
"MessageId": "010001a216aa1059-714bfc4b-4549-d065-6d1c-<12桁の連番>-000000"
}
The first email, with all values present, produced only a Send event that included the subject. The second email, with a missing value, produced a Send event without a subject, followed by a Rendering Failure event. The error message included the name of the missing value.
$ bash events.sh $Q
Send a@example.com 010001a216aa0d33-f400a844-2307-cf26-5760-<12桁の連番>-000000 ねこさん、ようこそ
Send a@example.com 010001a216aa1059-714bfc4b-4549-d065-6d1c-<12桁の連番>-000000 (件名なし)
Rendering Failure a@example.com 010001a216aa1059-714bfc4b-4549-d065-6d1c-<12桁の連番>-000000 (件名なし) Attribute 'plan' is not present in the rendering data.
In the emulator, the missing value was not visible in the send-email result. It only appeared in this event. Next, I sent an email to b@example.com with no values passed (TemplateData set to "{}").
$ aws sesv2 send-email --from-email-address sender@example.com --destination ToAddresses=b@example.com --configuration-set-name tpl-test --content '{"Template":{"TemplateName":"welcome","TemplateData":"{}"}}'
{
"MessageId": "010001a216aa39a7-2354f821-c477-8353-b377-<12桁の連番>-000000"
}
Running bash events.sh $Q full displayed the full JSON of the Rendering Failure event. The next block shows only the failure part at the end. As in the official documentation on event contents, it contained templateName and errorMessage.
"failure": {
"templateName": "welcome",
"errorMessage": "Attribute 'name' is not present in the rendering data."
}
Send in Bulk with Different Values per Recipient
send-bulk-email lets you send to multiple recipients in one call, inserting different values for each recipient. According to the official documentation, the real SES accepts up to 50 destinations (Destination) in one call. Put the default values in --default-content, and the per-recipient values in ReplacementTemplateData. This time I listed four destinations.
$ cat bulk.json
[
{"Destination":{"ToAddresses":["a@example.com"]},
"ReplacementEmailContent":{"ReplacementTemplate":{"ReplacementTemplateData":"{\"name\":\"たま\",\"plan\":\"有料\"}"}}},
{"Destination":{"ToAddresses":["b@example.com"]},
"ReplacementEmailContent":{"ReplacementTemplate":{"ReplacementTemplateData":"{}"}}},
{"Destination":{"ToAddresses":["c@example.com"]}},
{"Destination":{"ToAddresses":["d@example.com"]},
"ReplacementEmailContent":{"ReplacementTemplate":{"ReplacementTemplateData":"{\"name\":"}}}
]
For a@example.com I passed values for that recipient, and for b@example.com I passed an empty {}. For c@example.com I did not write per-recipient values. The values for d@example.com are deliberately broken JSON.
$ aws sesv2 send-bulk-email --from-email-address sender@example.com --default-content '{"Template":{"TemplateName":"welcome","TemplateData":"{\"name\":\"お客\",\"plan\":\"無料\"}"}}' --configuration-set-name tpl-test --bulk-email-entries file://bulk.json
{
"BulkEmailEntryResults": [
{
"Status": "SUCCESS",
"MessageId": "010001a216aa5f14-1117797b-cc8a-7641-3c19-<12桁の連番>-000000"
},
{
"Status": "SUCCESS",
"MessageId": "010001a216aa5f14-c23130e0-df11-4567-c4b6-<12桁の連番>-000000"
},
{
"Status": "SUCCESS",
"MessageId": "010001a216aa5f14-614773c9-d604-29ca-ed4e-<12桁の連番>-000000"
},
{
"Status": "INVALID_PARAMETER",
"Error": "Template rendering data is invalid"
}
]
}
In the emulator, results were returned per destination, in the order listed. Only the destination with broken JSON returned INVALID_PARAMETER; the other three were accepted. I checked the events that arrived in the queue with the events.sh script above.
$ bash events.sh $Q
Send b@example.com 010001a216aa5f14-c23130e0-df11-4567-c4b6-<12桁の連番>-000000 (件名なし)
Send a@example.com 010001a216aa5f14-1117797b-cc8a-7641-3c19-<12桁の連番>-000000 たまさん、ようこそ
Rendering Failure b@example.com 010001a216aa5f14-c23130e0-df11-4567-c4b6-<12桁の連番>-000000 (件名なし) Attribute 'name' is not present in the rendering data.
Send c@example.com 010001a216aa5f14-614773c9-d604-29ca-ed4e-<12桁の連番>-000000 お客さん、ようこそ
Looking at the subjects: a@example.com received the values written for it, and c@example.com, which had no per-recipient values, received the default values. The point to watch is b@example.com. The official template documentation says that if ReplacementTemplateData is an empty {}, the default values (TemplateData in DefaultContent) are used. In the emulator, the default values were not used. The destination was treated as having no values, and it produced a Rendering Failure.
The emulator's public source code for bulk sending (send_bulk_email.rs) also uses the default values only when ReplacementTemplateData is omitted. (I read the latest commit in the repository, which is different from the 1.0.624 I installed.) If you want the emulator to use the default values, do not write per-recipient values at all, as with c@example.com.
Templates Using each or if Cannot Be Sent in the Emulator
According to the official documentation on advanced personalization, saved templates can use Handlebars syntax. This includes nested values such as {{order.id}}, repetition with {{#each}}, conditional branches with {{#if}}, and inline partials. I made a template that lists the items in an order and adds a line only when there is a coupon.
$ cat order.json
{"Subject":"ご注文番号 {{order.id}}","Text":"{{#each order.items}}- {{this}}\n{{/each}}{{#if coupon}}クーポン {{coupon}} を使いました。{{/if}}"}
With test-render-email-template, the items were listed one per line, and the coupon line did not appear when there was no coupon.
$ aws sesv2 test-render-email-template --template-name order --template-data '{"order":{"id":"A-1001","items":["かつおぶし","ねこじゃらし"]},"coupon":"NEKO10"}' --query RenderedTemplate --output text | python3 decode.py
Subject: ご注文番号 A-1001
--- text/plain
- かつおぶし
- ねこじゃらし
クーポン NEKO10 を使いました。
$ aws sesv2 test-render-email-template --template-name order --template-data '{"order":{"id":"A-1002","items":["かつおぶし"]}}' --query RenderedTemplate --output text | python3 decode.py
Subject: ご注文番号 A-1002
--- text/plain
- かつおぶし
However, calling send-email or send-bulk-email with this template was refused with NotImplemented. The error says that sending with a template that uses a section ({{#each}} or {{#if}}), a partial, or a helper is scaffolded but not implemented in this emulator.
$ aws sesv2 send-email --from-email-address sender@example.com --destination ToAddresses=a@example.com --content '{"Template":{"TemplateName":"order","TemplateData":"{\"order\":{\"id\":\"A-1001\",\"items\":[\"かつおぶし\"]}}"}}'
aws: [ERROR]: An error occurred (NotImplemented) when calling the SendEmail operation: operation SendEmail with a template that uses a section, a partial or a helper call is scaffolded but not implemented in this emulator
In the emulator, you can test sending only with templates that insert values directly, such as {{name}}.
Update and Delete Templates
update-email-template replaces the entire content. This time I removed the HTML body and changed the word order of the subject.
$ aws sesv2 update-email-template --template-name welcome --template-content '{"Subject":"ようこそ、{{name}}さん","Text":"{{name}}さん、登録ありがとうございます。"}'
$ aws sesv2 get-email-template --template-name welcome --query TemplateContent
{
"Subject": "ようこそ、{{name}}さん",
"Text": "{{name}}さん、登録ありがとうございます。"
}
Delete templates you no longer use with delete-email-template. Reading the template with get-email-template after deleting it returned NotFoundException.
$ aws sesv2 delete-email-template --template-name order
$ aws sesv2 get-email-template --template-name order
aws: [ERROR]: An error occurred (NotFoundException) when calling the GetEmailTemplate operation: Template order does not exist.
When you check templates in the emulator, view the inserted result with test-render-email-template. Check the sending result with the MessageId, and with the Send and Rendering Failure events received through the configuration set.




