FreeReference architectureAWSLambda
A serverless API, request by request
In one sentence: You write the function; the cloud runs it only when a request arrives and scales it for you.
Animated diagrams are not available for printing. Get StackKinetic Pro to download this explainer.
Inspect:
Read this explainer as text
Read an item
Beginner
- You open your profile. The app asks the API for your details.
- The front desk asks the guard: is this person allowed in?
- The guard checks your badge and says yes.
- The front desk wakes up your code to handle the request.
- Your code looks up your profile.
- The database sends your profile back.
- Your code packages up the answer.
- Your profile appears. No server was sitting around waiting for you.
Practitioner
- The client calls GET /profile with a token.
- The gateway sends the token to the authorizer.
- The token is valid; the request is allowed.
- The gateway invokes the Lambda function.
- The function reads the item from DynamoDB.
- DynamoDB returns the item.
- The function returns a JSON response.
- The client receives the response.
Architect
- HTTPS request with an Authorization bearer token.
- Authorizer invoked (or the cached decision reused).
- Allow decision with the caller’s identity in the request context.
- Synchronous invoke; a warm environment is reused if one is free.
- GetItem by partition key: single-digit milliseconds.
- Item returned; consumed capacity is billed per request.
- Function returns; the environment stays warm for the next call.
- End to end, you paid only for this request’s compute and reads.
Cold start
Beginner
- The first request in a while arrives.
- Your code was asleep, so the cloud has to set it up first. That takes a moment.
- Now your code can look up the data.
- The data comes back.
- Your code answers. It stays awake for a while in case more requests arrive.
- You get your answer, just a little slower than usual.
Practitioner
- A request arrives after a quiet period.
- Lambda creates a new environment and loads your code: a cold start.
- The function reads from the table.
- The item is returned.
- The function responds; the environment stays warm for reuse.
- The response is a bit slower than a warm request.
Architect
- Request arrives with no warm environments available.
- Cold start: environment init plus your code’s init. Provisioned concurrency or SnapStart reduce it.
- Init done; the handler runs and calls DynamoDB.
- Item returned.
- Warm environment kept for subsequent invokes.
- Added latency is the init duration; it only affects a small share of requests.
Too many requests
Beginner
- An app goes wild and sends far too many requests.
- The front desk politely says “slow down” and doesn’t pass them on, which protects your code and your bill.
Practitioner
- A client exceeds the API’s rate limit.
- The gateway responds 429 Too Many Requests without invoking the function.
Architect
- Requests exceed the stage’s rate and burst limits.
- 429 returned at the edge; the backend and your bill are protected. Clients should retry with back-off.
Now add…
Take it with you
Pro adds video downloads, with embeds and editable source coming soon. Core explainers are always free to watch.