<?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 Mohamed Latfalla on Medium]]></title>
        <description><![CDATA[Stories by Mohamed Latfalla on Medium]]></description>
        <link>https://medium.com/@mlatfalla?source=rss-797cc3a8347b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*1fUQ3jcAnrZrf_9o1260yg.jpeg</url>
            <title>Stories by Mohamed Latfalla on Medium</title>
            <link>https://medium.com/@mlatfalla?source=rss-797cc3a8347b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 14 Nov 2026 15:44:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mlatfalla/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[Serverless Event Driven orchestration?]]></title>
            <link>https://mlatfalla.medium.com/serverless-event-driven-orchestration-57e2b814d0c7?source=rss-797cc3a8347b------2</link>
            <guid isPermaLink="false">https://medium.com/p/57e2b814d0c7</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cloud-architecture]]></category>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[serverless]]></category>
            <dc:creator><![CDATA[Mohamed Latfalla]]></dc:creator>
            <pubDate>Sat, 30 Mar 2024 21:36:31 GMT</pubDate>
            <atom:updated>2024-03-30T21:36:31.468Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FT7G66kbkC5J8B13uzKI8A.jpeg" /></figure><p>The beauty of Serverless architecture is the its simplicity. You can do a lot of functionality based on a simple event got triggered from a single function. Basically, this, lets say workflow, gets triggered when for example a file was committed into a specific S3 bucket.</p><p>But, when it comes to complex workflows, its getting more challenging to maintain a healthy, successful workflow that accomplish the needful. The simple way is Lambda function Destination, which gets triggered when the main function execution completed. Of course you can trigger is when the function got completed successfully or failed (with keeping in consideration code skills to handle the function failures). But this is not an ideal scenario for complex workflow.</p><p>Lets mention several services and the sequence of evolve to achieve the best orchestration on my opinion:</p><h3>SQS:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*rRfhpqkDM5o9W2cntXMg5w.png" /></figure><p>Simple Queue Service is one of the great options you need to keep in consideration. Simply it serve a waiting station lets say for the functions. You can send the event payload into the queue and then control many aspects for the execution like:</p><ul><li>Waiting time before consuming the message: How long should the event wait before it gets available for a function to consume it.</li><li>FIFO: whether your workflow should maintain first in first out for any sequence execution needed.</li><li>DLQ: if your function failed to consume the message, then send it to an investigation queue, which will hold the message for you to do your code or your sequence check. This is really good point for SQS.</li></ul><p>But, making SQS as a trigger point for other Lambda functions can be overwhelming as you need to maintain multiple aspects for that. What can be done?</p><h3>StepFunctions:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WZReBm4ru-D1pOfQT_sSfQ.png" /></figure><p>Stepfunction is a service that can work as your workload composer. This service is great to coordinate the sequence of function execution in your workload. Why this is a great service?</p><ul><li>State Machine: Order the execution of your functions in the order you need. What should be executed first and what should come next. Each function Payload feeds the other function to proceed with your execution.</li><li>Parallel Execution: If one function payload suits multiple functions input, and the workflow can have multiple functions to be executed at the same time then this is a BIG plus for StepFunctions.</li><li>A lot of compatible services: You can integrate Many services in your workflow as the compatibility is available. In fact, you can integrate DLQ from SQS into your workload as well.</li></ul><p>This is great, but can this get better?</p><h3>EventBridge:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/1*T7Aaa4lpl4ly4ekQjJkEpw.png" /></figure><p>EventBridge is an Event Bus service that has some points in common with StepFunctions but can serves wider range of workflows. Lets see why this is really good service:</p><ul><li>Event Routing: this is the main routing point for the service. This simply can redirect the payload into the desired destination even if the destination wasn’t Lambda function. Thanks to the set of services that are compatible with it.</li><li>Schema Registry: This is the part that is responsible about identify, classify and trigger rules in EventBridge that can leverage the Routing service to redirect payloads into destinations. New schema version for a specific function? No problem, schema versioning is in place.</li><li>Event Archive: This is really important feature and let me tell you why? This can make you reconcile missing events or missing execution that failed for any reason like concurrent limit exceeded or network interruption.</li></ul><h3>To summaries:</h3><p>Serverless orchestration is something grow with you. You will not find the ideal scenario from day one or year one. As you can see from the sequence I mentioned the services in that not a single service is going to be an ideal solution for your workflow. Invest time in understanding these services, mirror it over your workflow, and construct what you need. I know its intimidating to leverage this much of cool services in one application but this is something you should get away from. Do not couple your workflow or at least if needed, do not do it too much.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=57e2b814d0c7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Use Secrets in Lambda Safely]]></title>
            <link>https://aws.plainenglish.io/how-to-use-secrets-in-lambda-safely-720a4fb7b7a0?source=rss-797cc3a8347b------2</link>
            <guid isPermaLink="false">https://medium.com/p/720a4fb7b7a0</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Mohamed Latfalla]]></dc:creator>
            <pubDate>Wed, 27 Mar 2024 04:02:51 GMT</pubDate>
            <atom:updated>2024-03-27T04:02:51.656Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/643/1*J1U2kzWvqf6nDiVWJPPyNQ.jpeg" /></figure><p>When it comes to call and interact with other resources that need username/password, some people tends to hardcoded it in the code. Which in fact, is the worst thing you can do. For many reasons:</p><h3>1- easy to gain access:</h3><p>When you hardcoded your SQL server credintials in the code, you wider the range of people who can gain unauthorized access to your resources. This can be done by getting a copy of your code or even simpler, memorize it. Sounds rediculos right? Trust me I saw this before.</p><h3>2- update credentials Delima:</h3><p>When you have a policy states that you need to update the password quarterly, or once a year. You have to know everywhere you hardcoded this credentials, which sounds hectic. Because when you miss one place, and your system is coupled. Good luck finding it.</p><p>I can keep going giving more examples but I believe the message got received. Lets focus on AWS Lambda, one of the easiest computing unit you can code in.</p><p>Imagine with me having an application consists of 50 lambda function, which 25 functions has the value hardcoded. You changed for any reason the app DB connection. And you have 20 function out of the 50 function connect to a third party service that the policy forced you to update the password. Its one time job, but its one time job once every quarter. Who want to do this job? No one.</p><p>AWS Lambda has a verity of secret holders services that you can call to retrieve the secrets safely and within the same network. The highest security concerns you will have if you’re dumping the password into logs or you have the wrong IAM roles associated with the wrong users. I can’t think of more obvious ways that can scare you storing your passwords in one of the following services:</p><p><strong>Environment Variables:</strong></p><p>This is the most straight forward place they you can store your secrets in. This gets encrypted within your lambda container. How to use it? Simple, check the below captures:</p><p>Go to configuration from the main lambda function page, add your secrets:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dLY0QXGpQLkyS-5l444jGw.png" /></figure><p>The below example uses python code. You need to import os library and assign the value into it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VzL8uWjTQ9da9qs9IjHLPA.png" /></figure><p>Thats it! You can see below the example of it being called and captured.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*Tonuq1O_Ez_bg3TtLrfEFw.png" /></figure><p>The only downside of this is that you need to update all your functions if you updated your secrets but this is a secure way to use and call your secrets. Is there a better way? Yes!</p><p><strong>Secrets managers:</strong></p><p>This is by far, the best way I can recommend to use when it comes to secure and use your secrets. This way can reflect into all functions that are using your secrets. It can rotate the encryption key that encrypt your secrets.</p><p>What you need to add into your Lambda IAM role is only “<strong><em>secretsmanager:GetSecretValue</em></strong>” to read the secrets.</p><p>Go to secrets manager, create a new secret and fill it with what you need.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aoEKxI46-SmtvKBjMZm3AA.png" /></figure><p>After you save the secrets, you can validate it here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*htsNfOLrJS13t8do_S2hQQ.png" /></figure><p>An example of python code to call the secrets:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*SUx-mUhKTH_pS6K7SONBcA.png" /><figcaption>Simply test your function to see the secrets retrieved successfully.</figcaption></figure><p>Simply test your function to see the secrets retrieved successfully.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zc8In1qQVhVOwqOXeMJ8dg.png" /></figure><p>This way is the best way by far. Very simple and can be called by any other AWS service. Lambda is an example of this use-case.</p><p>Bonus service to store the secrets? Yes!</p><p><strong>Parameter Store:</strong></p><p>This way as we can store your secrets. The thing I like about this one is that even the changes can have versions of your changes. This case insure you can always get your old secrets when it gets changed by mistake. Very simple and straight forward as well.</p><p>You need to add “<strong><em>ssm:GetParameters</em></strong>” to your Lambda IAM role.</p><p>This is an example of a parameter store:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*92-DB9MAdLa23MBlkWDWjA.png" /></figure><p>And this is the python example to call the parameters:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*pLe-qch1TeI6Aifu5aBE4g.png" /></figure><p>And this is an example how you will get your secrets:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/552/1*IFcf1qUKvNbeCB6UqK8gwg.png" /></figure><h3>Summary:</h3><p>You need to secure your secrets in your functions, this is the best practice. When it comes to Lambda, there are many options you can use and it’s based on your preferences, you can use your way of securing it.</p><h3>In Plain English 🚀</h3><p><em>Thank you for being a part of the </em><a href="https://plainenglish.io/"><strong><em>In Plain English</em></strong></a><em> community! Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://twitter.com/inPlainEngHQ"><strong>X</strong></a><strong> | </strong><a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a><strong> | </strong><a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a><strong> | </strong><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Discord</strong></a><strong> | </strong><a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a></li><li>Visit our other platforms: <a href="https://stackademic.com/"><strong>Stackademic</strong></a><strong> | </strong><a href="https://cofeed.app/"><strong>CoFeed</strong></a><strong> | </strong><a href="https://venturemagazine.net/"><strong>Venture</strong></a><strong> | </strong><a href="https://blog.cubed.run/"><strong>Cubed</strong></a></li><li>More content at <a href="https://plainenglish.io/"><strong>PlainEnglish.io</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=720a4fb7b7a0" width="1" height="1" alt=""><hr><p><a href="https://aws.plainenglish.io/how-to-use-secrets-in-lambda-safely-720a4fb7b7a0">How to Use Secrets in Lambda Safely</a> was originally published in <a href="https://aws.plainenglish.io/">AWS in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Should I use AWS Lambda SnapStart?]]></title>
            <link>https://aws.plainenglish.io/should-i-use-aws-lambda-snapstart-520edf5c48cb?source=rss-797cc3a8347b------2</link>
            <guid isPermaLink="false">https://medium.com/p/520edf5c48cb</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[lambda]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Mohamed Latfalla]]></dc:creator>
            <pubDate>Tue, 20 Dec 2022 08:16:53 GMT</pubDate>
            <atom:updated>2022-12-20T08:16:53.076Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hv8QSnFMRaFOlh6Uh7EVLg.png" /></figure><p>One of the main issues that makes Lambda struggle in some scenarios is Cold Start. Which is the time that Lambda takes for the first execution.</p><p>Cold start is the first execution after a new version got published or an exection after a long inactive period of time, mainly. <br>This execution cause a delay in finishing the request, as it takes time for AWS to prepare the computing unit, which is relatevly fast, and to do the Init phase, which could take a long time mainly for Java becaues of the nature of code compiling.</p><blockquote>Note: If you want to see your request from the moment it hits Lambda endpoint till the end, enable X-Ray. Its not free.</blockquote><p>Let me add more into this point as it is the key point for this feature. <br>When your Lambda function set for a long period of time without executions, AWS will reclaim its space from the EC2s that are specified for Lambda. Also, if you published a new version of the same function, which it could be adding a single space into your code, will delete the current version from the EC2s and replace it with the new version. These two main point of causing the cold start.</p><h3><strong>Cool, So what SnapStart does?</strong></h3><p>SnapStart will cache the init phase internally for you. So when you call the function, it will pring the cached version to shorten the Init phase. In this case, the first execution will be way faster. As AWS shared, the cache part is free, yaay!!.</p><p>Lets dive into the Pros and Cons for this feature shall we?</p><h3><strong>Pros:</strong></h3><p><strong>A- Speed:</strong> Lambda first execution would be much faster, especially with the heavy runtime like Java. Because the function resources initialization will be cached, Retrieving a cached image of your executable is much faster than rebuilding it every time you need to scale up or run it after inactive period.</p><p>Thats it! This feature is really to the point. It solve a big issue for many users.</p><p>I know its a new feature but lets adress the obvious points that AWS will need to deal with soon.</p><h3><strong>Cons:</strong></h3><p><strong>A- Runtime:</strong> They support only Java for now. Which is obvious as the nature of code compliling and the number of different frameworks you can use. Other runtimes like Python is really fast to load in Lambda. Enabling this feature as well for Python makes it much powerfull and ready for more scenarios.</p><p><strong>B- Caching:</strong> The solution cause another set of issues. Lambda is a computing unit that does what you code it to do. So, you must do a lot of testing for your code before you apply it on production workload. You much check your code for not using or relying on a set of files, saved configuration that gets pre-compiled because there is a chance that it would be using some cached values.</p><p><strong>C- One function, multiple versions?:</strong> Because Lambda has a lot of ways to be triggered, you must update your trigger with the coorect ARN to use the version that has the SnapStart. If you don’t, it won’t use it and will use the normal function, with no SnapStart previlidge. But if this is the case, every new version, a new trigger update? hmmm no good.</p><p>I can add more points but lets focus on what is the takeaway from this feature.</p><p>It is really great feature. I’ve been using Lambda for the past 4+ years and I faced many time the cold start issue. But from my point of view, it could be better.</p><p>Like for example, add more runtimes. I know it could be a big challenge to release it with other runtimes like Python, which I can directly point to one potential issue, multiprocessing manager. Or the smartness in the trigger services to use always the SnapStart version. But these things will eventually come.</p><h3><strong>Should I use it?</strong></h3><p>If you are a Java user, I believe its a must for you to adopt this feature. It dissolve the aincient issue of Serverless. It would give you almost the same effect of running your function on an EC2, faster. But, you must do a lot of testing for your code. You built your function on a way that it works with and without Cold Start. This one might shake your code a bit.</p><p><em>More content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><em>. Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a>, <a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><em>, </em><a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong><em>YouTube</em></strong></a><em>, and </em><a href="https://discord.gg/GtDtUAvyhW"><strong><em>Discord</em></strong></a><strong><em>.</em></strong></p><p><strong><em>Interested in scaling your software startup</em></strong><em>? Check out </em><a href="https://circuit.ooo/?utm=publication-post-cta"><strong><em>Circuit</em></strong></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=520edf5c48cb" width="1" height="1" alt=""><hr><p><a href="https://aws.plainenglish.io/should-i-use-aws-lambda-snapstart-520edf5c48cb">Should I use AWS Lambda SnapStart?</a> was originally published in <a href="https://aws.plainenglish.io/">AWS in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Handle Asynchronous Requests in AWS]]></title>
            <link>https://aws.plainenglish.io/how-to-handle-asynchronous-requests-in-aws-a4e8ef993f57?source=rss-797cc3a8347b------2</link>
            <guid isPermaLink="false">https://medium.com/p/a4e8ef993f57</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[event-driven-architecture]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[serverless]]></category>
            <dc:creator><![CDATA[Mohamed Latfalla]]></dc:creator>
            <pubDate>Fri, 21 Oct 2022 04:16:48 GMT</pubDate>
            <atom:updated>2022-10-21T04:16:48.065Z</atom:updated>
            <content:encoded><![CDATA[<h4>Part 1</h4><p>One of the most interesting architectures nowadays is event-driven. It consists of an event producer and action. So, if we imagined that I uploaded an excel sheet to S3, I want a set of actions to be performed against the records that are in this file. Pretty simple, event-driven architecture will solve the issue.</p><p>But, what makes this flow, somehow hard to maintain is that when it starts, it keeps moving. Another imagination is if you have 500k+ records in that excel file, and you had an unhandled error hits the record number 200k, what would you do? Do you reload the file and waste all computing power that processed 199,999 records? Sounds expensive and frustrating.</p><p>Luckily, there are number of ways to handle this issue. Allow me to present “ a way” to solve this issue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*Ir9f-CRsF-32K0XB0gtWMw.png" /></figure><p>It seems to be simple and repetitive? Yes it is.</p><p>Let’s assume you uploaded an excel file to S3, and you want all the rows to be cleaned from extra spaces, perform some data adjustment, and insert the records to a database.</p><p>So let me walk you through the record lifecycle, and then why it was this way:</p><p>1- File got uploaded, S3 events triggered Data Generator function.</p><p>2- Data Generator function will pass all the records into Queue 1. After visibility timeout and delivery delay reached, Function 1 will start pulling batches from the queue.</p><p>3- If a record had unhandled error, the whole batch will be sent to DLQ 1.Why is that? Because The function pulled a whole batch, not a single record. So, the batch will be still in the queue until Lambda tells the queue I’m done with it you can delete it. Otherwise, the batch will be deliver to Queue 2 and will be deleted from Queue 1 after Function 1 returns success to Queue 1.</p><p>4- The same scenario will be performed with Queue2, Function 2 and DLQ2.</p><p>Now let me tell you why this scenario is achieving the goal.</p><p><strong>1- Event-Driven:</strong></p><p>As you can see, no action will be performed unless it satisfies the trigger requirements. Uploading the file to S3 is the flow generator. Without it, the whole flow will be idle.</p><p><strong>2- Lower batch to retry:</strong></p><p>SQS FIFO (First In — First Out) can send batches that hold up to 300 messages per second or 3000 when it get sent by batches. This has some factors to it that shapes the batch size ( Data Generator passed messages interval, visibility timeout, and delivery delay). Having 300 messages to handle is more manageable than the whole file.</p><p><strong>3- DLQ is the saviour:</strong></p><p>Because of DLQ, the unhandled records can be isolated and dealt with separately. Some records might have some special characters, different format or even empty strings. This can toast all the processed data if it was not held in a safe place (like cache or inserted into DB). Once the records reached DLQ, you have the freedom to do whatever you want to that batch of records. Like reprocess if, for example, you exceeded the concurrent limit of Lambdas, or you had the unhandled error.</p><p><strong>4- Price wise? Justifiable:</strong></p><p>When we see the price of 1 million requests (0.50$) it is nothing comparing with the benefits that we’re getting from. Because this is the price we pay to isolate the records that shows us clearly the gaps and code mistakes to handle our records. Without it, you will pay way more for Lambda with the reruns that are unnecessary and A LOT MORE for CloudWatch for put logs action. Which is by the way expensive if you dont know how to use it wisely.</p><p>To conclude this short article, I highly encourage anyone who works with Serverless to invest more in this part of the architecture. Because the amount of money and time you invest to handle these small, yet expensive errors, is totally worth it. I will bring part 2 to show you how you can make it more dynamic with EventBridge. Until then, be safe.</p><p><em>More content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><em>. Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a>, <a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><em>, </em><a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong><em>YouTube</em></strong></a><em>, and </em><a href="https://discord.gg/GtDtUAvyhW"><strong><em>Discord</em></strong></a><em>. Interested in Growth Hacking? Check out </em><a href="https://circuit.ooo/"><strong><em>Circuit</em></strong></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a4e8ef993f57" width="1" height="1" alt=""><hr><p><a href="https://aws.plainenglish.io/how-to-handle-asynchronous-requests-in-aws-a4e8ef993f57">How to Handle Asynchronous Requests in AWS</a> was originally published in <a href="https://aws.plainenglish.io/">AWS in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Did I Create EC2 by Voice?]]></title>
            <link>https://aws.plainenglish.io/how-did-i-create-ec2-by-voice-14319200abc?source=rss-797cc3a8347b------2</link>
            <guid isPermaLink="false">https://medium.com/p/14319200abc</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[event-driven-architecture]]></category>
            <dc:creator><![CDATA[Mohamed Latfalla]]></dc:creator>
            <pubDate>Wed, 15 Jun 2022 12:19:01 GMT</pubDate>
            <atom:updated>2022-06-15T12:19:01.593Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dvuUUDEaeYcasKnt85BFSw.jpeg" /></figure><p>AWS is amazing, the services and the interconnection parts make it fun and really enjoyable to work with, even for fun projects like this.</p><p>Do you want to try it? <a href="https://github.com/imohd23/voice-to-infra">Click here</a></p><p>So, I was bored and decided: I want to launch EC2 with voice! Pretty simple. The diagram will show you how:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*ZaJnroRDWIoeMZlXAcB-HA.png" /></figure><p>The diagram shows the whole story, but lets describe it a bit.</p><p><strong>1- The record:</strong></p><p>The first step is to create a unified statement that you want your transcription job to turn into text, which will be processed by the function.</p><p>For this example, I used a website to record my voice and to download it as mp3.</p><p><strong>2- Upload the file:</strong></p><p>Once I got the record, I uploaded it into S3 and let it work. I configured my bucket to send S3 payload into Lambda that I created to deal with what gets passed from this bucket action.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3rxnOuPmh1pCoTKiZOG72A.png" /></figure><p>Then, Lambda and Transcribe time come.</p><p><strong>3- Lambda time:</strong></p><p>Once the payload triggers the function, I get what I need from the payload to pass it into Transcribe. These are straight forward steps.</p><p>I let it to identify the language because I didn’t know the recorded voice will be with which accent. If I recorded it with my accent, I believe it will get a hard time understanding the Arabic accent of my English.</p><pre>transcribeJob = transcribe.start_transcription_job(</pre><pre>                TranscriptionJobName=transcribeJobName,</pre><pre>                Media={<br>                     &#39;MediaFileUri&#39;: &#39;s3://&#39;+bucketName+&#39;/&#39;+fileName<br>                       },<br>                IdentifyLanguage= True<br>)</pre><p>Then, waiting for Transcribe to finish its job.</p><p><strong>4- Transcribe:</strong></p><p>Transcribe is a fast service, despite that my record is short, the response you get is relatively fast.</p><p>So, I get the job status and look for `TranscriptionJobStatus`. Once I get `Completed`, I get the link that holds the text for my job.</p><p>This is an example from the console:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z1YwuYgQTW76Qare0wYSlQ.png" /></figure><p>I do some basic verification over the words as I set the function to get some keywords like Create and Option to identify the action I want to do.</p><p>The next step is to check the resource that I want to make. I hardcoded it as I did the minimal for this example. But, as always, the sky is the limit.</p><p><strong>5- Creation time:</strong></p><p>Once all the previous steps are done, I loop over the pre-config list that I made and get the parameters to pass it into the command. In my case here is creating an EC2 instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nYnEJmVDOTOiMnRA38SnAg.png" /></figure><p>And here you go, an instance got created because of a voice record.</p><p><strong>To conclude:</strong></p><p>There are many things you can do with event-driven architecture. This is a small, fun, waste of time for some, but great evidence that this kind of architecture is powerful. I did lambda execution via SMS before and it was fun. Check it out if you’re interested in this kind of unusual actions with AWS Lambda.</p><p><em>More content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><em>. Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a><em> and </em><a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><em>. Check out our </em><a href="https://discord.gg/GtDtUAvyhW"><strong><em>Community Discord</em></strong></a><em> and join our </em><a href="https://inplainenglish.pallet.com/talent/welcome"><strong><em>Talent Collective</em></strong></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=14319200abc" width="1" height="1" alt=""><hr><p><a href="https://aws.plainenglish.io/how-did-i-create-ec2-by-voice-14319200abc">How Did I Create EC2 by Voice?</a> was originally published in <a href="https://aws.plainenglish.io/">AWS in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Is AWS Lambda Good for ETL Jobs?]]></title>
            <link>https://aws.plainenglish.io/is-aws-lambda-good-for-etl-jobs-68685786bf8e?source=rss-797cc3a8347b------2</link>
            <guid isPermaLink="false">https://medium.com/p/68685786bf8e</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[articles]]></category>
            <dc:creator><![CDATA[Mohamed Latfalla]]></dc:creator>
            <pubDate>Thu, 12 May 2022 10:13:06 GMT</pubDate>
            <atom:updated>2022-05-12T10:13:06.625Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*IcQEYWxOO0Oyz0d65K8knA.jpeg" /></figure><p>ETL stands for: “Extract, Transform, Load”, which is the process of dealing with a series of data in a computing unit.</p><p>Since AWS Lambda is a computing unit, cheap to use, and versatile with what you can achieve or combine with, makes it an appealing option for this kind of jobs. But does it?</p><h3>1- What ETL Jobs need to finish successfully?</h3><p>Let’s assume that you have an excel sheet with a huge amount of rows along with a respectful number of columns, and you need to clean, transform and store these rows in a specific order or shape. You need to have certain components to achieve this task.</p><p>AWS Lambda provides these sets by being able to connect with storage services like S3, Glacier. Also, you can use EventBridge to create a series of actions that fits with the custom schemas you’ve configured. DynamoDB gives the ability to use NoSQL option that provides a pretty fast DB connectivity. SQS for queueing the data into the function, and catch the unprocessed data for later adjustment in the DLQ.</p><p>So, we can assure that the underlying architecture and connectivity is there for Lambda to do the job.</p><h3>2- Only Lambda can do the job?</h3><p>Of course NO. AWS has another service that called Glue, which is a Data Integration service that built to do these type of operation. It has its own set of features and options. But it cannot be compared to Lambda when it comes to the connectivity. Lambda has more options. Yes Lambda is a computing unit and Glue declared as Data Integration service. But, what we’re doing here is to compare the use case itself, not the limitations.</p><p>What can be done in Lambda, can be done in any EC2 family. You just need to find the right family to do the job. But, keep in mind that EC2 is a customer managed service, you have to take care of.</p><p>One small comment here, if your ETL is consuming a lot of CPU, do not use T family.</p><p>Another point I want to clarify that with what Lambda can utalize, it can recover the job if an issue comes to the code like unexpected data type like a difference in datetime format. Lambda can redirect these rows into DLQ which can work as a net that catch the uncommon data rows. This connectivity isn’t presented clearly in other services that might made you rerun the whole file after fixing the code manually. Trust me I’ve been there.</p><h3>3- Advantages vs Disadvantages:</h3><p>Let’s start with with the disadvantages:</p><ul><li>Time: you cannot run the job normally for more than 15 minutes. It needs more than that to split the file, run many functions and maintain the passed data integrity.</li><li>Power: it is very limited to what you can allocate, it is hard to know the right amount of memory to allocate which comes to CPU allocation.</li><li>Misconfiguration: since its a computing unit, your code might be the misconfiguration. Using the wrong function in your code could lead to many issues which affects the allocation of memory and create bottleneck.</li></ul><p>Let’s lift the spirit a bit:</p><ul><li>Less configuration: Since its a managed service, you don’t need to think about the availability of service, or if any other process will use the computing power that you need for your job. It’s all taken care of.</li><li>Ready runtimes: If you need to use python, just select it and all needed tools, services are ready to be used. As simple as that.</li><li>sidekick services: You can use a lot of services to help you achieve the goal easily. Thanks to the SDK.</li></ul><h3>So, the question is does it work for ETL?</h3><p>The answer is: <strong>it depends.</strong></p><p>It depends on what are you doing, what are the expected outcome and how are you utalizing it. It can be very costly if you’re using a lot of surrounding services. Or your code it taking a long time to run. All these factors can influence your decision.</p><p>There are no perfect services for ETL. There are services can do the job. Do you know what kind of job is needed to accomplished? Can you picture the process? Then you can answer this question.</p><p><em>More content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><em>. Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a><em> and </em><a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><em>. Check out our </em><a href="https://discord.gg/GtDtUAvyhW"><strong><em>Community Discord</em></strong></a><em> and join our </em><a href="https://inplainenglish.pallet.com/talent/welcome"><strong><em>Talent Collective</em></strong></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=68685786bf8e" width="1" height="1" alt=""><hr><p><a href="https://aws.plainenglish.io/is-aws-lambda-good-for-etl-jobs-68685786bf8e">Is AWS Lambda Good for ETL Jobs?</a> was originally published in <a href="https://aws.plainenglish.io/">AWS in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create Lambda Layers in AWS Lambda]]></title>
            <link>https://aws.plainenglish.io/create-lambda-layers-in-aws-lambda-83f0b1aef471?source=rss-797cc3a8347b------2</link>
            <guid isPermaLink="false">https://medium.com/p/83f0b1aef471</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[lambda]]></category>
            <category><![CDATA[automation]]></category>
            <dc:creator><![CDATA[Mohamed Latfalla]]></dc:creator>
            <pubDate>Wed, 29 Dec 2021 12:46:51 GMT</pubDate>
            <atom:updated>2021-12-29T12:46:51.258Z</atom:updated>
            <content:encoded><![CDATA[<h4>A guide on how to create Lambda layers in AWS Lambda.</h4><p>For a while, I struggled when it comes to making layers for my functions. I used to download them locally, zip them, upload them into S3 when their sizes are big, and then create a version. This process takes a long time and the changes you make to a defective layer are high when you’re using Windows or Mac because of some layers that compile binaries when you download them.</p><p>I wrote an article back in 2019 on how to do that with the help of Docker.</p><p><a href="https://aws.plainenglish.io/how-to-compile-resources-for-aws-lambda-f46fadc03290">How to Compile Resources for AWS Lambda?</a></p><p>Since then, I still get reads for it. Which triggers the need to create a new simple and extremely fast way to use this amazing feature, Lambda Layers.</p><p>I will walk you through what it does and how you can have it in your account. Please note that this process is only (currently) for <em>Python3.8</em>.</p><h3>What is does?</h3><p>This script consists of 3 main steps: Create a new layer, update the existing one, and read what’s inside your latest layer version.</p><h4>Create a new layer:</h4><p>Because of the struggle I mentioned at first, this process is time-consuming when it comes to the manual, traditional way. So, with providing some key information, the script will create the directory structure, install the libraries with <em>PIP, </em>calculate the direct size to prevent exceeding layer limit, zip it, upload it into newly created S3 bucket (or existing if you have one), and finally, publishing the new layer.</p><p>these steps are the minimal that you can do to create a new layer. Please note that some values are hardcoded, it can be easily made dynamic but it&#39;s out of the scope (currently).</p><h4>Update existing layer:</h4><p>Because managing an existing layer could be hard, as you will need to do many steps to maintain the existing libraries and add new ones. This script will get the referenced zip file of the latest version of your layer, download it, add to it, upload it into S3 again, and publish a new layer version.</p><h4>Read Layer content:</h4><p>Because of the problem that log4j made a couple of weeks ago, and what threat can existing resources made if they were got affected, you will need to monitor your resources and update them accordingly. This action will get the latest layer version zip file, extract it, use <em>PIP </em>to check what’s inside and which version you have. This could also help maintain supported libraries versions.</p><p>Enough talking, let&#39;s dive into it:</p><h3>Preparation and execution:</h3><p>We will go through the steps in order:</p><h4>S3 steps(if you don’t have one already):</h4><p>1- Login into your AWS account and go to S3.</p><p>2- Create a new S3 bucket, keep it in the same region you work in.</p><p>3- Set it up as you wish, no red lines are here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FZ1KPdckqUtLOJx08ixevw.png" /></figure><h4>Lambda steps:</h4><p>1- Go to the Lambda console and create a new function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BZy1OSFWI4G5pacUT1Tsbg.png" /></figure><p>2- Open the function -&gt; Click on Configuration -&gt; Click on Permissions -&gt; click on Role Name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*juyLl9POa2B--id2aL5cRw.png" /></figure><p>3- Click on Policy Name -&gt; Edit policy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NqmSrDOhVb-WmHvHsCavOg.png" /></figure><p>4- Paste this policy (edit <em>resource</em> as you wish) -&gt; save it.</p><pre>{<br>    &quot;Version&quot;: &quot;2012-10-17&quot;,<br>    &quot;Statement&quot;: [<br>        {<br>            &quot;Sid&quot;: &quot;VisualEditor0&quot;,<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Action&quot;: [<br>                &quot;lambda:ListFunctions&quot;,<br>                &quot;lambda:ListLayerVersions&quot;,<br>                &quot;lambda:ListLayers&quot;<br>            ],<br>            &quot;Resource&quot;: &quot;*&quot;<br>        },<br>        {<br>            &quot;Sid&quot;: &quot;VisualEditor1&quot;,<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Action&quot;: [<br>                &quot;lambda:GetLayerVersion&quot;,<br>                &quot;lambda:DeleteLayerVersion&quot;,<br>                &quot;lambda:AddLayerVersionPermission&quot;<br>            ],<br>            &quot;*&quot;<br>        },<br>        {<br>            &quot;Sid&quot;: &quot;VisualEditor2&quot;,<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Action&quot;: [<br>                &quot;s3:PutObject&quot;,<br>                &quot;s3:GetObjectAcl&quot;,<br>                &quot;s3:GetObject&quot;,<br>                &quot;logs:CreateLogStream&quot;,<br>                &quot;lambda:PublishLayerVersion&quot;,<br>                &quot;s3:ListBucket&quot;,<br>                &quot;logs:PutLogEvents&quot;<br>            ],<br>            &quot;Resource&quot;: [<br>                &quot;*&quot;<br>            ]<br>        }<br>    ]<br>}</pre><p>5- Go to GitHub and get the code -&gt; to copy the whole code in code.py and paste it into your function.</p><p><a href="https://github.com/imohd23/lambda_layer_maker_python3.8">GitHub - imohd23/lambda_layer_maker_python3.8: This is a script to make create, update and ready AWS Lambda layers you have in your account.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*taWBrSvsbXfPqigPwG0_Yw.png" /></figure><p>6- Click on <em>Test </em>and paste this json (all fields are required)</p><pre>{<br>  &quot;layer_name&quot;: &quot;LAYER NAME&quot;,<br>  &quot;s3_bucket&quot;: &quot;YOUR S3 BUCKET&quot;,<br>  &quot;libraries&quot;: [&quot;LIBRARIES&quot;],<br>  &quot;action&quot;: &quot;create_new&quot;<br>}</pre><p><em>NOTE: in the action key, there are 3 valid values: create_new, update, read_only</em></p><p>7- Test the function is what triggers it, give it a try.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6d4czDyvMYmFr-VYmyvoSg.png" /></figure><p>These are proofs of this script execution:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ls1WdGBX62kBVWl09AHQuQ.png" /></figure><p>Feel free to adjust the code as you wish, and let me know if you have any issues.</p><h3>Conclusion:</h3><p>This is a <em>way </em>of doing this procedure, I’m pretty sure you have your own way too. let me know, does it worth it? Do you know how to code in Node.js or Java and wish to see this script take another turn and provide another language&#39;s support? I’ll be thrilled if that happened.</p><p>Stay Safe.</p><p>Thank you for reading.</p><p><em>More content at </em><a href="http://plainenglish.io/"><em>plainenglish.io</em></a><em>. Sign up for our </em><a href="http://newsletter.plainenglish.io/"><em>free weekly newsletter</em></a><em>. Get exclusive access to writing opportunities and advice in our </em><a href="https://discord.gg/GtDtUAvyhW"><em>community Discord</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=83f0b1aef471" width="1" height="1" alt=""><hr><p><a href="https://aws.plainenglish.io/create-lambda-layers-in-aws-lambda-83f0b1aef471">Create Lambda Layers in AWS Lambda</a> was originally published in <a href="https://aws.plainenglish.io/">AWS in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Secure an AWS Serverless Application]]></title>
            <link>https://aws.plainenglish.io/how-to-secure-your-aws-serverless-application-ddf81c591095?source=rss-797cc3a8347b------2</link>
            <guid isPermaLink="false">https://medium.com/p/ddf81c591095</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Mohamed Latfalla]]></dc:creator>
            <pubDate>Thu, 08 Jul 2021 04:51:21 GMT</pubDate>
            <atom:updated>2021-07-17T21:25:51.172Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zXC2C4Jy-8zh05p7ZD-JkA.jpeg" /></figure><p>Security is no joke, one of the key things you have to visit whenever you’re architecting a new serverless application.</p><p>Serverless application is basically an idea, like any other application, that you have and it has a logic. You need a computing power to execute your logic, an object storage in case you need it, a place to store your information and a way to tell your logic: go go go!</p><p>Pretty simple!</p><p>The beauty of Serverless is that we don’t care where and why our logic got stored the way it does, although Information Security teams would get really mad if they read this statement. Anyway, what really matters for us as a cloud developers, as I like to name ourself, is that our logic is getting executed, customers are happy, win-win situation!</p><p>But, I wish it was that way. We all need to care about our own applications security. Some people would say: Security! Hack! We got exposed! Well, sometimes these things happen. But, you as a cloud developer, can help preventing this from happening. Let’s dive into it together shall we?</p><h3>Standard Services</h3><p>Most basic Serverless applications would need the following services:</p><ol><li>Execution endpoint -&gt; API GW</li><li>Object storage -&gt; S3</li><li>Computing unit -&gt; Lambda</li><li>Records storage -&gt; DynamoDB</li></ol><p>Of course you can have more than this, but let’s keep focusing on the main parts that shape the basic Serverless application.</p><p>All these services are managed by AWS, in case of batching, updating or deprecating runtime, scaling services based on our usage. All the major tasks are handled by them. Which is the soul of this architecture, focusing on developing and leaving operation tasks for them. Which I’m really fine with. But they can’t do the job without us, the cloud developers.</p><p>We have to care about our applications. We must secure it, which in fact, is pretty simple.</p><p>Securing your Serverless application starts at the beginning, best practice.</p><p>Wait, are you telling me that if I followed the best practice per service, that would secure my application? Yes!</p><p>Let’s take a closer look on some of these steps per service.</p><h3>API Gateway (API GW)</h3><h4><strong>Use WAF</strong></h4><p>AWS provides a service called WAF, which is a Web Application Firewall. Self explanatory name that tells you why to use this service. It provides a protection against harmful usage of your resources that might affect the availability of your application and consume its resources, which will lead to interrupting the usability of the application .</p><p>Use WAF to monitor your API GW executions and act based on specific metrics. Using pre-defined roles would save you time planning and testing techniques to prevent common online threats.</p><h4><strong>Configure Endpoint Throttling</strong></h4><p>You know your application and your customers, if an endpoint is getting unusual executions, this means that there is something wrong. Setting up throttling threshold would stop the exhaustion of your resources, especially if this endpoint is executing Lambda, which will visit in a minute.</p><h4><strong>Validate Your API GW Execution</strong></h4><p>One of the major risks in Serverless applications is broken-authentication. If your endpoints are being called and consumed by unauthorized actor, this means you’re in a big trouble.</p><p>Use services like AWS Cognito to authenticate the executer. In this case, you would have a better understanding about your customers and to insure that no one will execute a function that he’s not supposed to.</p><h3>S3</h3><h4><strong>Block Public Access (in some cases)</strong></h4><p>If you’re hosting sensitive data like identity cards, passports, secret reports, you have to block public access to this bucket. This will prevent any attempts to expose your files.</p><p>But, this recommendation won’t work if you’re hosting publicly available data in your bucket as it needs public access. Yes, there are some other options to share these files publicly while it’s publicly blocked. But, why the hassle? If you reached this point, you need a help on your S3 strategy.</p><h4><strong>Encrypt At-Rest And On-Transit Files</strong></h4><p>The main 3 operations against S3 are: putting object, store it and eventually retreive it. So, to do these 3 operations securly, consider the following:</p><p>To upload securely into S3, use presigned url for that. The reason for it is that you, as a cloud developer, allow PUT action into a specific bucket for a specific file. In this way, you give the API an authority just to do a single action on a single file. Less privilege less concerns.</p><p>To store the file, you have to enable server-side encryption. This recommendation comes from AWS themself as they advice this move to enhance the security level and privacy. Also, it comes with no additional cost. Cool right?</p><p>To share the file, consider the presigned url, the same concept as upload. When you generate a presigned link for sharing a file, it gives you a url that consist of object path and an access token that is valid to retrieve only that specific file for a period of time. Once it gets expired, it is unuseable.</p><h4><strong>IAM Role Access</strong></h4><p>Creating an IAM role is really one of the best “best practice” actions that you as a cloud developer needs to enhance. For S3 case, creating one with specific actions would limit the level of S3 bucket/content exposure.</p><p>Create a role that has the specific action on the specific bucket. Why? Because this will make sure, even in case of compromised access, that this access won’t cause a great harm on your data.</p><h4><strong>Bucket Policy</strong></h4><p>Bucket policy is a list of rules that guards the bucket from misused intentionally or unintentionally. I had a hard time understanding this concept and some examples need articles to describe but lets summaries it in the next example:</p><p>You have a bucket that can accept files generated only from any resources that is deployed in “Core-Production-VPC”. Usually we guard our bucket with an IAM role, but in this case, it’s not the suitable thing as anyone who can have an IAM role allowing actions against this bucket will be able to perform actions against it. So, we create an S3 bucket policy that can accept PutObject only from “Core-Production-VPC”.</p><p>Who will win? IAM role or Bucket Policy in this case? Well, it’s a combination of both. If your IAM role has an access to this bucket, the call to this bucket will pass through. But, if you don’t fulfilled policy requirements, then sorry, you can’t PutObject in it.</p><p>Really cool way to make sure you don’t have misconfiguration or misuse from IAM roles.</p><h3>Lambda</h3><h4><strong>One IAM Role Per Function</strong></h4><p>Lambda has an access to many services and when you use SDK, oh man, you have them all! So, should you be happy? NO, because the risks are countless.</p><p>So, let’s focus on this as its really important point. Less privilege less concerns. AWS advice that you limit your function with a unique, sophisticated IAM role privileges. In this case, you can be sure that this function won’t cause unexpected harm as its boundary is well defined and known. One of the new security risks is Event Injection. Did you test your function well? Think twice.</p><h4><strong>Temporary Credentials For AWS Access</strong></h4><p>As we said in the previous point, Lambda can access almost all your AWS resources. Tell this information to your Information Security team and run away! So, How to set its access boundaries ? In API GW section, we talked about authorization, and yes it applies here. You have an application that one of your customers stores data into DynamoDB. You generate a short living token to be used from this customer with the specific target. Once the time comes, the access is revoked. Simple and affective.</p><h4><strong>Limit Execution Duration</strong></h4><p>When it comes to execution duration, it comes to what you actually pay AWS. As Lambda is pay-as-you-use, you need to know what you’re paying for.</p><p>One of the concerns is that if your functions are under DDoS attack (which is not good), your function will be running all the time. This has a financial and usability impacts. But, to reduce the affect from these kind of attacks is to limit execution duration to what your tests show. Test the function, know how long usually needs, and set it as a hard limit for your team. Function will timeout and will free up the resources. But, this would make a bigger attack rates? Not necessarily as you might face a small amount of load, which can reduce the amount of affected customer. How?</p><p>Ok, if you’re under attack, your resources are bing executed in a high rate calls, which could make them busy. To avoid that, to a certain rate, limit the execution. This will result to quickly release them and free up the place for “some” customers calls. It seems not to be a great option but if the attacker reached the functionality level, you don’t have that much of options. Do you?</p><h4><strong>Coding Best Practice</strong></h4><p>Your coding practices can have a great impact on your security. How? Let’s find out.</p><p>Let’s assume you have a wrong IAM role attached to your function, and you’re using a 3rd party library that has vulnerabilities, guess what can happen? Always choose a trusted 3rd party libraries.</p><p>If you have a gigantic function that had an enormous payload. The passed payload has an event injection script and you didn’t validate it. Man you’re doomed. Always validate your payload.</p><p>I can keep writing about this section forever. But I believe the message received. Best practice can save you from threats.</p><h3>DynamoDB</h3><h4><strong>Encrypt At-Rest Data</strong></h4><p>So, when you have an important data that you need to store in your table, like sensitive information about the clients, or your customer business secrets, you defiantly need to encrypt them in your table. The reason is to protect these data from unauthorized access via your API or even from your developers! Yes, sometimes the risk can come from inside.</p><p>How to store your keys? Well, you have many options, like System Manager, Secret Manager or in your lambda environment variables.</p><h4><strong>IAM Roles to Access DynamoDB</strong></h4><p>This point is not new, you have to lock the access into your tables with IAM role. In this case, you, as we described earlier, can insure no function will do anything that is not supposed to do, which will decrease the surface of potential harm from your functions that could be a victim to any Event Injection attack.</p><h4><strong>VPC endpoint to access DynamoDB</strong></h4><p>If you have functions that get deployed within a specific VPC and only these are being able to access a specific table, you can setup a policy that allows the access from only the wanted VPC. Cool! This also will decrease the attack surface as if one of your functions that belongs to another source got compromised, you’re good to some extend as not everything in DynamoDB will be exposed to the attacker.</p><h3>Summary</h3><p>So, to summarize, following these steps “will” enhance your Serverless application security as you cover most of the main points. As you can see, these are really not hard steps. It has a lot of documentation behind it and it will enhance the team standards. It is a win-win situation.</p><p>Stay Safe!</p><p><em>More content at </em><a href="http://plainenglish.io/"><strong><em>plainenglish.io</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ddf81c591095" width="1" height="1" alt=""><hr><p><a href="https://aws.plainenglish.io/how-to-secure-your-aws-serverless-application-ddf81c591095">How to Secure an AWS Serverless Application</a> was originally published in <a href="https://aws.plainenglish.io/">AWS in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I Processed 558k Transactions on AWS Lambda in 5 Minutes]]></title>
            <link>https://aws.plainenglish.io/how-did-i-processed-half-a-million-transactions-in-aws-lambda-within-minutes-120c69d37ce5?source=rss-797cc3a8347b------2</link>
            <guid isPermaLink="false">https://medium.com/p/120c69d37ce5</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Mohamed Latfalla]]></dc:creator>
            <pubDate>Wed, 23 Jun 2021 05:55:17 GMT</pubDate>
            <atom:updated>2021-07-10T10:11:51.417Z</atom:updated>
            <content:encoded><![CDATA[<h4>How I processed over 500 thousand AWS Lambda transactions in 5 minutes</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*rq_wm-LGJGYs2ZUWY0yeXQ@2x.jpeg" /></figure><p>Processing data could be an intensive task, especially on the computing units as the read and write operations takes a lot of resources. Luckily, if you have the right tools, you can achieve it easily. But, is it worthy? Let’s find out.</p><p>In this article I will share my experience with you on how did I achieved that. It is really simple and complicated at the same time. Why? Because of how Lambda works and what you have to think of when you “Code” because that really makes a difference.</p><h3>Why did I thought about it?</h3><p>Few years ago, my manager told me to think about a processing architecture to process BIG volumes of records but not that heavy operations. Like 800k rows of data, with 16 columns, that the amount of work needs to be done over each row isn’t complicated. So, Event-Driven Architecture!!</p><p>I went through a lot of issues on how to deal with the limited resources in Lambda and how to deal with my records dropping because of timing out and OS errors. S3 was another story also to learn how to tune it for my use-case. A dear friend who works as senior consultant in AWS Bahrain helped me getting some tools in place to achieve this promising idea. It was one of the best experiences I ever got dealing with AWS resources.</p><p>Enough talking let’s get some diagram in place.</p><h3>Solution Diagram</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/396/1*e7MNsZnSRCU7fssSJh6qPg@2x.jpeg" /></figure><p>Diagram looks scary? Trust me, it isn’t.</p><p>Let me break it down for you in some steps:</p><h4>1. Initiate the process</h4><p>Because I’m adopting Serverless architecture, it means Event-Driven events that if something happened, things will act based on it and the results will trigger another actions, till the end of the process.</p><p>So, in our case is S3 Put request. When we upload the file into S3, it will put the file inside a bucket and when the file fully uploaded into it, Lambda will get triggered with S3 payload. Our first step just got finished. Whats next?</p><h4>2. Clean data</h4><p>Because we got a csv file, some columns and rows could contain spaces, some special characters that MIGHT break your code. So, clean it up.</p><p>Cleaning these records will prepare it to be ready for insertion. But, since we have a lot of records and the function might fail, how to track what was added and what left over?</p><h4>3. Add clean data into a queue</h4><p>We will add the cleaned records into a queue. The reason is to track what has been added and what did not got added. Basically, SQS will act as an organizer. It will send small batches into Lambda, Lambda will add it into DynamoDB, then it will return success message to SQS to remove it from the queue.</p><p>What will happen in case of failed record is SQS will retry 3 times, as per my configuration, to try insert operation. If these 3 tries failed, then it will move it into Dead Letter Queue (DLQ) which is another SQS queue that have the failed records. Then, you can debug why these records never make it into DynamoDB and can be processed again or even reject it.</p><h4>4. DynamoDB</h4><p>Because we are trying to process massive chunks of data, we need some sort of Database that can handle the extreme load or records. DynamoDB solves this issue. There were a lot of experiments on how to handle the number of records and how to behave with the limited read/write throughput as write can handle 1kb data per unit. So, DynamoDB on-demand solve the issue.</p><p>As per AWS documentation, using on-demand DynamoDB throughput is the option when you cannot predict your workload. Because it will prepare the max throughput just in case its needed.</p><p>We moved the records from csv to DynamoDB, then what?</p><h4>5. Stream records to SQS</h4><p>DynamoDB is really good event executer for Lambda. When you enable Stream, you can specify a Lambda function that react to your passed payloads from it. The good thing is you need to act based on type of record. We are dealing now with the newly added records. So, when we verify the tag, we add the record into another SQS.</p><p>The reason for this queue is the consistency of records delivery. You are adding the record once, capture it and add it into the queue so you can deal with it. If not, then you have to scan the table to get unprocessed records and process them. Why the hassle? Let the queue deal with it.</p><h4>6. Process data</h4><p>We reached the latest stages of record lifecycle in this architecture. When it reaches the Process Queue, it pass the records in batches, process them, and then pass them to another queue. As I clarified earlier, for consistency purposes.</p><h4>7. Update the processed record</h4><p>Finally, the record will be grabbed from the Finished queue and passed into the Lambda function that will update the record with the processed information. If records failed to be passed, DLQ will gather them for your further debugging and actions.</p><h3>Challenges</h3><p>These points seems to be a straight-forward scenario, BUT, its not. Let me walk you through some problems and how it got solved.</p><h4>1. Lambda Lambda Lambda</h4><p>Lambda is the key player here, we have limited time to execute the logic in your code. How can you insure the records were red from the file, cleaned, and added into the queue? Its hard but what you will need is speed. I code in Python and I used Multiprocessing library to speed things up. I used Multiprocessing Process function to use every single possible processing unit in Lambda. This action made my process to clean (in some tests) 558k transaction in 1:30 min! It was really fast. Again, it is not straight-forward scenario. Lambda can handle around 500 process when you allocate the max memory. Any other process will raise “OS Error 38: too many files open”. Why did I faced this issue? Because I joined all running processes and it was not closing finished processes. So, I run half the batch and loop over the running processes. If it finished, I force it to close. Problem solved.</p><h4>2. Keep an eye on CloudWatch</h4><p>I made a big mistake by passing event variable into CloudWatch even when I was running the big batches. This resulted to write 6.6TB of data because of my many tests. The price of CloudWatch put log action is expensive so use it wisely.</p><h4>3. DynamoDB on-demand is the keyword</h4><p>I started my configuration with making my DynamoDB provisioned, which is something for predicted workload. I made it 5 read and write throughput and that was an issue. I faced the issue that out of 558k records, only 1k was inserted into my table. I raised it into 100 throughput and still at least 60% out of the file get lost and not added! Then I reread the documentation and noticed my issue, DynamoDB on-demand is the solution for unpredicted load. I added all the 558k+ records within 5 min! Pretty FAST!</p><h4>4. SQS can be tricky</h4><p>SQS is a great service and has a lot options and opportunities. But, you need to know what is the size of the batch you’re passing every time and what is the predicted time for your batch to finish. The reason for that is when you tell SQS to wait x seconds before making this batch available again, it might get processed multiple times. Know your code and your data, test test test and then configure it for heavy workload.</p><p>These points were my top concerns, S3 was interesting but not that complicated as I expected. But the main question, does it worth it?</p><h3>Conclusion</h3><p>Everything in this life depends on conditions, if you don’t want to manage instances or you want it with the minimal effort then yes, this scenario is valid for you. Keep in mind that debugging these use-cases can be tense because of how connected and how one mistake in one step can affect the coming steps.</p><p>Stay Safe.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=120c69d37ce5" width="1" height="1" alt=""><hr><p><a href="https://aws.plainenglish.io/how-did-i-processed-half-a-million-transactions-in-aws-lambda-within-minutes-120c69d37ce5">I Processed 558k Transactions on AWS Lambda in 5 Minutes</a> was originally published in <a href="https://aws.plainenglish.io/">AWS in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Deploy a Full Environment for WordPress via Docker using Terraform]]></title>
            <link>https://aws.plainenglish.io/how-to-deploy-a-full-environment-for-wordpress-site-via-docker-by-using-terraform-73c84624fd52?source=rss-797cc3a8347b------2</link>
            <guid isPermaLink="false">https://medium.com/p/73c84624fd52</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Mohamed Latfalla]]></dc:creator>
            <pubDate>Mon, 28 Dec 2020 13:23:10 GMT</pubDate>
            <atom:updated>2021-07-19T07:52:15.584Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oJRXWRAKtfnQ8Qf6McyvnA.png" /></figure><p>For many users, preparing an environment in AWS to host their website/system was tough, especially if you were new to Cloud.</p><p>Also, even after doing the preparation, the creation of resources might take a while too! But, what if you can do the following within the 20-minute window? Check out the list:</p><ul><li>Create a VPC and all essentials for public and private subnets.</li><li>Create an EFS and prepare an access point to this storage option.</li><li>Create a launch template to replicate your configuration into multiple EC2s in different subnets.</li><li>Prepare your website as Docker image to have consistent replica of your main concern (your website and its DB).</li></ul><p>It feels wired right? Actually no, because this is the beauty of IAC and Terraform. Why don’t we go deeper? Prepare your swimming suit.</p><blockquote>NOTE: This is a POC script and got tested, yes it can be better but for the article purpose, I guess this is a good starting point.</blockquote><h3>What you will get?</h3><p>Check the image below, do not get tricked yet, wait for the clarafications:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*Fy_zrmlx6QqpCECqyubVHw.png" /></figure><p>After you run the code “ as it is”, you will get a load balancer placed in one of the public subnets, one EC2 machine that got deployed by Auto Scaling Launch Template and EFS.</p><p>These things are enough to run your website, at least for this use case that I am talking about.</p><p>But what actually happened when I run the script is the following:</p><ul><li>For VPC, the script will make a VPC, subnets (public and private), routing tables and internet gateway.</li><li>For Auto Scaling, the script will make a launching template with what is needed to replicate the configuration into multiple instances as it required and will make sure that the minimum required instances are always meet the configuration.</li><li>For Load Balancer, the script will prepare an endpoint associated with health check metrics.</li><li>For EC2, the script will launch an instance from the configuration script that got attached to the Auto Scaling launching template, this will install and setup Docker inside the machine and will pull the project from GitHub.</li><li>For EFS, the script will create all needed resources like security group, access point, and access point attachment for this storage.</li></ul><p>Is that too much? I guess not, some other systems need a lot more. But, let us agree on one thing, doing all these things in 20 min manually is exhausting.</p><h3>The steps of deployment:</h3><p>It is really easy and needs few clicks, let us start, shall we?</p><p>Before we start, clone this <a href="https://github.com/imohd23/Terraws-script">link</a>.</p><p>1- Do you have Terraform installed?</p><p>First thing first, check if you have Terraform installed in your machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/594/1*S97uQprIZMi98Xlyjn7lJw.png" /></figure><p>2- Do you have your AWS credentials?</p><p>Because we are going to deploy this instruction to AWS, make sure one of these two options are available:</p><ul><li>AWS CLI is configured, So you should only know which profile will use in case of multiple configurations are placed.</li><li>AWS access and secret keys, because of course, we need credentials to access.</li></ul><blockquote>NOTE: Check provider.tf once you decide which connection to use.</blockquote><p>3- Some necessary commands.</p><p>Open a terminal window and navigate into the project.</p><p>Because we are going to make a new instance and we might need to access the instance, so run these commands.</p><pre>ssh-keygen -t rsa -b 4096 -C &quot;your_email@example.com&quot; -f $PWD/id_rsa</pre><blockquote>NOTE: Do not change the key name unless you go to vars.ft and change it there also.</blockquote><p>Then, run this command to get all needed modules:</p><pre>terraform init</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*bsAnguY71Hs96DMjEqMv6g.png" /></figure><p>4- Trigger the script.</p><p>There is only one step left, maybe two if you want to check what will happen.</p><p>To check what are the resources that will be created, run this command:</p><pre>terraform plan</pre><p>To bring all these planned resources to the life, run this command:</p><pre>terraform apply</pre><p>After all resources get aligned in the correct order, a message will ask you to approve these changes, type yes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/405/1*Qp2UP47c6XnrbdGSTa4fsQ.png" /></figure><p>And now you can relax till the whole process is finished.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/453/1*Cq5kfqNzuuirmMB46wwGIQ.png" /></figure><blockquote>NOTE: After Terraform script is done, please wait 5–10 min before checking the website, the reason is that the infrastructure is done but the instance script is in progress. EFS mounting needs some time to be done.</blockquote><p>To clean everything, run this command:</p><pre>terraform destroy</pre><h3>Important points:</h3><p>1- Why EFS in this simple use case? Because I am using Docker to host the website and DB all together, and you have an auto-scaling launch template, EFS should insure the consistency of your DB because the DB has a volume pointed into EFS. Any new instance will use EFS as volume.</p><p>2- At the end of the script execution, Terraform will return an ELB link and this will not work directly. Why? Because WordPress&#39;s first initial page is going to be /admin to finish all needed configuration. So, go to aws console -&gt; EC2 -&gt; your created instance and visit its public IP to finish the setup. Then all going to be good.</p><h3>Summary:</h3><p>I don’t know if this process is going to be helpful for anyone, but since I know how to make it, why not share it?</p><p>Creating a full basic environment in AWS can be difficult, especially for newcomers to this platform. This script will give them few important points to think about and show why using Docker is a really good option, why using Terraform is not hard, and finally, why IAC is something they need to work on.</p><p><em>More content at </em><a href="http://plainenglish.io/"><strong><em>plainenglish.io</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=73c84624fd52" width="1" height="1" alt=""><hr><p><a href="https://aws.plainenglish.io/how-to-deploy-a-full-environment-for-wordpress-site-via-docker-by-using-terraform-73c84624fd52">How to Deploy a Full Environment for WordPress via Docker using Terraform</a> was originally published in <a href="https://aws.plainenglish.io/">AWS in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>