sendsend.email

Send email with AWS Lambda

A server-side call to the SendSend API from your AWS Lambda app.

  1. Create a test API key in the dashboard first: it never delivers real email. Switch to a live key once your domain is verified.
  2. Add SENDSEND_API_KEY as an environment variable on the function, or better, read it from AWS Secrets Manager.
  3. Add this to index.mjs:
export const handler = async (event) => {
  const { to } = JSON.parse(event.body ?? '{}');
  const res = await fetch('https://api.sendsend.email/v1/emails', {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${process.env.SENDSEND_API_KEY}`,
      'Content-Type': 'application/json',
      'Idempotency-Key': event.requestContext?.requestId ?? crypto.randomUUID(),
    },
    body: JSON.stringify({ from: 'Acme <hello@mail.acme.com>', to: [to], subject: 'Hello from Lambda', html: '<p>It works!</p>' }),
  });
  return { statusCode: res.status, body: await res.text() };
};

Using the request id as the idempotency key means a retried Lambda invocation cannot send twice.

Good to know