AWS Lambda Overview and Setup Guide
Learn about AWS Lambda, a serverless computing service. Find out how to configure Lambda functions, explore its benefits, and understand its limits.
AWS Lambda Overview
AWS Lambda is a serverless computing service that executes user-defined code in response to triggers or events. It automatically manages the underlying infrastructure, scales across multiple availability zones, and supports various programming languages such as Java, Python, Node.js, Bash, Go, and Ruby.
Key Recommendations for Using AWS Lambda
Stateless Function Design
Write your Lambda function code in a stateless manner to avoid relying on previous execution states.
Scoped Variables
Avoid declaring function variables outside the scope of the handler to prevent unintended persistence across invocations.
File Permissions
Ensure that your files have the correct +rx (read and execute) permissions in the uploaded ZIP package so Lambda can execute the code.
Clean Up
Delete old or unused Lambda functions to maintain a clean and efficient environment.
How to Configure AWS Lambda
Step 1: Sign In
Log in to your AWS account.
Step 2: Select Lambda
From the AWS services section, choose the Lambda service.
Step 3: Select a Blueprint (Optional)
You can choose a blueprint for your function or skip this step to start from scratch.
Step 4: Configure the Function
- Enter the required details to set up your Lambda function.
- Paste your code (Node.js, Python, etc.) that will be triggered by an event (e.g., new item in DynamoDB).
- Set the necessary permissions.
Step 5: Review and Create
- Click "Next" to review your configuration details.
- Click "Create Function" to finalize the setup.
Step 6: Add Event Sources
- Go to the Event Sources tab and add at least one source, such as a DynamoDB table.
- Associate the stream with your Lambda function.
Step 7: Test the Function
- Add entries to the DynamoDB table to trigger the Lambda function.
- Verify execution by checking Lambda logs.
Step 8: View Logs
Select the Monitoring tab in Lambda, and click on "View Logs in CloudWatch" to view execution logs.
Benefits of AWS Lambda
No Registration Needed
Lambda tasks don’t require registration, unlike Amazon SWF.
Reusable Functions
Lambda functions can be reused across different workflows.
Direct Execution
Functions are invoked directly by Amazon SWF, eliminating the need for an external execution program.
Tracking
Lambda provides metrics and logs to track function executions and monitor performance.
AWS Lambda Limits
Throttle Limits
The default throttle limit is 100 concurrent Lambda executions per account per region. Exceeding this limit returns a throttling error (code 429), which can be increased by contacting AWS Support.
Resource Limits
- Ephemeral Disk Capacity (/tmp space): 512 MB
- File Descriptors: 1,024
- Processes and Threads: 1,024 combined total
- Maximum Execution Duration: 300 seconds (5 minutes)
- Invoke Request/Response Payload Size: 6 MB each
Service Limits
- Deployment Package Size (.zip/.jar file): 50 MB
- Uncompressed Deployment Package Size: 250 MB
- Total Deployment Package Size per Region: 1.5 GB
- Scheduled Event Sources per Account: 50
- Lambda Functions per Scheduled Event: 5
For the latest limits and detailed information, refer to the official AWS Lambda documentation.
With these guidelines, you can effectively set up and manage AWS Lambda functions, ensuring efficient and scalable serverless computing.