Learn Aws-lambda - 10 Code Examples & CST Typing Practice Test
AWS Lambda is a serverless compute service that lets developers run code without provisioning or managing servers, automatically scaling with incoming requests.
View all 10 Aws-lambda code examples →
Learn AWS-LAMBDA with Real Code Examples
Updated Nov 25, 2025
Code Sample Descriptions
Simple AWS Lambda Function (Python)
# aws_lambda/demo/lambda_function.py
def lambda_handler(event, context):
return {
'statusCode': 200,
'body': 'Hello, Lambda!'
}
A simple AWS Lambda function in Python that returns 'Hello, Lambda!' when invoked.
AWS Lambda Function with Query Parameters
# aws_lambda/demo/query.py
def lambda_handler(event, context):
name = event.get('queryStringParameters', {}).get('name', 'Guest')
return {
'statusCode': 200,
'body': f'Hello, {name}!'
}
Lambda reading query parameters from API Gateway and responding.
AWS Lambda Function with JSON Response
# aws_lambda/demo/json.py
def lambda_handler(event, context):
return {
'statusCode': 200,
'headers': {'Content-Type': 'application/json'},
'body': '{"message": "Hello JSON!"}'
}
Lambda returning JSON data.
AWS Lambda Function Handling POST Requests
# aws_lambda/demo/post.py
def lambda_handler(event, context):
if event.get('httpMethod') == 'POST':
body = event.get('body')
return {
'statusCode': 200,
'body': f'Received: {body}'
}
return {
'statusCode': 405,
'body': 'Method Not Allowed'
}
Lambda processing POST request body from API Gateway.
AWS Lambda Function Using Environment Variables
# aws_lambda/demo/env.py
import os
def lambda_handler(event, context):
api_key = os.environ.get('MY_API_KEY', 'NotSet')
return {
'statusCode': 200,
'body': f'API Key length: {len(api_key)}'
}
Lambda accessing environment variables.
AWS Lambda Function Redirect
# aws_lambda/demo/redirect.py
def lambda_handler(event, context):
return {
'statusCode': 302,
'headers': {'Location': 'https://example.com'},
'body': ''
}
Lambda returning a redirect response.
AWS Lambda Function with Custom Headers
# aws_lambda/demo/headers.py
def lambda_handler(event, context):
return {
'statusCode': 200,
'headers': {'X-Custom-Header': 'LambdaExample'},
'body': 'Custom headers added'
}
Lambda adding custom headers in response.
AWS Lambda Function Fetching External API
# aws_lambda/demo/fetch.py
import requests
def lambda_handler(event, context):
response = requests.get('https://api.github.com')
return {
'statusCode': 200,
'body': response.text
}
Lambda fetching data from an external API and returning it.
AWS Lambda Function Returning HTML
# aws_lambda/demo/html.py
def lambda_handler(event, context):
html = '<!DOCTYPE html><html><body><h1>Hello HTML!</h1></body></html>'
return {
'statusCode': 200,
'headers': {'Content-Type': 'text/html'},
'body': html
}
Lambda responding with a simple HTML page.
AWS Lambda Function Conditional Response
# aws_lambda/demo/method.py
def lambda_handler(event, context):
method = event.get('httpMethod')
if method == 'POST':
return {'statusCode': 200, 'body': 'You sent a POST request'}
return {'statusCode': 200, 'body': 'You sent a GET request'}
Lambda responding differently based on HTTP method.
Frequently Asked Questions about Aws-lambda
What is Aws-lambda?
AWS Lambda is a serverless compute service that lets developers run code without provisioning or managing servers, automatically scaling with incoming requests.
What are the primary use cases for Aws-lambda?
Serverless APIs via API Gateway. Event-driven data processing. Scheduled tasks with CloudWatch Events. File processing for S3 uploads. Microservices and backend logic for apps
What are the strengths of Aws-lambda?
Seamless scaling for workloads of any size. Tightly integrated with AWS services. Supports multiple languages and custom runtimes. Serverless - no servers to provision or maintain. Flexible event-driven architecture
What are the limitations of Aws-lambda?
Execution time limited (default 15 minutes max). Cold-start latency for some runtimes. Vendor lock-in to AWS ecosystem. Resource limits on memory, ephemeral storage, and concurrency. Debugging and local testing can be complex
How can I practice Aws-lambda typing speed?
CodeSpeedTest offers 10+ real Aws-lambda code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.