AWS Lambda is a great serverless computing resource for a lot of different use cases. It could be used for a small project, for example, a cron job, or with other AWS Services to build something massive and complicated.
But it does have some limitation for users as well, here are some limitations (how to bypass the limitations as well) and some tips to use AWS Lambda properly.
JavaScript Codes
Limits of AWS Lambda
1. Payload Limit: 6 MB
A self-hosted Express service, by default it is 100 kB, but it could have unlimited size of the payload.
Note: that some browsers and servers may have their own limits on the size of request and response bodies, so you may need to configure those as well.
6 MB, in most cases it should be more than enough. But if the requirements for the payload is big, or your product is data heavy, then AWS Lambda probably is not a good option.
If you have to use AWS Lambda and the Payload is so big, consider read about this about how to use AWS S3 pre-signed URL to solve this issue.
How to deal with 6 megabytes limit in AWS lambda services?
2. Package Size: 50 MB
Since the deployment ZIP package for AWS Lambda, it always includes the dependency, no matter what language it is, Python, JavaScript, Dot Net … The packages size may be easier to reach 50 MB, besides optimise your dependency, for example in NodeJS project,
npm install --production
It could omit all dev dependencies to significantly reduce the package size.
There are other ways to solve the deployment package size limit issue, this article below is a good start to know more about it.
3. AWS Function Time-out: 900 seconds
900 seconds === 15 minutes
If you really have a work takes longer than 15 minutes to complete, consider using AWS SQS to build an asynchronous event-driven architecture.
Know more about SQS:
Event-driven architecture with Amazon SQS and AWS Lambda
More practical article from Enlear Academy.
Event Driven Architecture with AWS SQS
Cloud-native Queue Service in Microservice Architecture enlear.academy
If you don’t have to be sticky on AWS Lambda, there are other services as well.
- AWS Batch: AWS Batch is a service that allows you to run batch computing workloads on the AWS Cloud. You can use AWS Batch to execute long-running tasks that cannot be completed within the 15-minute limit of Lambda.
- AWS Fargate: AWS Fargate is a serverless compute engine that allows you to run containers on the AWS Cloud without managing the underlying infrastructure. You can use Fargate to run long-running tasks that cannot be completed within the 15-minute limit of Lambda.
4. AWS Lambda Supports 7 programming languages Natively
Node.js, Python, Java, Ruby, C#, Go, and PowerShell.
This could be bypassed in 2 ways.
- Use AWS Lambda Runtime API
- Use Lambda Container
AWS Lambda Bridge
Some useful Tips
128 MB Ram is not Always the Cheapest Option
When people started to use AWS Lambda, 128MB is always the defaul RAM to choose, since it is supposed to be cheaper. In fact, this statement is not always accurate.
In general, the cost of running a Lambda function with 128MB of memory allocated is relatively low compared to functions with higher memory allocations. This is because Lambda charges you based on the amount of memory used and the duration of the function execution.
When you allocate more memory to a Lambda function, it gets more CPU power and network bandwidth, which can help it complete its task faster. However, you will be charged more for the additional memory usage. On the other hand, if your function doesn’t require a lot of memory or CPU power, allocating 128MB of memory can be a cost-effective option.
Dashbird offers a free calculator to help to estimate the cost of AWS Lambda.
AWS Lambda Cost Calculator - Dashbird
So for saving the cost of AWS Lambda computing cost, try tuning it finely, the result may be surprising in the end.
Don’t Forget to Use VPCs
If your function requires access to resources in a private network, such as a database or cache, you can configure your function to run in a Virtual Private Cloud (VPC). This allows your function to access these resources securely without exposing them to the public internet. For example, if Aurora DB is used, you don’t have to expose the Aurora DB or other data storage tier publicly, VPC could be used here to build better security.
Try AWS SAM
AWS Console offers an interface for users to interact or try AWS Lambda, including deployment and testing. But SAM can simplify this for you locally.
SAM allows you to define your function’s resources and dependencies in a YAML file and deploy them using the AWS CLI. SAM can simplify your deployment process and make it easier to manage your function’s resources.
References
Others Interesting Articles of using AWS Lambda:
- Run WordPress in AWS Lambda WordPress is a PHP based popular CMS, when it was born, there was no cloud technoloy at all.
- Run WordPress on AWS Lambda (EFS Edition)
- Run container in AWS Lambda to remove the language restriction
- Building a simple serverless application status page a simple project to build on AWS Lambda
References:
Top comments (2)
Good info and thanks for sharing it.
On point no. 3, 15 minutes are 900 seconds not 90 seconds.
thanks for pointing it out. :)