AWS Lambda and Serverless Basics: Run Code Without Servers, Triggers, Pricing and Your First Function

AWS Technical Essentials 50 min min read Updated: Nov 17, 2026 Beginner
AWS Lambda and Serverless Basics: Run Code Without Servers, Triggers, Pricing and Your First Function
Beginner Topic 3 of 4

What Does Serverless Mean?

Serverless does not mean 'no servers'. It means you do not manage servers. AWS provisions, patches and scales them for you. You only provide code and pay for what runs.

Server-based (EC2)Serverless (Lambda)
You choose and manage serversNo servers to manage
Pay while the server runs (even idle)Pay only while code runs
You set up scalingScales automatically
Good for long-running appsGood for short, event-driven tasks

What Is AWS Lambda?

  • Lambda runs your function in response to an event
  • Languages: Python, Node.js, Java, .NET, Go, Ruby and custom runtimes/containers
  • You upload code, set memory (128 MB to 10,240 MB) and timeout (up to 15 minutes)
  • CPU grows with memory
  • It scales from zero to thousands of parallel runs by itself

Common Triggers

TriggerExample
Amazon S3A photo is uploaded, create a thumbnail
Amazon API Gateway or Function URLA web or mobile app calls an HTTP API
EventBridge scheduleRun a cleanup every night at 2 AM
SQS / SNSProcess messages from a queue or a notification
DynamoDB Streams / KinesisReact to data changes
Alexa, IoT, CloudWatch LogsVoice skills, devices, log processing

Your First Function

python import json def lambda_handler(event, context): name = event.get("name", "world") print(f"Received event for {name}") # goes to CloudWatch Logs return { "statusCode": 200, "body": json.dumps({"message": f"Hello, {name}!"}) }
  1. Open Lambda → Create function → Author from scratch
  2. Name hello-lambda, runtime Python 3.12 (or newer), architecture arm64 (cheaper) or x86_64
  3. Keep the default execution role (it allows writing logs)
  4. Paste the code and click Deploy
  5. Create a test event { "name": "Asha" } and click Test
  6. Open the Monitor tab and view logs in CloudWatch
bash aws lambda invoke --function-name hello-lambda --payload '{"name":"Asha"}' --cli-binary-format raw-in-base64-out out.json && cat out.json aws logs tail /aws/lambda/hello-lambda --since 10m

Permissions: Two Sides

SideMeaning
Execution roleWhat the function is allowed to do (for example read from S3, write to DynamoDB, write logs)
Resource-based policyWho is allowed to invoke the function (S3, API Gateway, another account)

Pricing and Limits

  • You pay for number of requests and duration × memory (GB-seconds). A free tier is available each month
  • Duration is billed in milliseconds
  • Key limits: 15 minutes max runtime, memory up to 10 GB, /tmp storage up to 10 GB, 1,000 concurrent executions by default per Region (can be raised)
  • Cold start: the first run after idle takes extra time to start. Reduce with smaller packages, SnapStart where available, or provisioned concurrency

Best Practices

  • Keep functions small and focused
  • Do not store state inside the function. Use S3, DynamoDB or other storage
  • Give the least privilege role
  • Set a sensible timeout and watch errors and throttles in CloudWatch
  • Use environment variables and Secrets Manager for settings
  • For async jobs add a dead-letter queue or failure destination

When Is Lambda a Good or Bad Fit?

Good fitPoor fit
Short tasks, event processing, APIs, automationJobs longer than 15 minutes
Unpredictable or spiky trafficConstant heavy compute where a server is cheaper
Glue between AWS servicesApps needing special OS-level control

Practice

  1. Create the hello function and test it
  2. Add an S3 trigger that logs the uploaded file name
  3. Create an EventBridge schedule that runs it every 5 minutes (then remove it)
  4. Change memory from 128 MB to 512 MB and compare duration and cost

Conclusion

Lambda runs your code in response to events with no servers to manage, scales automatically and charges per request and duration. Use execution roles for permissions, triggers for events, and CloudWatch Logs for debugging.

Quick Summary: serverless; Lambda; triggers; first function; permissions; pricing; best practices; fit.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators