Aws Lambda
Aws Lambda
By Anish Kumar
Agenda
• What is AWS Lambda ?
• How AWS Lambda Works ?
• Key Features
• Use Cases
• Pricing Model
• How to Create a Lambda Function ?
• Best practices
• Advanced Features of AWS Lambda
• Integration with other AWS Service
• Security in AWS Lambda
• Monitoring and Logging
• Real World Use Cases
• Conclusion
What is AWS Lambda
• AWS Lambda is a serverless compute service that runs your code in
response to events and automatically manages the underlying compute
resources.
• No need to provision or manage Server.
• Python, Java , Node.js, Ruby, Go, etc..
How AWS Lambda Works
• Lambda functions are triggered by various AWS services such as S3,
DynamoDB, Kinesis, SNS, API Gateway, etc.
• Code is executed in response to these events.
• Automatically scales by running code in response to each trigger.
• Charged based on the number of requests and the compute time used.
Key Features
• Event-Driven: Responds to events and triggers.
• Automatic Scaling: Scales automatically based on the number of events.
• High Availability: Built-in fault tolerance and availability.
• Integrated with AWS Services: Easily integrates with other AWS
services.
• Flexible Resource Model: Choose memory size and execution time limits.
Use Cases
• Data Processing: Real-time file processing (e.g., image resizing, log
analysis).
• Backends: Create backends for web, mobile, IoT applications.
• Real-time Stream Processing: Processing data streams from Kinesis or
DynamoDB Streams.
• Automation: Automate tasks like backups, security checks, and system
administration.
Pricing Model
• 1 million free requests and 400,000 GB-seconds of compute time per
month.
• Pay for the number of requests and the compute time.
• Requests: $0.20 per 1 million requests after the free tier.
• Duration: $0.00001667 for every GB-second used.
How to Create a Lambda Function
• Step 1: Log in to AWS Management Console.
• Step 2: Navigate to AWS Lambda service.
• Step 3: Click "Create function".
• Step 4: Choose a blueprint or author from scratch.
• Step 5: Configure function (name, runtime, role).
• Step 6: Write or upload code.
• Step 7: Configure triggers.
• Step 8: Test and deploy the function.
Best Practices
• Keep Function Small
• Stateless function (Avoid stateful operations to leverage scaling)
• Optimize Memory and Execution Time
• Error Handling
• Monitor and Log
Advanced features of AWS Lambda
• Concurrency and Scaling Controls
• Reserved Concurrency & Provisioned Concurrency
• Lambda Layers
• manage common code (such as libraries and dependencies) & shared across multiple functions
(reducing redundancy).
• Custom Runtimes
• Use custom runtimes to run Lambda functions in any programming language.
Integration with other AWS Service
• AWS Step Functions
• Coordinate multiple AWS services into serverless workflows using visual workflows.
• Simplifies complex processes such as error handling and retries.
• Amazon API Gateway
• Create, publish, maintain, monitor, and secure APIs at any scale.
• AWS Lambda serves as the backend for these APIs, executing in response to HTTP requests.
• AWS SAM (Serverless Application Model)
• An open-source framework for building serverless applications.
• Define serverless applications using a simple and clean syntax.
Security in AWS Lambda
• IAM Roles and Permissions
• Assign IAM roles to Lambda functions to control access to other AWS resources.
• Environment Variables
• Use AWS Key Management Service (KMS) for encrypting environment variables.
• VPC Integration
• Deploy Lambda functions within a VPC to access private resources.
Monitoring and Logging
• AWS CloudWatch
• Monitor and log Lambda function performance and execution.
• Set up CloudWatch Alarms to alert based on specific metrics.
• AWS X-Ray
• Trace and analyze requests as they travel through your Lambda functions.
• Helps in identifying performance bottlenecks and debugging issues.
• Logging Best Practices
• Implement structured logging using JSON for better analysis.
• Use log levels to control the verbosity of log output.
Real World Use Cases
• Netflix
• Uses AWS Lambda for real-time file transcoding and processing.
• Airbnb
• Employs Lambda for streamlining data pipelines and real-time monitoring.
• Coca-Cola
• Utilizes Lambda for managing inventory and logistics operations.
Conclusion
• AWS Lambda is a powerful, serverless compute service that simplifies
building and scaling applications.
• AWS Lambda provides a robust, scalable, and cost-efficient solution
for a wide range of applications.