AWS Lambda Transactional Email API (2026): Send a Payment Receipt with POST /emails
Send transactional email from an on-demand AWS Lambda (HTTP or app event, not a scheduler) with Rovela’s HTTP API: environment variables for the Bearer key, native fetch, and Idempotency-Key. Distinct from EventBridge Scheduler and Cognito guides.
AWS Lambda is already on-demand; transactional email belongs in the handler
A Lambda function already runs in a short-lived environment you control: environment variables hold secrets, the handler receives an HTTP request or an event your application published, and nothing from that process is shipped to a browser. Transactional email — “we issued your payment receipt,” a booking confirmation, a security notice — is that kind of work. The natural way to send it is one HTTPS POST with a Bearer key, not a mailbox SMTP session hanging off a long-lived process.
Rovela’s Email API is built for that. There is no client library to install and no official Lambda layer you have to pin. The base URL is https://api.rovela.dev. You authenticate with Authorization: Bearer re_… (Authentication) and queue a message with POST /emails. The response is a message id. HTTP 200 means the message was accepted and queued, not that it has already arrived (Quick Start).
This is not a scheduler tour and it is not a Cognito customization. Scheduled windows already live in the EventBridge Scheduler email guide; Cognito’s custom-email path is covered separately in AWS Cognito custom email. This article is an on-demand function: an HTTP API or function URL, or an event your own application emits after a payment is captured, posting a receipt with an Idempotency-Key. The trigger is “this payment just happened,” not “it is 9:00 again.”
If you are still choosing between HTTP and SMTP, read Email API vs SMTP. Rovela’s SMTP is mailbox SMTP for mail apps (mx.rovela.dev:465, a device credential, send-as-self, 30 messages a minute from one client address). Programmatic volume from a Lambda handler belongs on POST /emails.
What you need before the first Lambda send
The first-email guide and the Quick Start are the same five steps, whether your caller is curl or fetch inside a Lambda handler:
- Create an account. You start on the free plan, which sends real mail. There is no separate sandbox or test key.
- Add and verify a sending domain (a subdomain such as
mail.example.comis a common choice). You cannot send from a domain you have not verified; an unverified or foreignfromis refused with a 400 that names the domain. See the domain setup guide and what domain email is. - Create an API key. A
sending_accesskey can send and nothing else — the right default for production. Afull_accesskey can also read messages and events, and manage domains, templates, and webhooks. The full key is shown once. - Send with
POST /emails. - Confirm delivery in the dashboard, with
GET /emails/:idorGET /emails/:id/events(those reads needfull_accessor a dashboard session), or with a webhook.
from is a string in the documented form "Acme <hello@yourdomain.com>". The address must sit on a verified sending domain. That is the same rule that makes domain email trustworthy: you prove you control the domain before you speak as it. How the display name and the address work is covered in the From name guide.
At least one of html, text, or template is required. Send both html and text where you can — many clients preview the text part (HTML email API).
Environment variables and a small emails helper
Keep the key in the function’s environment, or in the secrets mechanism your organization already uses to populate that environment at deploy time. Never put it in the function bundle as a literal, never log it, and never return it from the handler. A leaked sending_access key can send mail as your domain.
A current Node.js Lambda runtime already has fetch. You do not need a second HTTP client just to send mail. The JSON body and headers are the same ones the Emails API documents.
// emails.mjs
export class ApiError extends Error {
constructor({ statusCode, name, message }) {
super(message || `Rovela: HTTP ${statusCode}`)
this.statusCode = statusCode
this.name = name || 'ApiError'
}
}
export async function sendEmail({ to, subject, html, text, replyTo, tags, idempotencyKey }) {
const apiKey = process.env.ROVELA_API_KEY
const from = process.env.ROVELA_FROM
if (!apiKey || !from) {
throw new Error('Missing ROVELA_API_KEY or ROVELA_FROM')
}
const headers = {
Authorization: `Bearer ${apiKey}`,
'Content-Type': 'application/json',
}
if (idempotencyKey) {
headers['Idempotency-Key'] = idempotencyKey
}
const body = { from, to, subject }
if (html) body.html = html
if (text) body.text = text
if (replyTo) body.reply_to = replyTo
if (tags) body.tags = tags
const res = await fetch('https://api.rovela.dev/emails', {
method: 'POST',
headers,
body: JSON.stringify(body),
})
const payload = await res.json().catch(() => ({}))
if (!res.ok) {
throw new ApiError({
statusCode: Number(payload.statusCode || res.status),
name: payload.name,
message: payload.message,
})
}
return payload
}
Set ROVELA_API_KEY and ROVELA_FROM on the function (for example Acme <hello@mail.example.com>). Prefer a sending_access key in the production function. Keep full_access out of this handler — you do not need it to queue a receipt.
A handler that sends after a payment is captured
A payment receipt is a good everyday example because it is not a login code and it is easy to double-send: your billing service retries, the HTTP client times out and repeats, two workers see the same payment event. Give every receipt a stable Idempotency-Key. An Idempotency-Key may be up to 256 characters; a retry of the same request within 24 hours returns the original response instead of sending again.
The handler below accepts an HTTP payload (API Gateway or a function URL) or a simple application event with a paymentId. It is the same function either way. What it is not: a cron expression, a scheduled EventBridge rule, or a “run every hour” tour.
// index.mjs
import { sendEmail, ApiError } from './emails.mjs'
function readPaymentId(event) {
if (event?.paymentId) return String(event.paymentId)
if (event?.detail?.paymentId) return String(event.detail.paymentId)
if (typeof event?.body === 'string') {
const body = JSON.parse(event.body || '{}')
return String(body.paymentId || '')
}
if (event?.body && typeof event.body === 'object') {
return String(event.body.paymentId || '')
}
return ''
}
export async function handler(event) {
const paymentId = readPaymentId(event)
if (!paymentId) {
return { statusCode: 400, body: JSON.stringify({ error: 'Missing payment' }) }
}
const payment = await loadCapturedPayment(paymentId)
const receiptUrl = signedReceiptUrl(payment)
try {
const result = await sendEmail({
to: payment.customerEmail,
subject: 'Your payment receipt',
html: `<p>We received payment ${payment.number}.</p><p><a href="${receiptUrl}">Download receipt</a></p>`,
text: `We received payment ${payment.number}. Download your receipt: ${receiptUrl}`,
tags: { purpose: 'payment-receipt', payment_id: paymentId },
idempotencyKey: `payment-receipt:${paymentId}`,
})
return { statusCode: 200, body: JSON.stringify({ ok: true, emailId: result.id }) }
} catch (err) {
if (err instanceof ApiError) {
return {
statusCode: 502,
body: JSON.stringify({ error: err.message, statusCode: err.statusCode }),
}
}
throw err
}
}
If this function is reachable over HTTP, authenticate the caller yourself — a signed header from your billing service, a private API, or an IAM-authorized function URL. The Emails API is called from your Lambda, not from a browser. A checkout page should post to your own endpoint only if that path already requires a session or a service identity; it must never call api.rovela.dev with a key the client can see.
loadCapturedPayment and signedReceiptUrl are your domain code. This article does not invent a Rovela payments endpoint — Rovela accepts the message you already decided to send.
If you later need many personalized messages in one go, use batch (POST /emails/batch, up to 100 messages, each processed independently). template and topic_id are rejected on batch rather than ignored; send those through POST /emails.
Errors you should handle in the helper
Every documented error uses the same envelope, so one ApiError covers them (Quick Start, Email API error handling):
{ "statusCode": 400, "name": "Bad Request", "message": "html or text body is required" }
The message says what was wrong. Surface it in your own logs as-is — without logging the API key.
400— a missing required field, a base64 attachment that does not decode, afromdomain that does not belong to your organization, atemplatethat does not exist, or more than 50 recipients on one message.401— missing or invalid credential, or asending_accesskey used to read, reschedule, or cancel a message.429— rate limit exceeded. The first-email guide notes that the rate limit is per key, and that each message in a batch counts individually. The official batch example waits onRetry-Afterwhen that header is present (and falls back to one second if it is not). This article will not invent a requests-per-second number, because the public docs do not publish one.
HTTP 200 on send is not delivery. If you need to look a message up later, GET /emails/:id and GET /emails/:id/events require a full_access key or a dashboard session — do not put that key in the same function that sends every receipt. Managing sending domains is a different API and a different key scope (Domains API, Email API authentication, sending domains API). A sending_access key used on a management endpoint such as GET /domains is documented as 403; that is not the same as a failed send.
Lambda timeouts are not a reason to skip the idempotency header. If the function is retried because the first invocation timed out after Rovela had already accepted the message, the same payment-receipt:${paymentId} key returns the original id instead of a second receipt.
Delivery is asynchronous — do not poll from the handler
The handler should record the message id and return. Confirm delivery in the dashboard, with the Email delivery status API, or with a webhook. For production, prefer a webhook over polling GET /emails/:id from the invoke path.
A webhook endpoint can be a second Lambda or any HTTPS URL you control that reads the raw body, verifies x-resend-signature, and returns 2xx quickly. Verification is byte-exact HMAC-SHA256 over "<timestamp>.<raw body>" (webhook security). A 400 you return because a payload surprised you is a permanent loss; store anything you do not yet understand rather than rejecting it. Deduplicate on the event id. Managing webhook endpoints themselves is covered in the Email Webhooks API guide.
When you need a message to go out later, use scheduled_at (scheduled email). POST /emails/:id/cancel can cancel a message that has not been sent yet; reading, rescheduling, and cancelling need a full_access key or a dashboard session. Public docs do not describe a reschedule request body, so this article will not invent one. When you need many sends in one request, use batch transactional email. Reusable layouts belong in the Templates API and the templates guide.
What not to do in a Lambda codebase
Do not point Nodemailer, or any other SMTP client, at Rovela mailbox SMTP and call that your application mailer. Mailbox SMTP is for mail apps: a mailbox can send only as itself, and a single client address is limited to 30 messages a minute. That is the wrong default for app volume, which is the point of Email API vs SMTP relay as well.
Do not put a Rovela key in a public repository, in a frontend checkout bundle, or in a Lambda layer that other, less trusted functions also import. Call the API from this handler. Authentication is explicit: a browser or app bundle is readable by anyone who has it.
Do not treat this guide as a replacement for the EventBridge Scheduler article or the Cognito article. A cron window and a custom Cognito email are different jobs. This handler is for mail your product sends because a payment was captured — a receipt, not a daily digest and not a forgot-password message.
Hosted mailboxes are a different product surface. People can read and send from them in a mail app. Your Lambda should not share a device credential with someone else’s Outlook profile.
If you send on behalf of several customers from one organization, restrict a key to a single domain so a leak cannot send as somebody else (Email API for multi-tenant SaaS). Retries of a failed HTTP call should reuse the same idempotency key (Email API retries).
If you later compare providers, the documented pages include Rovela vs Amazon SES, vs Resend, vs SendGrid, vs Postmark, vs Mailgun, and vs Brevo. This article does not invent an SES integration; the Lambda here talks to Rovela over POST /emails.
A compact Lambda checklist
- Verify the sending domain before you set
from. An unverified domain is a 400, not a silent drop. - Keep
ROVELAcredentials in the function environment and never print them in logs. - Prefer a
sending_accesskey in the production receipt function; keepfull_accessfor tooling that reads events or manages webhooks. - Send both
htmlandtextwhen you can, and set anIdempotency-Keyon any path a retry can hit twice — including Lambda’s own retries. - Record the message
idand return from the handler. Watch delivery with a webhook, not a loop on the invoke path. - If you need a first request in curl, use the transactional email API overview, the curl sending guide, or the HTTP email API explainer — then come back to this handler for the Lambda shape.