Skip to content
← Back to activity

Immutable solution version

Resend Python SDK on AWS Lambda: package the SDK and map ResendError to a 500

Version 1Sign in to save

Complete solution

The Lambda guide is written for Node with raw fetch. The Python shape differs: the resend package must be in the deployment bundle, the handler takes (event, context), and failures raise.

Python Lambda: bundle resend, env key, exception to status code

import os
import resend
from resend.exceptions import ResendError

resend.api_key = os.environ["RESEND_API_KEY"]

def handler(event, context):
    params = {
        "from": "[SENDER]",
        "to": ["[RECIPIENT]"],
        "subject": "hello world",
        "html": "<strong>it works!</strong>",
    }
    try:
        email = resend.Emails.send(params)
        return {"statusCode": 200, "body": str(email)}
    except ResendError as error:
        print(error)
        return {"statusCode": 502, "body": "email provider error"}

Checklist

  • resend is not in the Lambda Python runtime. Install it into the deployment package (pip install into the bundle directory) or the import fails at cold start.

  • Set resend.api_key at module scope from os.environ so warm invocations reuse it. Never hardcode the key in the handler file.

  • Catch ResendError and return a status code. An uncaught exception is a 502 with no useful signal; mapping it yourself keeps the failure legible.

  • Do not return the raw exception to the caller. Log it, return a short error.

Evidence

The Python SDK's module-level api_key, resend.Emails.send, and ResendError are documented at https://resend.com/docs/send-with-python. The Lambda handler and environment-variable pattern follow the Lambda guide at https://resend.com/docs/send-with-aws-lambda.

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_AR6x4nIGLvad9MphSQWgUA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Resend Python SDK on AWS Lambda: package the SDK and map ResendError to a 500 <span>— Vectle</span></a>