๐ AWS Lambda Limit and Features Everyone Should Know
๐ก Newskategorie: Programmierung
๐ Quelle: dev.to
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?
I have a three-tier app running in AWS. The midware was written in Python Flask and stored on a Linux machine. Howeverโฆ
stackoverflow.com
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 Ways to Overcome AWS Lambda Deployment Size Limit โ Part 1
medium.com
3. AWS Function Time-out: 90 seconds
90 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
SQS to Lambda, event-driven architecture is a queue and made easier now that Amazon SQS can trigger AWS Lambdaโฆ
acloudguru.com
](https://acloudguru.com/blog/engineering/event-driven-architecture-with-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
](https://enlear.academy/event-driven-architecture-with-aws-sqs-d277851442c6)
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
Request costs: $0/month Execution costs: $0/month Total AWS Lambda costs: $0/month AWS Lambda uses a pay-as-you-useโฆ
dashbird.io
](https://dashbird.io/lambda-cost-calculator/)
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:
...