Skip to main content
This is the advanced guide for AWS Lambda. If you’re just getting started, check out the Quickstart Guide first.
This guide covers advanced patterns for sending emails from AWS Lambda, including deployment strategies, event triggers, monitoring, and production best practices.

Using Raw Fetch API

If you prefer not to add the SDK dependency, use the native fetch API:

Node.js

Python

Using AWS Secrets Manager

For production deployments, store your API key in AWS Secrets Manager instead of environment variables:
1

Create a secret

2

Grant Lambda permission

Add the secretsmanager:GetSecretValue permission to your Lambda execution role:
3

Update your function code

Retrieve the secret at runtime:
Cache the Lettr client instance across invocations to avoid fetching the secret on every request. Lambda containers are reused, so the cached client will persist between invocations.

Deployment Strategies

Using Lambda Layers

Create a Lambda Layer to share the Lettr SDK across multiple functions:
1

Create the layer directory

2

Package and upload

3

Attach to your function

Using Container Images

Deploy Lambda functions as container images for more control:
Build and deploy:

Event Triggers

API Gateway Integration

Connect your Lambda function to API Gateway for HTTP-triggered emails:

EventBridge Integration

Trigger emails from EventBridge events:

SQS Integration

Process email requests from an SQS queue for reliable, async sending:

Monitoring and Logging

CloudWatch Logs

Lambda automatically sends logs to CloudWatch. Structure your logs for easy searching:

CloudWatch Metrics

Create custom metrics for email sending:

Troubleshooting

Lambda cold starts can add 1-3 seconds to the first invocation. Optimize by:
  1. Using Provisioned Concurrency for predictable latency
  2. Minimizing dependencies — use native fetch instead of axios
  3. Caching clients outside the handler function
If emails fail to send before the function times out:
  1. Increase timeout to 30 seconds (default is 3 seconds)
  2. Use async processing — send to SQS and process in a separate function
  3. Check for network issues — ensure Lambda has internet access
If you see 401 Unauthorized errors:
  • Verify your API key is correctly set in environment variables
  • Check that the key starts with lttr_ and is 68 characters total
  • Ensure the key hasn’t been deleted or revoked in the Lettr dashboard
If you’re sending high volumes, you may hit rate limits. Use exponential backoff:
If you consistently hit rate limits, consider upgrading your Lettr plan or implementing a queue-based architecture with SQS to smooth out bursts.
If you have issues retrieving secrets:
  1. Verify IAM permissions — ensure secretsmanager:GetSecretValue is granted
  2. Check secret name — it must match exactly
  3. Verify region — Secrets Manager is region-specific
  4. Cache the client — avoid fetching on every invocation

Best Practices

  1. Use environment variables for configuration (API key, from email, etc.)
  2. Cache the Lettr client outside the handler to improve performance
  3. Set appropriate timeouts — 10-30 seconds for email sending functions
  4. Implement proper error handling — distinguish between retryable and permanent errors
  5. Log request IDs for debugging and tracking delivery
  6. Use IAM roles with least privilege permissions
  7. Enable X-Ray tracing for performance monitoring
  8. Consider SQS for high-volume or batch sending

What’s Next

Quickstart Guide

Back to quickstart

Vercel Functions

Deploy on Vercel

Cloudflare Workers

Deploy on Cloudflare

Webhooks

Track delivery with webhooks