Quick setup examples

AWS Lambda

Send your first email from an AWS Lambda function using the sendping SDK.

Send your first email from an AWS Lambda function using the sendping Node SDK. Bundle the SDK into your Lambda deployment package with your preferred bundler (esbuild, webpack, etc.) or a Lambda Layer.

Prerequisites

Before you start, you will need:

1. Install the SDK

npm install sendping

2. Create an AWS Lambda function

Go to aws.amazon.com and create a new Lambda function using the Node.js 20.x (or later) runtime.

3. Store your API key

Under the function's Configuration → Environment variables, add SENDPING_API_KEY with your key. Reading it from the environment keeps the secret out of source.

Environment variable
SENDPING_API_KEY=mb_xxxxxxxxx

4. Edit the handler function

Use the SDK client in your handler. It returns { data, error } — no try/catch needed for HTTP errors.

index.mjs
import { SendPing } from 'sendping';

const mb = new SendPing(process.env.SENDPING_API_KEY);

export const handler = async (event) => {
  const { data, error } = await mb.emails.send({
    from: 'Acme <onboarding@yourdomain.com>',
    to: ['delivered@test.sendping.co'],
    subject: 'hello world',
    html: '<strong>it works!</strong>',
  });

  return {
    statusCode: error ? 500 : 200,
    body: JSON.stringify(error ? { error } : { data }),
  };
};

5. Deploy and send email

Click Deploy, then Test at the top of the screen. A successful run returns the created email's id.

See the full request body — cc, bcc, reply_to, attachments, scheduled_at — in the Send an email reference.