![]() ![]() Here’s a look at my full serverless.yml file. This is real easy with Serverless and simply requires us to add the appropriate block to our config. We’ll also need to activate binary media types. Once the layer is deployed, make note of the ARN because you’ll need it for your Serverless config file. I had to seek out a special ImageMagick layer which was compiled with free type as I needed typography support. Here’s a link to an ImageMagick layer which you can deploy to your AWS account. It is also the ideal way to make sure the ImageMagick library is bundled with your function. Layers are the way Lambda allows you share common components between functions. Anyway, there are two things we’ll need to do to make sure our Lambda function works properly: Make sure ImageMagick is available to our function and activate binary media types so our function can return an image. I found myself learning the basics after a few tries and then using the ease of the Serverless framework to discover areas of AWS I didn’t even know existed. I would highly recommend the Serverless Stack tutorial if it is new to you. I use the Serverless framework to setup my AWS projects due to its ease of use and ability to scaffold up and tear down projects as needed. Lambda, I’m Home! Serverless Prerequisites In addition, we’ll use another function to dynamically serve companion HTML share pages which contain all the meta tags required. Rather than generating and storing every dynamic image, we’re going to use a Lambda function to return an image as part of a real-time response. That’s Cards for Twitter and OpenGraph tags for Facebook, respectively. □ Instead, we must utilize the meta functionality of both platforms to get them to share an image as part of a on-click URL share. The trade off was that it was off system so there is no way we can track if a failure happens in any of the steps but that issue is solvable by having a crontab that checks if any image in the root directory was processed or not, and if not, process it.As I mentioned in Part 1, the one-click, non-authenticated, image share to Twitter and Facebook does not exist. This way I not only reduced the time that this particular endpoint took, but I also centralized the logic of image uploads in the whole system, this way it was cleaner, faster and more efficient (since Imagemagick is way more powerful than any PHP built in function).Īlso, since images became lighter and progressive in nature the time to interact with the web page was decreased and the pages loaded faster. ![]() I then wrote a nodeJS code to interact with Imagemagick library that:ī - remove any meta data from the image to further decrease its sizeĬ - convert the image into a progressive jpgĭ - resizes the image into 3 different sizes with keeping the aspect ration the same So, I installed Imagemagick library into an AWS Layer and used this layer inside a Lambda function that is triggered whenever an Image resource was uploaded into a bucket. ![]() To solve this issue I firstly wanted to decouple the logic of image processing from the business logic, and then change the way we handled the image processing itself. It was challenging to track the flow since it was an old code base and the above logic was scattered across multiple classes/services This intense IO and image processing with PHP was taking a lot of time, and, on the other hand was producing images with large sizes and wrong formats. A project I was working on had an issue with one of its key API endpoints, the endpoint used to take a lot of time to respond, after investigating I concluded that the reason was the way image resources were handled on the server the image was firstly sent as a parameter to the endpoint, then it was saved to desk as is, after that it was read from disk to be compressed and then it was written again on disk, then it was read from disk again to be resized into three different sizes and converted into the proper format then these three images were sent to a S3 bucket. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |