# Python Lambda: bundle resend, env key, exception to status code
```python
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.