Technical
Lambda Functions: Your First Serverless Deployment
You have read about serverless. You understand the concept. But you have never deployed a Lambda function to AWS. The gap between theory and your first deployment is smaller than you think. Here is how to do it in 20 minutes.
What a Lambda Function Is
A Lambda function is a piece of code that runs when triggered by an event. No server setup, no process management, no scaling configuration. You upload your code, define a trigger, and AWS handles everything else.
Your First Function
The simplest Lambda function is a Python file with a handler:
def handler(event, context):
name = event.get('queryStringParameters', {}).get('name', 'World')
return {
'statusCode': 200,
'headers': {'Content-Type': 'application/json'},
'body': json.dumps({'message': f'Hello, {name}!'})
}That is a complete HTTP endpoint. The event parameter contains the request data (headers, query parameters, body). The context parameter has metadata about the execution environment.
Deploying with SAM
AWS SAM (Serverless Application Model) is the simplest deployment tool:
# template.yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
HelloFunction:
Type: AWS::Serverless::Function
Properties:
Handler: app.handler
Runtime: python3.12
Events:
HelloAPI:
Type: Api
Properties:
Path: /hello
Method: getsam build
sam deploy --guidedSAM creates the Lambda function, sets up API Gateway, configures permissions, and gives you a public URL. Two commands.
Free Tier Limits
AWS Lambda free tier gives you:
- 1 million requests per month
- 400,000 GB-seconds of compute time per month
For context, a typical API request takes 100-500ms with 128MB memory. That is roughly 800,000 to 3.2 million requests per month within the free tier. More than enough for a blog, a portfolio, or a small SaaS.
Cold Starts: The Tradeoff
The one downside of Lambda is cold starts. When a function has not been called recently, the first invocation takes 1-3 seconds to initialize. Subsequent calls are fast (under 100ms).
Mitigation strategies:
- Use smaller deployment packages (less code to load)
- Choose Python or Node.js over Java (faster cold starts)
- Use provisioned concurrency for critical endpoints (costs money)
- Accept 1-2 second cold starts for non-critical endpoints (free)
What You Build Next
Once you have deployed your first function, the pattern repeats:
- Add a POST endpoint for form submissions
- Add DynamoDB for data storage
- Add SES for sending emails
- Add scheduled events for cron jobs
Each addition is a few lines of SAM configuration. The architecture scales without changing the deployment pattern.
See the AWS SAM documentation for the complete deployment guide.
RELATED READING
The Consulting Shift I Am Making In Year Two
After a year of writing and building, my consulting practice is changing shape. Shorter engagements. Sharper outcomes.
ReadThe Frontend Shift: Shipping Less JavaScript In Year Two
A year ago I reached for Next.js for everything. This year I often reach for nothing.
ReadThe Serverless Lesson I Would Write On A Sticky Note
After a year of shipping serverless projects, one rule explains most of the wins and all of the losses.
Read