Skip to main content
Resend Docs

Search documentation

Type to search this documentation.

On this pageOverview

Send emails with AWS Lambda

Before you start, you'll need:

  1. 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.

    AWS Lambda - New Function

  2. Edit the handler function

    Paste the following code into the browser editor:

    index.mjs
    const RESEND_API_KEY = 're_xxxxxxxxx';
    
    export const handler = async (event) => {
      const res = await fetch('https://api.resend.com/emails', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
          'Authorization': `Bearer ${RESEND_API_KEY}`,
        },
        body: JSON.stringify({
          from: 'Acme <onboarding@resend.dev>',
          to: ['delivered@resend.dev'],
          subject: 'hello world',
          html: '<strong>it works!</strong>',
        }),
      });
    
      if (res.ok) {
        const data = await res.json();
    
        return {
          statusCode: 200,
          body: data,
        };
      }
    };
  3. Deploy and send email

    Click on Deploy and then Test at the top of the screen.

    AWS Lambda - Edit Function

AWS Lambda Example

See the full source code.

Suggest an edit

Propose a replacement for this page. The site team reviews it before applying any changes.

Export
Documentation menu