The price per 100 ms of compute time also depends on the hardware you choose to have your function executed on. You are charged for every 100ms of execution time. PricingĪWS Lambda pricing is pretty affordable. Sounds great, but I haven't had a chance to try it yet. There is a node library - thaumaturgy that spins up a Lambda function to do the building of those special node packages, stores them to S3 and downloads them to your computer. There is actually another option, that I only found after finishing this project. You may even want to check in your node_modules into git. Downside is that you can't share your code with colleagues as easily. Then you just bundle it in your node_modules and upload it with the code. Or download the sharp lib precompiled on the right architecture - download it here.Do the compiling on the same architecture that the Lambda runs on - which you do by spinning up an AWS micro instance and doing the compiling there, and then you download the result and copy it to your node_modules.It won't work, it will throw an "Invalid ELF Header" error. You can't just npm install sharp locally, zip it with code and upload to Lambda (as you normally would do with other packages). Since it uses native APIs, it needs to be compiled on the same architecture that the Lambda runs on. It uses VIPS, that only holds a part of the image in memory at one time, so it's very fast and efficient.īut an issue with using Sharp in AWS Lambda environment is exactly the VIPS library. Sharp is a NodeJS image transformation library that way exceeds other libraries like ImageMagic in terms of speed. Here is the list of all available event sources for Lambda. How do you run a Lambda function? There are several ways of invoking it - via an HTTPS request to a specific url or your Lambda (Amazon API Gateway), or when an specific event happens on one of the AWS services like SNS or S3. You only write the code, and AWS takes care of starting instances of your Lambda function, scaling it up or down and balancing hardware requirements. Your Lambda function can do anything, and in our case it was resizing images. You write code for your Lambda function, in Java, NodeJS or Python, and you upload it to AWS Console. AWS Lambda was a perfect match for those requirements.ĪWS Lambda is Amazon's compute service. We wanted this processing to be scalable, and to allow it to run in parallel without much programming overhead. But we also had to wait for all the images to upload before starting to resize them - there were business rules preventing us from resizing images as they come. So the images needed to be available (nearly) as soon as the new Order came in, in different sizes. When I say resizing, I actually mean getting all those images from S3, doing the resizing, and storing them back to S3.Ī lot of hi-res images would be uploaded with the Order (1000 or more), and as soon as they all got uploaded, the Admin would see the new Order and should be able to browse through the images - two sizes of thumbs alongside the original image. The result - resizing 1000 images (around 1.2 GB) to 2 thumbnail sizes in a little less than 3s. Recently I worked on a project that required fast image resizing.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |