<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Thuy Ng on Medium]]></title>
        <description><![CDATA[Stories by Thuy Ng on Medium]]></description>
        <link>https://medium.com/@thuyng?source=rss-964d3cec7677------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Prgy-J_cnnQq_Sdg.jpg</url>
            <title>Stories by Thuy Ng on Medium</title>
            <link>https://medium.com/@thuyng?source=rss-964d3cec7677------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 05:41:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@thuyng/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Resize image with Lambda function and AWS API Gateway by Ruby]]></title>
            <link>https://medium.com/@thuyng/resize-image-with-lambda-function-and-aws-api-gateway-by-ruby-b20b8bb440ad?source=rss-964d3cec7677------2</link>
            <guid isPermaLink="false">https://medium.com/p/b20b8bb440ad</guid>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[aws-api-gateway]]></category>
            <dc:creator><![CDATA[Thuy Ng]]></dc:creator>
            <pubDate>Thu, 19 Sep 2019 07:03:48 GMT</pubDate>
            <atom:updated>2019-09-19T08:46:27.992Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is serverless?</h3><p>Serverless architecture (also known as <em>serverless computing</em> or <em>function as a service</em>, <strong>FaaS</strong>) is a software design pattern where applications are hosted by a third-party service, eliminating the need for server software and hardware management by the developer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/0*Dw3EUfzqPAP2PUaW" /></figure><p>— Note: we can not install software/hardware for this, we can run only the code on serverless. Example, for process of image, we always need the imageMagick software so we don’t need to install it to serverless since it has been installed already.</p><p>You should especially consider using a serverless provider if you have a small number of functions that you need hosted.</p><h3>Architecture of Lambda function</h3><h3>What is lambda function?</h3><p>The code you run on AWS Lambda is called a “Lambda function.”</p><h3>Create lambda function</h3><p>You can choose many languages here. Now step to choose Ruby function:</p><ol><li>To execute the lambda you have to create permission, role, and add role to IAM user:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/558/0*q8dfY1fZnNf0ssgo" /></figure><ol><li>Go to Service-&gt;Compute-&gt;Lambda. Click on “create function”. Select Ruby 2.5</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lD1AvenMuU9gd3i4" /></figure><ol><li>Assign the role for this function:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hNXGxwMIS6gIckHq" /></figure><h3>Deploy lambda function</h3><ul><li>If your code only code without any gems/plugins/vendors, you can write your code inline on lambda function.</li><li>If your code includes any gems/plugins/vendors, you have to write code on your local, and upload your code to lambda function(mean the deployment by uploading code)</li><li>Step to deploy with ruby:</li></ul><ol><li>Create Ruby project includes .rb file and Gemfile. You bundle gems to vendor</li></ol><blockquote>bundle install — deployment</blockquote><p>2. zip code &amp; vendors to a zip folder.</p><p>zip -r lambda_function.zip lambda_function.rb vendor</p><p>3. Open lambda function: upload &amp; save it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8YIiTywQQdyIYrI0" /></figure><p>After you upload your code to AWS Lambda, you can add trigger to your function with specific AWS resources (e.g. a particular Amazon S3 bucket, Amazon DynamoDB table, Amazon Kinesis stream, or Amazon SNS notification)</p><p>For API gateway, the trigger will be added when you create this API on this step:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PX7Zh565d1L_bYrp" /></figure><h3>Architecture of of Amazon API Gateway</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nQBXot9OS6U1NkPQ" /></figure><h3>What is API Gateway?</h3><p>Amazon API Gateway is an AWS service for creating, publishing, maintaining, monitoring, and securing REST and WebSocket APIs at any scale.</p><h3>Create API Gateway with Lambda function</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3iF4cbXzLVGIrrVi" /></figure><p><strong>Option: Check to ‘Use Lambda Proxy integration’</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MH69Ts-Uq7aHq1RA" /></figure><p><strong>Option: Don’t check to ‘Use Lambda Proxy integration’</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*W_oGvGh74uPRdzcH" /></figure><h3>Deploy API Gateway</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YAXTEQbhmHLdnScS" /></figure><h3>There are some ways to call API Gateway:</h3><p><a href="https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-call-api-using-generated-sdk.html">Call REST API through generated SDKs</a></p><p><a href="https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-use-postman-to-call-api.html">Use Postman to Call a REST API</a></p><p><a href="https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-test-method.html">Use the Console to Test a REST API Method</a> =&gt; can not check authentication by this way</p><h3>How do API Gateway and Lambda function work for feature: resize image on s3:</h3><ul><li>When user call this API, lambda function will be called by trigger.</li><li>We need the API gateway with params size &amp; image to upload the resized image.</li></ul><p>Ex url: <a href="https://{restapi_id}.execute-api.{region}.amazonaws.com/%7Btarge-resize%7D/%7Bimage-key%7D">https://<em>{restapi_id}</em>.execute-api.<em>{region}</em>.amazonaws.com/<em>{targe-resize}</em>/<em>{image-key}</em></a></p><p>Follow the <a href="https://aws.amazon.com/blogs/compute/resize-images-on-the-fly-with-amazon-s3-aws-lambda-and-amazon-api-gateway/">AWS refer</a> feature will work like this image:</p><p>#1. User upload image to s3</p><p>#2. User call API Gateway</p><p>#3. Lambda function is Called</p><p>#4. Lambda function gets image from s3, resize image</p><p>#5. Lambda function uploads the resized image again to s3</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7QhO2HY2gsKMUwNQ" /></figure><p>We have another way to upload and resize in S3 by calling API Gateway directly:</p><p>#1. User call API Gateway with binary image data on body request</p><p>#2. Lambda Function is called</p><p>#3. Lambda Function resize image then upload resized image to S3.</p><p>But this way has blocker on AWS authentication. Since the only aws-sdk support for this authentication so we can not use the RestClient, httpParty, …to call these APIs with auth. And this way will work perfectly if the API doesn’t need authentication.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2xJoW22bXDX5ky-P" /></figure><p>And we will face this error:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Q3Iu5Ev4vkU-jLPt" /></figure><p>For this error, we should decode the binary and remove the invalid text. Example the code:</p><blockquote>Base64.decode64(event[“body”]).split(“ — — — WebKitFormBoundaryKwZbNBPCZQyYgDPK\r\nContent-Disposition: form-data; “).last.split(“\r\n\r\n”).last.gsub(“\r\n — — — WebKitFormBoundarysHaL2u7Mq2k1AEMt — \r\n”, “”)</blockquote><p>When you run code on Lambda function, you can see the log easily on Monitoring of Cloud Watch</p><h3>Get image from amazon s3. Steps:</h3><ol><li>Create lambda function, response the binary data image.</li><li>Create API Gateway to get data image.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Jr0ysFlR3ytgK517" /></figure><p>Android should call rest api:</p><ol><li>For upload image:</li></ol><p>METHOD: POST</p><p><a href="https://9yph8vzrob.execute-api.ap-southeast-1.amazonaws.com/development/android-upload/%7Btarget-resize%7D/%7Bimage-key">https://9yph8vzrob.execute-api.ap-southeast-1.amazonaws.com/development/android-upload/{target-resize}/{image-key</a>}</p><p>2. For get image:</p><p>Method: Get <a href="https://9yph8vzrob.execute-api.ap-southeast-1.amazonaws.com/development/get-image/%7Bimage-key">https://9yph8vzrob.execute-api.ap-southeast-1.amazonaws.com/development/get-image/{image-key</a>}</p><p>IF you don’t need lambda function for getting image from s3, you can use presigned_url of aws-s3 directly.</p><p><strong>You can follow the code base on git here:</strong></p><p><a href="https://github.com/thuynguyen/resize-image-aws-lambda.git">https://github.com/thuynguyen/resize-image-aws-lambda.git</a></p><p><strong>When should you use lambda function and API Gateway?<br></strong>When you need the service to call with concurrencies and scalable you should use it.<br>And when you need the common resized image service for many projects, you just build one lambda function. So the development time can be reduced.</p><blockquote>Author</blockquote><blockquote>Thuy Nguyen Sr. Ruby on Rails developer.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b20b8bb440ad" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[8]]></title>
            <link>https://medium.com/@thuyng/8-24e17ebfd012?source=rss-964d3cec7677------2</link>
            <guid isPermaLink="false">https://medium.com/p/24e17ebfd012</guid>
            <dc:creator><![CDATA[Thuy Ng]]></dc:creator>
            <pubDate>Wed, 11 Mar 2015 11:00:22 GMT</pubDate>
            <atom:updated>2015-03-11T11:00:22.278Z</atom:updated>
            <content:encoded><![CDATA[<p>8</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=24e17ebfd012" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[LOOK UP WORLD]]></title>
            <link>https://medium.com/@thuyng/look-up-world-23699a9dafb6?source=rss-964d3cec7677------2</link>
            <guid isPermaLink="false">https://medium.com/p/23699a9dafb6</guid>
            <dc:creator><![CDATA[Thuy Ng]]></dc:creator>
            <pubDate>Wed, 11 Mar 2015 08:18:04 GMT</pubDate>
            <atom:updated>2015-03-11T08:18:04.578Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PZlcU_SZg7hCZU-nsEoGDw.jpeg" /></figure><p><a href="https://housing.com/blog/2015/03/03/look-up-world/">LOOK UP WORLD</a></p><p>Holi is the festival that celebrates colours and happiness. It is only fitting that before this celebration starts, we say hello again and introduce our symbol, our soul to the world. Far from being just a makeover, it is the distillation of all that we stand for and culmination of a process that began a</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=23699a9dafb6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>