
10 AWS Lambda tips for faster, cheaper beginner functions
Memory buys CPU, arm64 is 20% cheaper, logs never expire by default: ten Lambda settings to get right before your first real serverless project.
Lambda is the easiest way to run code on AWS without managing a server, so it's where most students start with serverless. The defaults are fine for "Hello world", but a few settings decide whether your function is fast, cheap and safe. Here are ten tips worth knowing before your first real project.

Performance
1. Memory also buys CPU
Lambda gives your function CPU in proportion to its memory. At 1,769 MB you get one full vCPU; at 128 MB you get a small slice of one. A CPU-heavy function at 128 MB can run so slowly that it costs more than the same function at 512 MB, because you pay for memory × time.
Try it: run the open-source AWS Lambda Power Tuning tool. It runs your function at several memory sizes and charts cost against speed.
2. Create clients outside the handler
Code outside the handler runs once per execution environment and is reused on warm invocations. Put SDK clients, database connections and config loading there:
import boto3
s3 = boto3.client("s3") # created once, reused while the environment stays warm
def handler(event, context): return s3.list_buckets()["Buckets"][:3]3. Keep the package small
Every extra dependency adds to cold-start time. Remove what you don't use, and don't ship test files or large data in the deployment package. For Java, Python and .NET, SnapStart can cut cold starts further.
Cost
4. Switch to arm64
Lambda on arm64 (Graviton2) costs 20% less per GB-second than x86 and often runs as fast or faster. For most Python and Node.js functions it's a one-setting change. Check native dependencies first.
5. Know the always-free tier
Every account gets 1 million requests and 400,000 GB-seconds per month, every month, not just in the first year. At 128 MB and 200 ms per call, that's millions of free invocations. What isn't covered: CloudWatch Logs beyond its own free tier, data transfer, and any other service your function calls.
6. Set log retention
Lambda's log groups default to Never expire. Set a retention period, and use Lambda's advanced logging controls to choose JSON format and a log level, so debug lines don't ship in production.
Safety
7. Set the timeout on purpose
The default timeout is 3 seconds and the maximum is 15 minutes. Too short and real requests fail; too long and a stuck function burns money until it's killed. Set it a little above your normal worst case.
8. Use reserved concurrency as a guardrail
Reserved concurrency caps how many copies of a function can run at once. It protects downstream systems like a small database, and it limits how fast a bug or a burst of traffic can spend money. Setting it to 0 is an instant off switch.
9. Avoid recursive loops
The classic beginner bill: a function triggered by S3 uploads writes its output back to the same bucket and prefix, triggering itself again. Lambda can detect and stop some recursive loops, but don't rely on it. Write output to a different bucket or prefix.
10. Keep secrets out of environment variables
Environment variables are fine for config like table names. For API keys and passwords, use Secrets Manager or Parameter Store. The AWS Parameters and Secrets Lambda Extension caches values, so you're not calling the API on every invocation.
Quick checklist
- [ ] Memory tuned (try Power Tuning)
- [ ] Clients created outside the handler
- [ ] arm64 where dependencies allow
- [ ] Timeout set to just above your normal worst case
- [ ] Log retention and log level set
- [ ] Reserved concurrency on anything public
- [ ] No trigger that can call itself
- [ ] Secrets in Secrets Manager or Parameter Store
What's the Lambda setting you wish you'd known about earlier? And are you on arm64 yet?
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article