AWS Learning Journey

No Servers, No Problem? AWS Lambda and the Serverless Toolkit

Lambda functions, layers, concurrency, and event sources — plus API Gateway, Step Functions, EventBridge, SNS, SQS, dead-letter queues, and SAM. What serverless is great at, and where it bites.

9 min read · 1663 words
AWSServerlessAWS LambdaEvent Driven ArchitectureCloud Computing
No Servers, No Problem? AWS Lambda and the Serverless Toolkit cover image

AWS from Zero to Production — Phase 4, Part 5 of 6 · See the full series roadmap


Imagine a feature that resizes every image users upload.

With servers, you’d provision instances, install software, patch them, scale them for peak load, and pay for them all night while nobody uploads anything.

With serverless, you write one function. It runs when a file lands in S3, scales to thousands of uploads at once, and costs nothing when nobody’s uploading.

That’s the appeal. But serverless also has limits, quirks, and failure modes that surprise people in production. This article covers both.

What you’ll walk away with


What “serverless” really means

There are still servers. You just don’t manage them. Serverless services share four traits:


AWS Lambda

AWS Lambda runs your code in response to events. You upload a function; AWS runs it when triggered.

import json

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}!"}),
    }

Key limits and settings

Execution roles

Every function has an execution role — the IAM role it assumes when it runs. At minimum, it needs permission to write logs to CloudWatch. Add exactly what the function calls, nothing more.

Environment variables

Use them for configuration: table names, feature flags, and endpoints. For secrets, store a reference and fetch the value from Secrets Manager or Parameter Store at runtime — or use the AWS Parameters and Secrets Lambda Extension, which caches them.

Layers

A layer is a ZIP archive of libraries or shared code that multiple functions can use. A function can use up to five layers. They keep deployment packages small and share common dependencies.


Versions and aliases

Triggers and clients call the alias. To release, point the alias at a new version. To roll back, point it back.

Aliases also support weighted routing, for example 90% to version 7 and 10% to version 8 — a built-in canary release.


Concurrency: how Lambda scales

Concurrency is the number of requests your functions are handling at the same moment. Each concurrent request runs in its own execution environment.

Cold starts

When Lambda creates a new execution environment, it downloads your code and runs initialization code. That’s a cold start. It adds latency to that request.

Reduce it by:

Watch out: Lambda can scale far faster than a relational database can accept connections. A burst of 1,000 concurrent functions each opening a connection can overwhelm the database. Use RDS Proxy (Phase 5), reserved concurrency, or a queue in between.


How Lambda gets invoked

Event source mappings in practice

SQS queue  --->  Lambda polls  --->  function gets a batch of up to N messages
                                     success -> messages deleted
                                     failure -> messages return to the queue

Enable partial batch responses, so one bad message doesn’t force the whole batch to be retried.


Amazon API Gateway

API Gateway puts an HTTPS API in front of Lambda functions and other backends.

API Gateway handles throttling, authorization, and custom domains with ACM certificates.


AWS Step Functions

Step Functions coordinates multi-step workflows as state machines: run this, then that; retry on failure; branch; wait; run in parallel.

Order received
   |
   v
Validate payment ----(fails)----> Notify customer
   |
   v
Reserve stock (retry 3x with backoff)
   |
   v
Parallel: send email | update analytics
   |
   v
Done

Step Functions can call over 200 AWS services directly, often with no Lambda in between.


Amazon EventBridge

EventBridge is a serverless event bus. Services publish events; rules match them and route them to targets.

{
  "source": ["myapp.orders"],
  "detail-type": ["OrderPlaced"],
  "detail": { "total": [{ "numeric": [">", 1000] }] }
}

This rule matches only orders over 1,000 — and can send them to Lambda, Step Functions, SQS, or many other targets.

Phase 10 goes deep on event-driven design.


Amazon SNS and Amazon SQS

SNS — publish and subscribe

Amazon Simple Notification Service pushes each message to all subscribers: Lambda functions, SQS queues, HTTP endpoints, email, or SMS. One event, many reactions.

SQS — queues

Amazon Simple Queue Service stores messages until a consumer processes them. It decouples producers from consumers and absorbs bursts.

The fan-out pattern

               +--> SQS queue --> billing service
SNS topic -----+--> SQS queue --> email service
               +--> SQS queue --> analytics service

Each service gets its own queue, processes at its own pace, and fails independently.


Dead-letter queues

Some messages will always fail: bad data, a bug, a missing record. Without a plan, they retry forever or vanish.

A dead-letter queue (DLQ) catches messages that fail too many times:

Rule: Every queue and asynchronous function in production should have a DLQ — and an alarm on it.


AWS Serverless Application Model (SAM)

SAM is an extension of CloudFormation with short syntax for serverless resources, plus a CLI for building, testing locally, and deploying.

AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31

Resources:
  HelloFunction:
    Type: AWS::Serverless::Function
    Properties:
      Runtime: python3.12
      Handler: app.handler
      CodeUri: src/
      MemorySize: 256
      Timeout: 10
      Events:
        Api:
          Type: HttpApi
          Properties:
            Path: /hello
            Method: get
sam build
sam local invoke HelloFunction
sam deploy --guided

Phase 6 covers CloudFormation, which SAM builds on.


When serverless is — and isn’t — a good fit

Great for

Think twice for


Common mistakes


Key takeaways


Quick self-check

Test yourself before moving on:

  1. What’s the maximum Lambda timeout?
  2. How do you release a new Lambda version with instant rollback?
  3. A message keeps getting processed twice. What SQS setting should you check first?
  4. Where do messages go after failing maxReceiveCount times?

Answers

  1. 15 minutes.
  2. Publish a version and point an alias at it; roll back by pointing the alias back.
  3. The visibility timeout — it may be shorter than the processing time. And make the consumer idempotent.
  4. To the dead-letter queue.

What’s next

In Part 6, the Phase 4 lab: containerize an API, push it to Amazon ECR, and run it on ECS Fargate in private subnets behind an Application Load Balancer — then ship a second version with zero downtime.

Serverless fan or skeptic? Make your case in the comments.


Share this article

LinkedIn post draft