<?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 Hoang Le on Medium]]></title>
        <description><![CDATA[Stories by Hoang Le on Medium]]></description>
        <link>https://medium.com/@hoangleitvn?source=rss-a579329b14f9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*IfVpAbyDDBL1aq-qIXe2rQ@2x.jpeg</url>
            <title>Stories by Hoang Le on Medium</title>
            <link>https://medium.com/@hoangleitvn?source=rss-a579329b14f9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 18:13:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hoangleitvn/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[Continuous Delivery — Deploying a Node.js app to AWS EC2 using Ansible]]></title>
            <link>https://medium.com/innomizetech/continuous-delivery-deploying-a-node-js-app-to-aws-ec2-using-ansible-39bdab26f02a?source=rss-a579329b14f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/39bdab26f02a</guid>
            <category><![CDATA[ansible]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[how-to]]></category>
            <category><![CDATA[aws-ec2]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Hoang Le]]></dc:creator>
            <pubDate>Mon, 03 Feb 2020 03:50:11 GMT</pubDate>
            <atom:updated>2023-07-28T01:38:44.255Z</atom:updated>
            <content:encoded><![CDATA[<h3>Continuous Delivery — Deploying a Node.js app to AWS EC2 using Ansible</h3><p>The main key point for all our projects is trying to automate all things, it helps to reduce errors (e.g. human mistake), fast and easy to deploy / rollback, and improves customer satisfaction.</p><figure><img alt="Continuous Delivery and Automation are Key" src="https://cdn-images-1.medium.com/proxy/0*RBJGZPYN8d8R2BuB" /><figcaption><a href="https://www.google.com.vn/url?sa=i&amp;source=images&amp;cd=&amp;ved=2ahUKEwiJ2rKF0bfeAhXYaN4KHcZ_D8QQjhx6BAgBEAM&amp;url=https%3A%2F%2Fwww.slideshare.net%2Fdcjuengst%2Fcloudbeesjenkinsplatform2016&amp;psig=AOvVaw1RxLgKUvrZis9gBgTe1LLi&amp;ust=1541314216834361">Images Sources</a></figcaption></figure><p>We do have some approaches to automate the deployment process that we have been applying to our projects such as using <a href="https://aws.amazon.com/elasticbeanstalk/">Amazon Elastic BeanStalk</a> or <a href="https://aws.amazon.com/ecs/">Amazon Elastic Container Service</a>. However, in some cases, our customers don’t want to use those approaches because they don’t use AWS, they’ve already had the servers to run the app, and they want to keep their app on their On-Prime Data Center and have their IT guys manage it. It led us to have to find out another approach to automate our delivery process. And we have chosen Ansible as the tool to implement our Continuous Delivery pipeline.</p><p>So I would like to write this article to share with you and outline our workflow and provide a brief introduction along with sample code to build this flow.</p><h4>The Tools</h4><ul><li><a href="https://jenkins.io/doc/">Jenkins</a>: Jenkins is a self-contained, open-source automation server that can be used to automate all sorts of tasks related to building, testing, and delivering or deploying software.</li><li><a href="https://www.ansible.com/">Ansible</a>: Ansible is an open-source automation platform. Ansible can help you with configuration management, application deployment, and task automation. It can also do IT orchestration, where you have to run tasks in sequence and create a chain of events that must happen on several different servers or devices.</li><li><a href="https://slack.com/">Slack</a>: a cloud-based set of proprietary team collaboration tools and services.</li></ul><h4>Why Ansible?</h4><p>As you know, there are a lot of tools for infrastructure automation (infrastructure as code) such as Terraform, Chef, Ansible, Juju, and more. But there are a few reasons that make me select Ansible as below:</p><ul><li>It is very, <a href="https://docs.ansible.com/ansible/2.7/installation_guide/intro_installation.html">very simple to set up </a>and yet powerful.</li><li>Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy. Avoid writing scripts or custom code to deploy and update your applications.</li><li>Automate in a language that approaches plain English, using SSH, with no agents (like Puppet or Chef) to install on remote systems.</li><li>Easy to integrate with our CI/CD pipeline using the Jenkins server.</li></ul><h4>The Steps</h4><p>What we are going to build is the following deployment flow:</p><ol><li>Launch EC2 instance(s) (optional).</li><li>Update OS and install needed dependencies such as install Node.js.</li><li>Deploy the Node.js app to EC2 instance(s).</li><li>Configure DNS (optional).</li><li>Smock test.</li></ol><h4>Let’s code…</h4><p><strong>Project Structure</strong></p><p>When doing any coding stuff, the <em>project structure</em> is one of the most important things I pay attention to. If you have experience working with Ansible, you should know how to organize the Ansible project. I followed the alternative approach mentioned in <a href="https://docs.ansible.com/ansible/latest/user_guide/playbooks_best_practices.html#directory-layout">this</a> article, feel free to select your own approach.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*XDd8mVzdG7WMvJ4N" /></figure><p>My project contains the following root directories/files:</p><ul><li><em>scripts</em>: it contains a shell <em>setup</em> script to install Ansible, Ansible Galaxy, and generate a self-signed certificate to run our Node.js app in secure mode (HTTPS).</li><li><em>cert</em>: directory to keep a self-signed certificate.</li><li><em>ansible</em>: put all Ansible code into this directory including playbooks, roles, var files, etc.</li><li><em>Jenkinsfile</em>: the Jenkins pipeline code for CI/CD pipeline.</li></ul><p><strong>Role</strong></p><blockquote><em>In Ansible, the role is the primary mechanism for breaking a playbook into multiple files. This simplifies writing </em><strong><em>complex playbooks</em></strong><em>, and it makes them easier to reuse. The breaking of playbook allows you to logically break the playbook into reusable components.</em></blockquote><p>Here are the following roles we will use on this project:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/0*06lE-LHgszRKN8ph" /></figure><ul><li><em>apache-server</em>: we don’t use this role on this project but I wanted to keep it here. This role will configure the Apache using our own <em>httpd.conf</em> template file. To install Apache, we can use <a href="https://github.com/geerlingguy/ansible-role-apache">geerlingguy.apache</a> role.</li><li><em>common</em>: put all your comment stuff into this role such as updating your OS to ensure your server(s) are up to date.</li><li><em>launch-ec2</em>: this role to launch EC2 instance(s) to deploy our app.</li><li><em>node-server</em>: contains all needed steps to deploy and run the Node.js app</li><li><em>nodejs</em>: install the Node.js runtime.</li></ul><h3>Conclusion</h3><p>Using Ansible, you can easy to provision and install software to run your application automatically, you can manage your infrastructure as code (IaC). However, running your software is not simple as this demo, you will need to do more things such as setup the network, configure the firewall, and auto-scaling. To do those things, you might need to combine them with other tools. For example, you can use the AWS CDK framework to provide your AWS infrastructure (network, database, EC2 instances, and auto-scaling), then use Ansible to provision your EC2 instances and configure your applications.</p><p>I hope this post will bring some ideas to you to design and deploy your application. If you have any issues or need help, just let me know by adding comments to this post.</p><p>Thank you for reading!</p><p>This post is originally published on <a href="https://innomizetech.com/blog/continuous-delivery-deploying-a-node-js-app-to-aws-ec2-using-ansible">our blog</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=39bdab26f02a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/innomizetech/continuous-delivery-deploying-a-node-js-app-to-aws-ec2-using-ansible-39bdab26f02a">Continuous Delivery — Deploying a Node.js app to AWS EC2 using Ansible</a> was originally published in <a href="https://medium.com/innomizetech">INNOMIZE</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WS re:Invent 2019 announcements Recaps]]></title>
            <link>https://medium.com/@hoangleitvn/ws-re-invent-2019-announcements-recaps-e1af75c3de5a?source=rss-a579329b14f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/e1af75c3de5a</guid>
            <category><![CDATA[announcements]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <dc:creator><![CDATA[Hoang Le]]></dc:creator>
            <pubDate>Fri, 20 Dec 2019 08:29:17 GMT</pubDate>
            <atom:updated>2019-12-20T08:29:17.146Z</atom:updated>
            <content:encoded><![CDATA[<p>If you didn’t have a chance to review all recent AWS announcements on their #awsreinvent2019, you can review this table.</p><p>#aws #cloudcomputing #clouddevelopment #cloudconsulting #cloudengineer #news #announcements #serverless</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Oq9gIYxDhPQGM9N22jaQ9Q.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e1af75c3de5a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A brief summary of JavaScript Learning Path]]></title>
            <link>https://medium.com/innomizetech/a-brief-summary-of-javascript-learning-path-ecaeb2adf285?source=rss-a579329b14f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/ecaeb2adf285</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[how-to]]></category>
            <dc:creator><![CDATA[Hoang Le]]></dc:creator>
            <pubDate>Tue, 17 Dec 2019 10:36:42 GMT</pubDate>
            <atom:updated>2023-07-28T01:39:43.136Z</atom:updated>
            <content:encoded><![CDATA[<h3>A Brief Summary of JavaScript Learning Path</h3><p>JavaScript is a popular language among web developers which gave rise to several frameworks that simplify your code. According to the largest online developer communities, <a href="https://insights.stackoverflow.com/survey/">StackOverflow</a> in their 2019 survey of the most sought-after programming languages shed some light on what to expect in the coming year:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*KLF1hRYGP1R3pzhE" /><figcaption><em>Top Programming Languages in 2019</em></figcaption></figure><p>As you can see, <a href="https://stackoverflow.com/jobs?sort=i&amp;q=javascript">JavaScript</a> is the most commonly used programming language. So how to learn <strong>JavaScript</strong>, how to up-level your programming language skills, and what is the path for learning JavaScript from the beginning? If you don’t know how to get started, then you should read this post.</p><h4>Step 1 — Learn basic and fundamentals</h4><p>Firstly, you need to understand the basic concepts and fundamentals of JavaScript, you can learn from</p><ul><li><a href="https://www.w3schools.com/js/">W3 Schools</a></li><li><a href="https://javascript.info/">Javascript.info</a></li></ul><p><a href="https://github.com/getify/You-Dont-Know-JS">You-Dont-Know-JS</a> is a series of books diving deep into the core mechanisms of the JavaScript language. You should read this to get more overview and advanced concepts of JavaScript such as Scope &amp; Closures, Objects &amp; Classes, Sync &amp; Async, ES.Next &amp; Beyond.</p><h4>Step 2 — Learn modern JavaScript</h4><p>Learning basic isn’t enough, you need to learn more about advanced and modern JavaScript concepts/syntax, it helps you write code efficiently, quickly, and high performance</p><ul><li><a href="https://es6.io/">ES6 for Everyone</a></li><li><a href="https://eloquentjavascript.net/">Eloquent JavaScript</a></li></ul><h4>Step 3 — Coding Style and Convention</h4><p>Coding standards (also sometimes known as ‘Coding Conventions’ or ‘Coding Rules’) are a set of guidelines that a group of developers stick to, to ensure that they all essentially follow the same style.</p><ul><li><a href="https://github.com/airbnb/javascript">Airbnb JavaScript Style Guide</a></li><li><a href="https://google.github.io/styleguide/jsguide.html#features-this">Google JavaScript Style Guide</a></li><li><a href="https://contribute.jquery.org/style-guide/js/">jQuery Style Guide</a></li></ul><p>Read about <a href="https://prettier.io/">prettier</a> and see how to configure it in order to format your code and save time.</p><h4>Step 4 — Review your knowledge</h4><p>Now is the time to review your understanding of JavaScript by answering interview questions</p><ul><li><a href="https://www.edureka.co/blog/interview-questions/javascript-interview-questions/">Top 50 JavaScript Interview Questions You Must Prepare in 2020</a></li><li><a href="https://www.guru99.com/javascript-interview-questions-answers.html">Top 85 JavaScript Interview Questions &amp; Answers</a></li><li><a href="https://www.toptal.com/javascript/interview-questions">37 Essential JavaScript Interview Questions</a></li></ul><h4>Step 5 — Practices</h4><ul><li>Learning JavaScript libraries (e.g. Lodash, ReactJS, Moment, jQuery, Ramda, and a lot more)</li><li>Learn JavaScript Frameworks such as Angular, VueJS, EmberJS)</li><li>Task runner (e.g. Gulp, Grunt) and module bunder (e.g. Webpack, Browserify)</li></ul><h4>Step 6 — Be an expert</h4><ul><li>Continue learning core concepts in JavaScript such as Closure, Hosting, Scope, Coercion, Prototypes</li><li>Learn OOP, <a href="https://medium.com/javascript-scene/master-the-javascript-interview-what-is-functional-programming-7f218c68b3a0">Functional Programming</a></li><li>Read this book <a href="https://addyosmani.com/resources/essentialjsdesignpatterns/book/">Learning JavaScript Design Patterns</a> or <a href="https://www.dofactory.com/javascript/design-patterns">design-patterns</a></li></ul><p>If you want to become a web, backend or full-stack developer, JavaScript isn’t enough, you need to learn more. Check out this roadmap and pick your path <a href="https://github.com/kamranahmedse/developer-roadmap">Web Developer Roadmap 2019</a> and keep yourself up to date.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ecaeb2adf285" width="1" height="1" alt=""><hr><p><a href="https://medium.com/innomizetech/a-brief-summary-of-javascript-learning-path-ecaeb2adf285">A brief summary of JavaScript Learning Path</a> was originally published in <a href="https://medium.com/innomizetech">INNOMIZE</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[07 best practices when using AWS SSM Parameter Store]]></title>
            <link>https://medium.com/innomizetech/07-best-practices-when-using-aws-ssm-parameter-store-63c8e7ab0d9b?source=rss-a579329b14f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/63c8e7ab0d9b</guid>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[parameter-store]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[serverless]]></category>
            <dc:creator><![CDATA[Hoang Le]]></dc:creator>
            <pubDate>Tue, 19 Nov 2019 10:09:12 GMT</pubDate>
            <atom:updated>2023-07-28T01:50:53.279Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/692/1*lRVlnGfb09veHQ3Ef8HMkg.jpeg" /><figcaption><a href="https://blog.hubstor.net/cloud-storage-and-data-encryption-how-businesses-can-protect-information-in-the-cloud"><em>Cloud Encryption</em></a></figcaption></figure><p><strong>Security</strong> is one of 5 pillars of the Well-Architected framework, it can archive by applying best practices and principals in <strong>IAM</strong>, <strong>Encryption</strong>, <strong>Complician</strong>, and <strong>Governance</strong>. Of course, best practices aren’t enough, you need to learn more. In this post, I only share our best practices and tip when working with AWS SSM Parameter Store. By sharing our best practices, my hope is to encourage you to build and deploy secure and reliable applications and also giving us your feedback.</p><p>As you know, AWS Lambda supports native environment variables, you can easy to define and add any environment variables you want during deployment or change on the AWS Console Management. But using native environment variables contains some disadvantages:</p><ul><li>It stores plaint-text variables which easy to see its value. You had an option to encrypt variables in the console using KMS, but it still fetching per innovation causes increase your bill.</li><li>Hard to share across projects and teams that add complexity to your applications and services. More complexity requires more time to operate and increase the cost, therefore, you won’t meed the conditional for the <strong>Operational Excellence</strong> pillar of the Well-Architected framework.</li><li>As per Yan Cui, it hards for implementing fine-grained access to sensitive data.</li></ul><h4>What is AWS Systems Manager Parameter Store (aka SSM Parameter Store)?</h4><blockquote><em>AWS Systems Manager Parameter Store provides secure, hierarchical storage for configuration data management and secrets management. You can store data such as passwords, database strings, and license codes as parameter values. You can store values as plain text or encrypted data. You can then reference values by using the unique name that you specified when you created the parameter. Highly scalable, available, and durable, Parameter Store is backed by the AWS Cloud. ~</em><a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html"><em>AWS</em></a></blockquote><h4>What are the benefits?</h4><p>There are a lot of benefits when using AWS SSM Parameter Store, I just copied those from the AWS documentation:</p><ul><li>Use a secure, scalable, hosted secrets management service with no servers to manage.</li><li>Improve your security posture by separating your data from your code.</li><li>Store configuration data and secure strings in hierarchies and track versions.</li><li>Control and audit access at granular levels.</li><li>Configure change notifications and trigger automated actions for both parameters and parameter policies.</li><li>Tag parameters individually, and then secure access from different levels, including operational, parameter, Amazon EC2 tag, and path levels.</li><li>Reference AWS Secrets Manager secrets by using Parameter Store parameters.</li><li>Use Parameter Store parameters with other Systems Manager capabilities and AWS services to retrieve secrets and configuration data from a central store.</li><li>Configure integration with the AWS services for encryption, notification, monitoring, and auditing.</li></ul><p>So now you understand what is the SSM parameter store and its challenges, let talk about how we use it by reviewing the following our best practices and tips:</p><h4>#1 — Organizing parameters into hierarchies</h4><p>AWS provides detailed <a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-paramstore-su-organize.html">instructions</a> on how to organize your SSM <strong>Parameter Store</strong> to define and manage parameters easily. Following its best practices can help you and make your life easier. Below are a couple of formats/conventions that our team normally using:</p><ul><li>/environment/service-name/type/application-name/parameter_name i.e. <em>/prod/billing/databases/invoicing-portal/db_connection_string</em></li><li>You also can add your department name as well i.e. <em>/prod/human-resource/employee/user_list</em></li></ul><h4>#2 — Consistent naming convention</h4><p>Using a <strong>well-defined</strong> hierarchy helps you to manage and retrieve parameters more efficiently, but you also need to use a consistent <a href="https://en.wikipedia.org/wiki/Naming_convention_(programming)">naming convention</a> across your AWS account, your departments, and your teams.</p><p>By archiving this best practice, it reduces your reviewing efforts by focusing on critical business logic rather than syntax and naming standards and then increase your productivity and quality which can increase your customer satisfaction.</p><h4>#3 — Restrict IAM permission</h4><p>AWS SSM Parameter Store normally keeps your sensitive information, so restrict permissions are required to improve your security of the application. Each Parameter Store has a unique Resource ARN per account and region, so you can easier to define role and policy base on the hierarchy of the parameter store.</p><p>Below is a sample code from the AWS official document shows how to define a policy to restrict access to the Parameter Store</p><pre>{<br>    &quot;Version&quot;: &quot;2012-10-17&quot;,<br>    &quot;Statement&quot;: [<br>        {<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Action&quot;: [<br>                &quot;ssm:*&quot;<br>            ],<br>            &quot;Resource&quot;: &quot;arn:aws:ssm:us-east-2::parameter/*&quot;<br>        },<br>        {<br>            &quot;Effect&quot;: &quot;Deny&quot;,<br>            &quot;Action&quot;: [<br>                &quot;ssm:GetParametersByPath&quot;<br>            ],<br>            &quot;Condition&quot;: {<br>                &quot;StringEquals&quot;: {<br>                    &quot;ssm:Recursive&quot;: [<br>                        &quot;true&quot;<br>                    ]<br>                }<br>            },<br>            &quot;Resource&quot;: &quot;arn:aws:ssm:us-east-2:123456789012:parameter/Dev/ERP/Oracle/*&quot;<br>        },<br>        {<br>            &quot;Effect&quot;: &quot;Deny&quot;,<br>            &quot;Action&quot;: [<br>                &quot;ssm:PutParameter&quot;<br>            ],<br>            &quot;Condition&quot;: {<br>                &quot;StringEquals&quot;: {<br>                    &quot;ssm:Overwrite&quot;: [<br>                        &quot;false&quot;<br>                    ]<br>                }<br>            },<br>            &quot;Resource&quot;: &quot;arn:aws:ssm:us-east-2:123456789012:parameter/*&quot;<br>        }<br>    ]<br>}</pre><h4>#4 — Combine into a single parameter likes database connection string and keep it all together (co-location)</h4><p>By using consistency hierarchies and naming convention you can archive this idea. Keep all related parameters all together makes easy to find and retrieve. Using fewer parameters can reduce your bills.</p><p>Instead of using 4 separated parameters for the database connection string as below:</p><pre>/{env}/{service}/databases/master/host = db.domain.com<br>                               /user = username<br>                               /password = password<br>                               /port = 3306</pre><p>We combine into a single parameter using a standard connection string format:</p><pre>/{env}/{service}/databases/master/db_connection = jdbc://username:password@db_host:port/database_name</pre><p>Using community library such as <em>connection-string-parser</em>, you can easy to parse the parameter values and use to open connection, see below code snippet:</p><pre>import { createConnection as createConnectionPromise, Connection } from &#39;promise-mysql&#39;;<br>import { ConnectionStringParser } from &#39;connection-string-parser&#39;;</pre><pre>const parseConnectionString = (dialect: string, connectionUri: string) =&gt; {<br>  const connectionParser = new ConnectionStringParser({<br>    scheme: dialect || &#39;mysql&#39;,<br>    hosts: []<br>  });<br>  const connectionStrParams = connectionParser.parse(connectionUri);</pre><pre>  return {<br>    host: connectionStrParams.hosts[0].host,<br>    port: connectionStrParams.hosts[0].port || 3306,<br>    database: connectionStrParams.endpoint,<br>    user: connectionStrParams.username,<br>    password: connectionStrParams.password<br>  };<br>};</pre><pre>export const createConnection = (connectionUri: string): Promise&lt;Connection&gt; =&gt; {<br>  return createConnectionPromise(parseConnectionString(&#39;mysql&#39;, connectionUri));<br>};</pre><h4>#5 — Use tool/library to fetch, cache, and export to environment variables at runtime</h4><p>You are charged for API integration to SSM parameters, every time you retrieve your parameter from the store, you will increase your bill. What could you do to reduce your billing?</p><p>By default, <strong>max throughput (transactions per second) to retrieve parameter via API is 1000</strong>, how do you manage and avoid exceed throughput error?</p><p><a href="https://twitter.com/theburningmonk">@Yan Cui</a> wrote an <a href="https://hackernoon.com/you-should-use-ssm-parameter-store-over-lambda-env-variables-5197fc6ea45b">article</a> describes reasons why you should use AWS SSM Parameter Store over Lambda environment variables, he also mentioned approaches for caching and cache expiration using his custom client library.</p><p>Our team is using <a href="https://github.com/middyjs/middy">middy</a> middleware to deal with some cross-cutting concerns outside business logic, like input parsing and validation, output serialization, error handling. Application configuration also an aspect that every developer needs to work out and manage to run business logic. Out of the box, middy provides <a href="https://github.com/middyjs/middy/blob/master/docs/middlewares.md#ssm">ssm</a> middleware support fetch and cache parameters from the AWS SSM Parameter Store, it also supports assign parameter values to environment variables.</p><p>Here is a sample code on how to use middy to fetch and cache parameter store</p><pre>const middy = require(&#39;middy&#39;);<br>const { ssm } = require(&#39;middy/middlewares&#39;);</pre><pre>export const handler = middy((event, context, cb) =&gt; {<br>  // You can access the parameter value inside function handler<br>  console.log(process.env.HARVESTAR_PCMSS_DB_CONNECTION);</pre><pre>  // Your business logic here<br>}).use(<br>  ssm({<br>    cache: true,<br>    names: {<br>      // Should have a prefix that include this micro service i.e. pcmss<br>      HARVESTAR_PCMSS_DB_CONNECTION: &#39;/dev/harvestar/pcmss/db_connection&#39;<br>    }<br>  })<br>);</pre><p>There are some alternative open-sourced libraries out there:</p><ul><li><a href="https://www.npmjs.com/package/aws-parameter-cache">aws-parameter-cache</a></li><li><a href="https://github.com/alexcasalboni/ssm-cache-python">ssm-cache-python</a></li></ul><p><strong>Do you really trust the community package?</strong></p><p>I head from some people, basically, they don’t want to assign variables into environment variables (i.e. variables you can access through the <em>process.env</em> global object in Node.js runtime). If you do so, I have some advice as below:</p><ul><li>Instead of assign variables to <em>environment variables</em>, you also have another option to assign the <em>context</em> object of the AWS Lambda when using <strong>middy/ssm</strong> middleware.</li><li>To avoid sending your sensitive information such as data credentials, accessing to the <em>/tmp </em>directory, or running a child process when executing your serverless functions. You can use <a href="https://www.npmjs.com/package/@puresec/function-shield">@puresec/function-shield</a> library. We are also using it in our production environment.</li></ul><blockquote><strong><em>TIPS — Avoid fetching parameters at build/deploy time, fetch it at runtime instead. If you do so, you have to redeploy each time the parameter changed.</em></strong></blockquote><h4>#6 — Using hardcoded environment variables for your local development</h4><p>Do you need to run your function locally that fetches AWS SSM Parameter Store directly? The answer is it is optional, for your local environment, you might not need to use AWS SSM Parameter Store, you can use a .<em>env </em>file to keep your local variables. Below are some approaches you can use to archive that idea, note you still need to test your function with your desired approach on AWS environment:</p><ul><li>Use the <a href="https://www.npmjs.com/package/env-cmd">env-cmd</a> library to load, extract and assign to <em>process.env </em>global object. By running <strong><em>env-cmd serverless offline</em></strong> command, you can access all variables defined in your .env file.</li><li>Using the <a href="https://github.com/serverless/serverless-secrets-plugin">serverless-secrets-plugin</a> to define the environment variable in a secured manner, you can easier to share across the team and commit the encrypted file.</li></ul><p>Using the same code as below with a modification, you can skip fetching parameter store from AWS and reduce your bill:</p><pre>const middy = require(&#39;middy&#39;);<br>const { ssm } = require(&#39;middy/middlewares&#39;);</pre><pre>const isLocalEnv = process.env.IS_OFFLINE || process.env.IS_LOCAL;</pre><pre>export const handler = middy((event, context, cb) =&gt; {<br>  // You can access the parameter value inside function handler<br>  console.log(process.env.HARVESTAR_PCMSS_DB_CONNECTION);</pre><pre>  // Your business logic here<br>}).use(<br>  ssm({<br>    cache: true,<br>    // By setting the paramsLoaded, you tell the middleware to<br>    // not fetch it from AWS SSM<br>    paramsLoaded: isLocalEnv,<br>    names: {<br>      // Should have a prefix that include this micro service i.e. pcmss<br>      HARVESTAR_PCMSS_DB_CONNECTION: &#39;/dev/harvestar/pcmss/db_connection&#39;<br>    }<br>  })<br>);</pre><h4>#7 — Pay attention to services limits</h4><p>Likes other AWS services, AWS SSM Parameter Store also has some limits, such as the maximum number of params per account and region, max param value size, max history. Understanding its limits help us design and build applications with high reliability. For example, avoid storing large items into the SSM parameter because of size limits (4KB for standard and 8KB for the advanced parameter). Refer to <a href="https://docs.aws.amazon.com/general/latest/gr/aws_service_limits.html">AWS service limits documentation</a> for more others.</p><h4>Resources</h4><ul><li><a href="https://hackernoon.com/you-should-use-ssm-parameter-store-over-lambda-env-variables-5197fc6ea45b">You should use SSM Parameter Store over Lambda env variables</a></li><li><a href="http://sharing%20secrets%20with%20aws%20lambda%20using%20aws%20systems%20manager%20parameter%20store/">Sharing Secrets with AWS Lambda Using AWS Systems Manager Parameter Store</a></li><li><a href="https://velotio.com/blog/2018/9/2/managing-secrets-using-aws-systems-manager-parameter-store">Managing Secrets Using AWS Systems Manager Parameter Store and IAM Roles</a></li></ul><h4>Conclusion</h4><p>By applying best practices, you can implement your applications with more <strong>reliable</strong>, <strong>secure</strong>, <strong>efficient, and cost-effective</strong> software on the cloud.</p><p>I hope this post brings some ideas to you and saves time. There are more interesting and useful articles, so find and read them to get more information. Feel free to let me know your recommendations or suggestions by adding comments below.</p><p>Thank you for reading!</p><p>This post appears first on <a href="https://innomizetech.com/blog/07-best-practices-when-using-aws-ssm-parameter-store">our blog</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=63c8e7ab0d9b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/innomizetech/07-best-practices-when-using-aws-ssm-parameter-store-63c8e7ab0d9b">07 best practices when using AWS SSM Parameter Store</a> was originally published in <a href="https://medium.com/innomizetech">INNOMIZE</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Cloud computing journey]]></title>
            <link>https://medium.com/innomizetech/my-cloud-computing-journey-e6bf9cb84cf2?source=rss-a579329b14f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/e6bf9cb84cf2</guid>
            <category><![CDATA[cloud-development]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[journey]]></category>
            <dc:creator><![CDATA[Hoang Le]]></dc:creator>
            <pubDate>Sat, 16 Nov 2019 14:30:56 GMT</pubDate>
            <atom:updated>2023-07-28T01:56:47.832Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>Cloud computing</em></strong> is a buzzing <em>word nowadays</em>. It appeared as early as 1996, with the first known mention in a Compaq internal document (<a href="https://en.wikipedia.org/wiki/Cloud_computing">per Wiki</a>). Many companies are joining the cloud computing journey and archived a lot of benefits.</p><p>I have been working on various cloud computing projects from start to finish; involved in the full project lifecycle, including design, planning, development, deployment, testing, maintenance, and support. Some clients prefer to use their on-premise data centers, but most of my projects used the cloud — <a href="https://aws.amazon.com/">Amazon Web Services</a>, <a href="https://azure.microsoft.com/en-us/">Microsoft Azure</a>, and <a href="https://www.heroku.com/">Heroku</a>. So, I wanted to write this post to share my <a href="https://en.wikipedia.org/wiki/Cloud_computing">cloud computing</a> journey. My hope is to encourage you to build secure, scalable, highly available, and cost-effective cloud applications. <strong>Learn to share and share to learn </strong>will help us all grow, don’t you agree?</p><p>If you are new to the cloud and wanted to explore more information, check out some articles below:</p><ul><li><a href="https://www.bluesilvershift.com/why-are-so-many-businesses-moving-to-the-cloud-2/">Why are so many businesses are moving to the cloud?</a></li><li><a href="https://www.technologyreview.com/s/425970/who-coined-cloud-computing/">Who Coined ‘Cloud Computing’?</a></li><li><a href="https://cloudcomputing521.wordpress.com/2017/05/01/history-of-cloud-computing/">History of Cloud computing</a></li><li>Check out <a href="https://www.softwaretestinghelp.com/cloud-computing-service-providers/">15 Top Cloud Computing Services Provider Companies</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*WWxSUjaeUm7p8xhz.png" /><figcaption>Cloud computing from Wiki</figcaption></figure><p>This is a lengthy article. So, if you prefer to simply view a particular topic, you can use the table of contents below.</p><ul><li><a href="#5ff7">Who am I?</a></li><li><a href="#a839">Starting my career as a software developer</a></li><li><a href="#1947">The beginning of my cloud computing journey</a></li><li><a href="#9a51">My startup journey is just started</a></li><li><a href="#c650">My own company is officially established</a></li><li><a href="#4c1e">We got the first AWS certification</a></li><li><a href="#cd11">A few more serverless projects</a></li><li><a href="#8df4">Our most recent cloud computing projects</a></li><li><a href="#4be7">Other works</a></li><li><a href="#84f6">My future plan</a></li></ul><h4>Who am I?</h4><p>Firstly, I’d like to introduce myself. My name is <strong>Hoang</strong>, I am the <strong>Co-founder and CTO </strong>of <a href="https://www.innomizetech.com/">InnomizeTech</a>. My title is <strong>CTO</strong> but I am a <strong>full-stack developer</strong> <strong>and software architect</strong>, passionate about <strong>Cloud Computing</strong>, <strong>Serverless</strong>, <strong>DevOps</strong>, <strong>Machine Learning</strong>, and <strong>IoT</strong>.</p><p>With 7+ years of experience in software development (web, desktop, and mobile), systems integration, Cloud computing, DevOps engineering, project management, and agile methodology, I thrive working both independently and collaboratively in a team and have strong leadership and communication skills from working directly with both technical and non-technical stakeholders.</p><h4>Starting my career as a software developer</h4><p>Before transitioning to <a href="https://en.wikipedia.org/wiki/Cloud_computing">Cloud computing</a>, I worked for an <a href="https://en.wikipedia.org/wiki/Outsourcing">outsourcing</a> company in Vietnam for four years after I graduated from University.</p><ul><li><strong>For the first two years</strong>, the primary programming language I used was <strong>C# (AWS .NET WebForm and AWS .NET MVC)</strong>.</li><li><strong>For the next year</strong>, I transitioned to another role, leading a team working with system integration stuff using <a href="https://wso2.com/">WSO2</a> and <a href="https://en.wikipedia.org/wiki/Microsoft_BizTalk_Server">BizTalk</a>, among other tools. I had a chance to work with our client’s CTO. We had a lot of fun and we did a great job.</li></ul><h4>The beginning of my cloud computing journey</h4><p><strong>In the third year</strong>, I started my first <strong>Cloud computing</strong> project. We had a project from a US-based client to build an application for activating mobile devices for various carriers. I was the technical lead of that project. After studying the requirements, we selected the following technology stack:</p><ul><li><a href="https://nodejs.org/en/">Node.js</a> for back-end, using the <a href="https://sailsjs.com/">Sails<strong>.</strong>js</a> framework</li><li><a href="https://www.mysql.com/">MySQL</a> database and using <a href="https://sequelize.org/master/manual/getting-started.html">Sequelize</a> for ORM. We used <a href="https://www.liquibase.org/">Liquibase</a> to generate, and migrate the database schema using source control.</li><li><a href="https://angular.io/">Angular</a> for the front-end application</li></ul><p>Actually, it isn’t a real <a href="https://searchcloudcomputing.techtarget.com/definition/cloud-application">cloud-based application</a>, since we used only a few cloud services to build the app. We have built the app and used the <a href="https://aws.amazon.com/elasticbeanstalk/"><strong>Elastic Beanstalk</strong></a> service for hosting. I have studied <a href="https://jenkins.io/">Jenkins</a> and built a Jenkins job for analyzing code, building, testing, and deploying to the Elastic Beanstalk app. Here is the diagram of the CI/CD I built at that time:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/613/0*zpGv2PQkmRu5XQDh" /></figure><p>We initially hosted the application on <strong>Elastic Beanstalk</strong> apps in order to apply our CI/CD script using AWS Beanstalk plugin on Jenkins for deployment. However, our client wanted to host it in their data center. Then we still use Beanstalk for our SIT/UAT environments, but we had to write documentation of around <strong>10 pages</strong> to describe how to set up <strong>Web Servers, App Servers</strong>, <strong>NGINX</strong>, <strong>Node.js,</strong> <strong>RDS</strong>, <strong>etc</strong>. A lot of back-and-forth communication between our <strong>development team</strong> and <strong>infra team</strong> because of issues and errors. But finally, we have successfully deployed, and the app is up and running<strong>.</strong></p><p>We kept working on that project for around a year. While developing new features, I also learned <a href="https://www.ansible.com/">Ansible</a> and built some playbooks to allow my client to deploy the app automatically without manual steps.</p><ul><li>Continuous Deployment — Deploying A Node.Js App To AWS EC2 Using Ansible</li></ul><p>At that time, I and my co-workers established a technical club to study and share about cloud computing. We learning cloud computing concepts and doing some hands-on exercises with <strong>AWS</strong> and <strong>Microsoft Azure</strong>. You can visit our <a href="https://www.facebook.com/groups/992679037443304/">Facebook page</a> to see our activities and great memories.</p><p>Before leaving the company, I studied and shared my CI/CD experiences. I have presented <a href="https://www.slideshare.net/HoangLe84/introduction-to-cicd-190596305">this presentation</a> for my promotion to the <strong>Senior Engineer</strong> position (I have changed a few things to share with everyone).</p><h4>My startup journey is just started</h4><p>In <strong>August 2017</strong>, I started my<strong> own job</strong>. We had a project for building a core/shared backend API for various client applications including <strong>SPA</strong>, <strong>Mobile App</strong>,<strong> and Integration services</strong>. After clarifying requirements with our clients, we have selected the below technology stack:</p><ul><li><a href="https://aws.amazon.com/lambda/">AWS Lambda</a> uses Node.js runtime and <a href="https://aws.amazon.com/api-gateway/">Amazon API Gateway</a> that utilize Auth, Caching, Logging, Monitoring Throttling, and Bursting Elastic features for backend services.</li><li>We use the <a href="https://serverless.com/">Serverless</a> framework for building API, deploying and configuring AWS resources such as S3 bucket, SNS topic, Queue, and DynamoDB. At this time, we used <strong>JavaScript</strong> as the primary programming language.</li><li><a href="https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-identity-pools.html">Amazon Cognito User Pool </a>for authentication and authorization.</li><li><a href="https://aws.amazon.com/rds/aurora/">Amazon Aurora</a> for the relational database. We keep using <a href="https://sequelize.org/master/manual/getting-started.html">Sequelize</a> and <a href="https://www.liquibase.org/">Liquibase</a>.</li><li><a href="https://aws.amazon.com/elasticache/">Amazon Elastic Cache (Redis) </a>for in-memory caching.</li><li>Other AWS services we have used such as VPC, S3, SNS, SQS, CloudWatch, Route53, Certification Manager, AWS System Manager, AWS Parameter Store, X-Ray</li><li><a href="https://angular.io/">Angular</a> for the frontend app. Static hosting with<a href="https://blog.innomizetech.com/2019/10/25/how-do-we-host-our-static-website/"> S3 and CloudFront</a>.</li><li><a href="https://jasmine.github.io/">Jasmine</a>, <a href="https://www.protractortest.org/#/">Protractor</a> for unit test, integration test, and E2E test.</li><li>We still use Jenkins for our DevOps server. But instead of defining the job manually on the admin console page, we wrote a Jenkinsfile that used the <a href="https://jenkins.io/doc/tutorials/build-a-multibranch-pipeline-project/https://jenkins.io/doc/tutorials/build-a-multibranch-pipeline-project/">Mutliplebranch pipeline.</a></li><li>And more…</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*IQAzwZV7ldbJkWtw" /></figure><p>We kept applying the same stack to a few projects for other clients and continuously improve and refactored our core modules/libraries. We have delivered and received positive feedback from our clients. The applications were running well, had lower costs, high availability, and were secure.</p><p>In relation to <strong>DevOps</strong>, we have all the stuff scripted and provided CLIs to allow building and deploying applications automatically. We’ve used <a href="https://aws.amazon.com/cloudformation/">CloudFormation</a> to provision and configure infrastructure components such as VPC, RDS. We outlined steps to deploy/remove and send it over to our client, DevOps engineers, they can deploy a new environment using a few commands and then remove it completely without manual steps. <strong>Automation reduces human mistakes and increases productivity and quality.</strong></p><h4>My own company is officially established</h4><p>In <strong>October 2018</strong>, we officially established <a href="https://www.innomizetech.com/">InnomizeTech</a>, our mission is to create awesome products that will make your everyday life easier. <strong>My aim is to build a professional team with passion, enthusiasm, and talent that can help bring more value to our customers and help them move fast and in the right direction.</strong></p><p>The experienced engineering and development team at <strong>Innomize</strong> are committed, and passionate, and continually challenge themselves on the advancements and changes of the technologies we utilize to deliver the most up-to-date and innovative solutions.</p><h4>We got the first AWS certification</h4><p>I and my team have been learning, and building a lot of real-world cloud-based applications for many years. To prove to our clients that we had the experience to do their jobs, we studied and took some AWS exams and finally, our team got AWS certifications:</p><ul><li>02 AWS Certified Solution Architecture — Associate</li><li>02 AWS Cloud Practioner</li><li>01 AWS Certified Developer — Associate</li></ul><p>We have been with <a href="https://www.thecoraledge.com/">The Coral Edge</a> our partner and primary client. Recently, they officially became the <strong>Select Consulting Partner</strong> with <strong>AWS</strong> and we are their Development Team.</p><h4>A few more serverless projects</h4><p><strong>In early 2019</strong>, we had a contract with another client from the US, we will help their development team maintain and build new features for their micro-services (the integration component for their e-commerce system). They used <a href="https://www.scala-lang.org/">Scala</a> as their programming language, and <a href="https://gradle.org/">Gradle</a> as the build tool, their developer implemented some <a href="https://gradle.org/">Gradle</a> tasks to deploy the Lambda function, create the API gateway, and other required AWS resources. Here is the technology stack I can summarize:</p><ul><li>Each microservice has its own <strong>Lambda</strong> function and <strong>API Gateway</strong> as the original design. They had an <a href="https://www.nginx.com/">NGINX</a> server as a <a href="https://en.wikipedia.org/wiki/Reverse_proxy">reserved proxy </a>server that will route traffic to AWS API gateways based on the request path.</li><li><a href="https://github.com/http4s/http4s">http4s</a> as the interface for Restful API.</li><li>They used the <strong>Postgres</strong> database and also using <strong>Liquibase</strong> to manage their database schema and versioning. They used <a href="https://github.com/tpolecat/doobie">Doobie</a> for functional JDBC for Scala.</li><li><a href="https://sentry.io/welcome/">Sentry</a> for error monitoring and reporting.</li><li>They do use <a href="https://aws.amazon.com/codebuild/">AWS CodeBuild</a>, <a href="https://aws.amazon.com/codedeploy/">AWS CodeDeploy</a>, and <a href="https://aws.amazon.com/codepipeline/">AWS CodePipeline</a> to implement CI/CD but it isn’t fully implemented when we join their team.</li></ul><p>When our developers work with their team, we have proposed some approaches to enhance and refactor their design:</p><ul><li>To remove their NGINX server and cost, we suggest they apply the <a href="https://www.jeremydaly.com/serverless-microservice-patterns-for-aws/">Robust API</a> pattern.</li><li>We helped design and built a <strong>project template</strong> in order to add a new microservice easily. Here are some of our ideas:</li><li>Defining a project template that uses AWS CodeStart which will allow us to create <strong>CodeCommit</strong> repositories, and define <strong>CodeBuild</strong> projects, and <strong>CodePipelines</strong> automatically when creating a new project. New microservices can be up and running by using a single command.</li><li>We suggest using the <a href="https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html">AWS SAM</a> framework for building Lambda functions and defining required AWS resources (i.e. Queue, Bucket, Topic, etc.). Previously, they deployed Lambda and other resources by implementing custom Gradle tasks.</li></ul><h4>Our most recent cloud computing projects</h4><p>Recently, we have been working on some projects that apply Micro-service architecture. We continue the above technology stacks with some changes/improvements:</p><ul><li>We used <a href="https://nx.dev/angular">NX Dev Tool</a> to define our workspace on a Monorepo. We built our CI/CD pipeline that supports deploying only affected apps by a change instead of redeploying all services. Thanks to the <strong>NX</strong> team for their idea and awesome tool.</li><li><a href="https://aws.amazon.com/step-functions/">Step Functions</a> for our micro-service communication, automated workflow.</li><li><a href="https://nestjs.com/">NestJS</a> for our Restful API that running on AWS Lambda.</li><li>AWS CDK to provision and configure our infrastructure as code (IoC)</li><li><a href="https://jestjs.io/">Jest</a>, <a href="https://www.cypress.io/">Cypress</a> for unit test, integration test, and E2E testing.</li><li>Along with using <a href="https://aws.amazon.com/cognito/">Cognito</a> we also use <a href="https://www.okta.com/">Okta</a>, <a href="https://auth0.com/">AuthO</a> for authentication and authorization.</li><li>CI/CD with <a href="https://aws.amazon.com/products/developer-tools/">AWS Develop Tools,</a> <a href="https://jenkins.io/">Jenkins</a>, <a href="https://azure.microsoft.com/en-us/services/devops/">Azure DevOps</a>.</li><li>Along with using Node.js runtime, we also use <strong>Java/Scala</strong> and <strong>.NET Core</strong> runtime.</li></ul><h4>Other works</h4><p>We focused on <strong>AWS</strong> as the primary cloud vendor and wanted to become an active development service by partnering with them. Along with cloud computing, our team also has experience in other technologies. We work with the latest technologies specializing in Web Development, Mobile Development, Cloud Computing (AWS, Azure), DevOps, and Automation Testing. Refer to our <a href="https://www.innomizetech.com/#services">Services</a> section on our website for more information.</p><p>We continue working on some other projects such as:</p><ul><li>DevOps using <a href="https://aws.amazon.com/cloudformation/">CloudFormation</a>, <a href="https://docs.aws.amazon.com/cdk/latest/guide/home.html">AWS CDK</a>, <a href="https://www.ansible.com/">Ansible</a></li><li><a href="https://aws-amplify.github.io/">Amplify</a> framework: hosting, authentication, Mobile App with AppSync.</li><li>Ruby on Rails app on AWS ECS.</li><li>Headless upload bills to various sites with AWS ECS and Protractor (<a href="https://www.youtube.com/watch?v=OJ4B81630MI&amp;t=29s">End to end automation test with Protractor</a>).</li><li><a href="https://blog.innomizetech.com/2019/11/01/building-serverless-web-crawler-with-puppeteer-on-aws-fargate/">Serverless web crawler with Puppeteer on AWS Fargate</a> that I recently wrote that post.</li><li>React, Amplify, AppSync.</li><li>Work with other AWS services such as <strong>AWS WAF,</strong> <strong>AWS Shield</strong>, <strong>Glue</strong>, <strong>ElasticSearch</strong>, <strong>Kinesis</strong>, and <strong>Athena</strong>.</li><li>We helped some clients design and define <strong>DevOps</strong>, and CI/CD pipelines using <strong>AWS Developer Tools</strong> and <strong>Azure DevOps</strong>.</li></ul><h4>My future plan</h4><p>My quote is <strong>“Learn to share and share to learn”</strong>, I am continually challenging myself on the advancements and changes of the technologies. I wanted to meet more people, talk, work, and help them. I do have a few things on my list so I am going to do:</p><ul><li>Build <a href="https://www.innomizetech.com/">Innomize</a> stronger, work with more clients, and collaborate with more people.</li><li>Learn more things such as Machine Learning, Deep Learning, Transfer Learning, Convolution Neural Networks, and IoT.</li><li>Build my own product.</li></ul><p>I cannot describe anything about myself in this post, if you wanted to know more about me and our team, then you can get in touch with me via:</p><ul><li><a href="https://twitter.com/hoangleitvn">Twitter</a></li><li><a href="https://www.linkedin.com/in/hoangleitvn/">LinkedIn</a></li><li><a href="https://dev.to/hoangleitvn">DEV Community</a></li><li><a href="https://github.com/hoang-innomizetech">Github</a></li><li><a href="https://medium.com/@hoangleitvn">Medium</a></li><li><a href="/service/mailto:hoang@innomizetech.com">Email</a></li></ul><p>If you are looking for developers, an offshore team, or need consulting about the AWS cloud, Serverless architecture, and so on, then <a href="https://innomizetech/contact-us">get in touch with us</a>, we can help you!</p><p>Thank you for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e6bf9cb84cf2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/innomizetech/my-cloud-computing-journey-e6bf9cb84cf2">My Cloud computing journey</a> was originally published in <a href="https://medium.com/innomizetech">INNOMIZE</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Top reasons why we use AWS CDK over CloudFormation]]></title>
            <link>https://medium.com/innomizetech/top-reasons-why-we-use-aws-cdk-over-cloudformation-6dd55b59b1dd?source=rss-a579329b14f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/6dd55b59b1dd</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[aws-cdk]]></category>
            <category><![CDATA[cloudformation]]></category>
            <dc:creator><![CDATA[Hoang Le]]></dc:creator>
            <pubDate>Tue, 12 Nov 2019 02:54:59 GMT</pubDate>
            <atom:updated>2023-07-28T02:39:07.803Z</atom:updated>
            <content:encoded><![CDATA[<p>This post is originally published on <a href="https://innomizetech.com/blog/top-reasons-why-we-use-aws-cdk-over-cloudformation">our blog</a>.</p><p>If you’re working with <strong>AWS Infrastructure</strong>, you may know that currently there are some tools/frameworks that support implementing your AWS infrastructure such as <a href="https://aws.amazon.com/cloudformation/">CloudFormation</a>, <a href="https://www.terraform.io/">Terraform</a>, and <a href="https://docs.aws.amazon.com/cdk/latest/guide/home.html">AWS CDK</a>. What is the best tool that your team can rely on and use? What is the best tool that can help you increase productivity and quality? Do you have the answer? If not, read this post, and I will give you our answer and reasons.</p><p>Our team has been working with <strong>AWS</strong> for a couple of years. We have designed and implemented infrastructure components including <strong>networking</strong>, <strong>server</strong>, <strong>storage</strong>, and other AWS services either <strong>manually</strong> or <strong>automated</strong>. Before using A<strong>WS CDK</strong>, we used <strong>AWS CloudFormation</strong>, but working with it is a challenge, hard to define and get an overview for a complex template in either <strong>JSON</strong> or <strong>YAML</strong> format.</p><p>In this post, I will not provide specific detail of <strong>AWS CDK.</strong> If you don’t know what it is, then check out the <a href="https://docs.aws.amazon.com/cdk/latest/guide/home.html">AWS CDK home page</a> to get some overviews and see how it works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*kf64f6MQ3hqkh5l8" /><figcaption>Sample code on how to create a VPC on AWS with AWS CDK</figcaption></figure><p>We select AWS CDK as the <strong>primary</strong> tool for our Infrastructure as Code (IaC) because of the following reasons:</p><p><strong>With AWS CDK we “WRITE LESS AND DO MORE</strong>“</p><p>We first impressed <strong>AWS CDK</strong>, when we try to find alternative ways to reduce complexity and overcome the challenges of using <strong>CloudFormation</strong>. For example, we have a CloudFormation template to define and configure networking resources including VPC, subnets, route tables, security groups, bastion hosts, integrate gateway, nat gateways, etc. We need to write around <strong>1000 lines of code</strong> in JSON format using CloudFormation. When we try with AWS CDK, we only need to write around <strong>50 lines of code</strong>. As you can see, <strong>AWS CDK can do the same thing, even add more features such as conditional number of NAT gateway, number of subnets, and availability zones.</strong></p><p>The following code will create all required resources that allow you to create a new VPC on AWS in minutes, you can then modify or add more resources depending on your requirements:</p><pre>import * as cdk from &#39;@aws-cdk/core&#39;;<br>import * as ec2 from &#39;@aws-cdk/aws-ec2&#39;;</pre><pre>export class NetworkStack extends cdk.Stack {<br>  public readonly vpc: ec2.Vpc;</pre><pre>  constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {<br>    super(scope, id, props);</pre><pre>    this.vpc = new ec2.Vpc(this, &#39;VPC&#39;, {<br>      cidr: &#39;10.0.0.0/16&#39;,<br>      natGatewaySubnets: {<br>        subnetName: &#39;Public&#39;<br>      },<br>      subnetConfiguration: [<br>        {<br>          cidrMask: 26,<br>          name: &#39;Public&#39;,<br>          subnetType: ec2.SubnetType.PUBLIC<br>        },<br>        {<br>          name: &#39;Application&#39;,<br>          subnetType: ec2.SubnetType.PRIVATE<br>        },<br>        {<br>          cidrMask: 27,<br>          name: &#39;Database&#39;,<br>          subnetType: ec2.SubnetType.ISOLATED<br>        }<br>      ]<br>    });</pre><pre>    const vpcSecurityGroup = new ec2.SecurityGroup(this, &#39;SecurityGroup&#39;, {<br>      vpc: this.vpc,<br>      description: &#39;Allow ssh access to ec2 instances&#39;,<br>      allowAllOutbound: true<br>    });</pre><pre>    vpcSecurityGroup.addIngressRule(<br>      ec2.Peer.anyIpv4(),<br>      ec2.Port.tcp(22),<br>      &#39;allow ssh access from the world&#39;<br>    );<br>  }<br>}</pre><p><strong>Easy to share and reuse your infrastructure as a library</strong></p><p><strong>Declarative infrastructure as code</strong> tends to be in languages that we don’t use every day like HCL, YAML, or JSON. AWS CDK uses<strong> object-oriented,</strong> provides <strong>abstraction</strong> techniques to create a model of our system, we can define <strong>modules</strong> to <strong>share across projects</strong>. We can use built-in construct libraries or from the community that can increase our productivity.</p><p><strong>CDK is a developer-friendly version of Cloud Formation</strong></p><p>AWS CDK is an <strong>imperative</strong> programming language, supporting Java, JavaScript, Python, TypeScript, and . NET. We can utilize our developer programming skills to reduce the time for learning a new syntax like <strong>Terraform</strong>. Think about a project in that we use TypeScript as the primary programming language for Front-end, Back-end, CI/CD, and IoC.</p><p><strong>Easy to use logic (if statements, for-loops, etc) when defining your infrastructure</strong></p><p>We know how to write an if or for-loops, right? How hard is it to write a <strong>condition</strong> when using CloudFormation? If you know the answer, then you will know why love AWS CDK.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*YBbTjIrUVP3ZznqZ" /><figcaption>Condition logic with AWS CDK</figcaption></figure><p><strong>Easy to get and integrate with our coding review workflow</strong></p><p>AWS CDK provides commands to generate the <strong>CloudFormation</strong> template, so we can still review the generated CloudFormation template before applying, it also can generate a dif that makes it easy to review and make the decision.</p><p><strong>Code completion within your IDE</strong></p><p>Does anyone remember how to define a full detail of an AWS resource using CloudFormation? Is there any <strong>schema</strong> or <strong>intelligence</strong> for the CloudFormation template that you can use for <strong>code completion</strong> to speed up your coding time?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*ULYDOlDOxVE4n5Lx" /><figcaption>Code completion with AWS CDK</figcaption></figure><p><strong>Allow us to test our code</strong></p><p>AWS CDK allows us to perform snapshot tests, and fine-grained assertions, and help us build reliable and testable code, <a href="https://aws.amazon.com/blogs/developer/testing-infrastructure-with-the-aws-cloud-development-kit-cdk/">here is the post</a> that provides step by step guide to writing and running unit tests using <a href="https://jestjs.io/">Jest</a>. With CloudFormation, you also can write some tests, but it requires another tool, check out <a href="https://aws.amazon.com/blogs/infrastructure-and-automation/up-your-aws-cloudformation-testing-game-using-taskcat/">this post</a> for more details.</p><p><strong>Easy to integrate with our CI/CD process</strong></p><p>Deployment can be done with one single command requiring installing any additional tool. We also use AWS CDK to define our CI/CD pipeline using AWS DevOps tools such as CodeBuild, and CodeDeploy, which is much better than writing a lot of CloudFormation code.</p><p>The A<strong>WS CDK</strong> just has a high level of <strong>CloudFormation</strong>, so if you want to how exactly it works, my suggestion is to have a try with <strong>CloudFormation</strong>, do some works around it, then try to convert it into AWS CDK, you will find out whether you will continue with CloudFormation or change to use AWS, or maybe you can change to other tools such as Terraform.</p><p><strong>Nothing is the best, it depends on your requirement, team, project, and your company</strong>. <strong>Have a nice coding!</strong></p><p><strong>Hoang Le</strong></p><p><strong>Learn to Share and Share to Learn.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6dd55b59b1dd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/innomizetech/top-reasons-why-we-use-aws-cdk-over-cloudformation-6dd55b59b1dd">Top reasons why we use AWS CDK over CloudFormation</a> was originally published in <a href="https://medium.com/innomizetech">INNOMIZE</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 toggle Vpc configuration per stage?]]></title>
            <link>https://medium.com/innomizetech/how-to-toggle-vpc-configuration-per-stage-6e4b04602e9f?source=rss-a579329b14f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e4b04602e9f</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[how-to]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <dc:creator><![CDATA[Hoang Le]]></dc:creator>
            <pubDate>Fri, 08 Nov 2019 03:41:43 GMT</pubDate>
            <atom:updated>2023-07-28T02:40:51.554Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to toggle VPC configuration per stage?</h3><p>This post is originally published on <a href="https://innomizetech.com/blog/how-to-toggle-aws-vpc-configuration-per-stage-with-serverless-framework">our blog</a>.</p><p><a href="https://forum.serverless.com/t/exclude-vpc-config-for-different-enviornments/9756">This guy has asked the serverless forum</a> for a solution to implement it. That is why I wanted to write this post to describe how to toggle <strong>VPC</strong> configuration per stage. I hope it can help you and save you time :)</p><p>If you are working on the <a href="https://serverless.com/">Serverless</a> framework to build your application on AWS. You possibly wanted to run your Lambda functions under your private Vpc to protect your functions and hide them from the world. But sometimes, you might want to run your function without <strong>VPC</strong> such as for non-production environments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/639/0*0ZpAdhUaJxduDwOV" /></figure><p><em>Vpc on AWS Lambda</em></p><p>Basically, we can disable <strong>Vpc</strong> configuration for the Lambda function by either:</p><ul><li>Omit the <strong>vpc</strong> property in the <strong>provider</strong> configuration.</li><li>Or you can set both <strong>securityGroupIds</strong> and <strong>subnetIds</strong> as an empty array.</li></ul><p>Based on the above logic, we can define a property in the <strong>custom</strong> prop as below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/286e12b3f405d835d9f4aec67d6df198/href">https://medium.com/media/286e12b3f405d835d9f4aec67d6df198/href</a></iframe><p>With the above configurations, deploying to the <strong>dev</strong> stage will not add your lambda functions to a Vpc, but deploying to the <strong>prod</strong> stage will add your lambda functions to your desired Vpc.</p><p>You can refer to some plugins I added in the <em>serverless.yml </em>file, it can be used to create your Vpc automatically or discover from the AWS account.</p><ul><li><a href="https://www.npmjs.com/package/serverless-vpc-plugin">serverless-vpc-plugin</a></li><li><a href="https://www.npmjs.com/package/serverless-vpc-discovery">serverless-vpc-discovery</a></li></ul><p>If you want to have a try, you can check out <a href="https://github.com/hoang-innomizetech/serverless-toggle-vpc-example">our repo</a> on GitHub.</p><p>Should you run into issues while practicing the steps outlined in this article, I encourage you to reach out to me. You can get in touch with me through my Twitter handle <a href="https://twitter.com/hoangleitvn">@hoangleitvn</a></p><p>Visit our <a href="https://innomizetech.com/blog">blog</a> for more interesting articles. If you have any questions or need help you can contact me via <a href="https://twitter.com/hoangleitvn">Twitter</a>.</p><p>Thank you for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e4b04602e9f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/innomizetech/how-to-toggle-vpc-configuration-per-stage-6e4b04602e9f">How to toggle Vpc configuration per stage?</a> was originally published in <a href="https://medium.com/innomizetech">INNOMIZE</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Top serverless plugins we are using]]></title>
            <link>https://medium.com/innomizetech/top-serverless-plugins-we-are-using-f02df901bbbf?source=rss-a579329b14f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/f02df901bbbf</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[plugins]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[serverless]]></category>
            <dc:creator><![CDATA[Hoang Le]]></dc:creator>
            <pubDate>Fri, 08 Nov 2019 03:30:10 GMT</pubDate>
            <atom:updated>2023-07-28T02:42:30.647Z</atom:updated>
            <content:encoded><![CDATA[<p>This post is originally published on <a href="https://innomizetech.com/blog/top-serverless-plugins-we-are-using">our blog</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LRlSVsz94TWLmwc3Fpx33Q.jpeg" /></figure><p>We are using the <a href="https://serverless.com/">Serverless</a> framework for a couple of years and building a lot of applications. So I wanted to summarize and provide a brief description of some plugins that our team is using every day. I am not sure it is good for you, if you have any recommendations, just let us know.</p><p>If you haven’t yet checked out this<a href="https://github.com/serverless/plugins"> list of Serverless Framework plugins</a>, you’re missing out. Or you can read this post for a short version.</p><blockquote><em>Don’t Reinvent The Wheel</em></blockquote><p>Don’t build it again if someone else already built it and open-sourced it for you.”. It’s free to use and the community support revolves around building, fixing, and maintenance.</p><p><a href="https://www.npmjs.com/package/serverless-offline">serverless-offline</a></p><p>I believe this is the most popular plugin, almost <a href="https://serverless.com/">Serverless</a> developers have used it at least one time. This Serverless plugin emulates the AWS Lambda function and API Gateway on your local machine to speed up your development cycles.</p><p>Along with using <a href="https://www.npmjs.com/package/serverless-offline">serverless-offline</a>, our team also uses some plugins that support emulating cloud services on our local machine such as:</p><ul><li><a href="https://github.com/99xt/serverless-dynamodb-local">serverless-dynamodb-local</a></li><li><a href="https://www.npmjs.com/package/serverless-step-functions-offline">serverless-step-functions-offline</a></li><li><a href="https://github.com/ar90n/serverless-s3-local">serverless-s3-local</a></li></ul><p><a href="https://github.com/serverless-heaven/serverless-webpack">serverless-webpack</a> and <a href="https://github.com/prisma-labs/serverless-plugin-typescript">serverless-plugin-typescript</a></p><p>It is easy to get started with zero-config by using <a href="https://github.com/prisma-labs/serverless-plugin-typescript">serverless-plugin-typescript</a> plugin for small projects. But for large scale projects, we are using the <a href="https://github.com/serverless-heaven/serverless-webpack">serverless-webpack</a> plugin that allows us to define our <a href="https://webpack.js.org/">webpack</a> configuration for bundling TypeScript code.</p><blockquote><em>If you are using </em>paths<em> configuration in the tsconfig.json file, then you might need to use </em><a href="https://www.npmjs.com/package/tsconfig-paths-webpack-plugin"><em>tsconfig-paths-webpack-plugin</em></a><em> plugin to automatically load modules based on the location specified in the </em>paths<em> config</em></blockquote><p><a href="https://www.npmjs.com/package/serverless-iam-roles-per-function">serverless-iam-roles-per-function</a></p><p>This plugin allows us to define the IAM roles per functions instead of using a single IAM role for all Lambda functions. <a href="https://twitter.com/theburningmonk">Yan Cui</a> has listed this plugin as 2nd serverless best practice on <a href="https://www.datree.io/resources/serverless-best-practices">this post</a></p><p><a href="https://github.com/amplify-education/serverless-domain-manager">serverless-domain-manager</a></p><p>We use this plugin to create custom domains for API Gateway.</p><p><a href="https://github.com/dougmoscrop/serverless-plugin-split-stacks">serverless-plugin-split-stacks</a></p><p>To avoid reaching the <a href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cloudformation-limits.html">200 resources limit of our CloudFormation</a> error, we use this plugin to split the main stack into multiple stacks.</p><p><a href="https://www.npmjs.com/package/serverless-plugin-warmup">serverless-plugin-warmup</a></p><p>How to reduce cost starts for Lambda functions? The question that a lot of developers are asking and trying to reduce cost starts. There are more solutions but one of them is using this plugin. It solved the cost starts by using a scheduled task that will invoke selected functions in a configurable interval (default is 5 mins, but we almost use 45 mins as the average interval that the Lambda function keep-alive)</p><p><a href="https://github.com/ACloudGuru/serverless-plugin-aws-alerts">serverless-plugin-aws-alerts</a></p><p>We use this plugin to define CloudWatch alarms for Lambda functions by using default definitions or adding log metric filters to log groups.</p><p><a href="https://github.com/serverless/serverless-secrets-plugin">serverless-secrets-plugin</a></p><p>Store some environment variables that we can commit to source control and share across teams. But for storing sensitive information, we use <a href="https://www.npmjs.com/package/@middy/ssm">@middy/ssm</a> middleware to fetch SSM parameters.</p><p><a href="https://github.com/smoketurner/">serverless-vpc-plugin</a></p><p>If you want to run your Lambda functions under your private VPC and want to define new VPC when deploying serverless, then use this plugin. You also can use <a href="https://www.npmjs.com/package/serverless-vpc-discovery">serverless-vpc-discovery</a> plugin to retrieve an existing VPC from your AWS account.</p><p><a href="https://github.com/jeremydaly/serverless-mysql">serverless-mysql</a></p><p>Use this plugin to manage MYSQL connections at scale.</p><p><a href="https://github.com/horike37/serverless-apigateway-service-proxy">serverless-apigateway-service-proxy</a></p><p>If you want to expose API for SNS, SQS, S3, and Kinesis Streams, then you can use this plugin without Lambda, also AWS resources will be created by that plugin.</p><p>And a few more as below:</p><p><a href="https://github.com/davidgf/serverless-plugin-canary-deployments">serverless-plugin-canary-deployments</a> this plugin supports Blue/green deployment for your Lambda.<br><a href="https://www.npmjs.com/package/serverless-pseudo-parameters">serverless-pseudo-parameters</a> this plugin allows using <a href="http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/pseudo-parameter-reference.html">CloudFormation Pseudo Parameters</a> in your serverless.yml<br><a href="https://www.npmjs.com/package/serverless-s3-deploy">serverless-s3-deploy</a> uses this plugin to sync your directory to a S3 bucket, we have used it for deploying our static website.<br><a href="https://www.npmjs.com/package/serverless-api-stage">serverless-api-stage</a> support defining stage variables, logging configuration (for AWS provider)<br><a href="https://github.com/serverless-heaven/serverless-aws-alias">serverless-aws-alias </a>this plugin enables the use of AWS aliases on Lambda functions, for example you can use this plugin to deploy multiple environments for different VCS branches.<br><a href="https://github.com/sinofseven/serverless-s3-remover">serverless-s3-remover</a> you cannot delete an S3 bucket with data, right? This plugin will solve that problem. It will prompt you to remove its data before removing Cloud Formation stack.<br><a href="https://github.com/haftahave/serverless-ses-template">serverless-ses-template</a> if you are using SES Template, right now AWS doesn’t provide UI to upload or edit templates on the Console Management, you can only use API to upload templates. This plugin will do that for you, it automatically creates, updating, and removes AWS SES Templates using a configuration and keeps your AWS SES Templates synced with your configuration file.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f02df901bbbf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/innomizetech/top-serverless-plugins-we-are-using-f02df901bbbf">Top serverless plugins we are using</a> was originally published in <a href="https://medium.com/innomizetech">INNOMIZE</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How do we host our static website]]></title>
            <link>https://medium.com/innomizetech/how-do-we-host-our-static-website-b0b60f2a09f2?source=rss-a579329b14f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/b0b60f2a09f2</guid>
            <category><![CDATA[static-site]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[hosting]]></category>
            <category><![CDATA[how-to]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Hoang Le]]></dc:creator>
            <pubDate>Sun, 03 Nov 2019 06:45:53 GMT</pubDate>
            <atom:updated>2023-07-28T02:44:06.403Z</atom:updated>
            <content:encoded><![CDATA[<p>You are building a static website and wanted to know how to host your site, but;</p><ul><li>You don’t want to perform manual steps.</li><li>You want to host for multiple environments such as <strong>Development</strong>, <strong>UAT</strong>, <strong>Staging</strong>, <strong>Production</strong>.</li><li>You want to reduce cost, provide high levels of reliability, require almost no IT administration, and scale to handle enterprise-level traffic with no additional work.</li><li>You wanted to deliver HTML, JavaScript, images, video, and other files to your website visitors around the world with CDN.</li></ul><p>In this article, I will show you how to host a static website in a few minutes without manual steps, you can define the CI/CD pipeline to automate your deployment process pretty easily. <a href="https://aws.amazon.com/getting-started/projects/host-static-website/">Amazon Web Services </a>is the most popular public cloud vendor in the world, they provide services to simply making a website on their infrastructure around the world. Check out <a href="https://aws.amazon.com/getting-started/projects/host-static-website/">this article</a> to know more details.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/561/0*VDhzpDhQ27pV7mCT" /></figure><p>If you are new to AWS, and you want to practice in order to know the steps to host a site on AWS, <a href="https://dev.to/arswaw/host-a-serverless-static-website-with-free-ssl-in-15-minutes-hd3">this article</a> will help you.</p><p><strong>DevOps</strong> at <a href="https://www.innomizetech.com/">Innomize</a> is the most important aspect of our solutions and is required for all our projects. Automation reduces time-to-market, the risk of human errors, and redundancy in the system while increasing the efficiency of the project delivery. To automate the static website deployment, there are a couple of ways:</p><ul><li>Use<strong> </strong><a href="https://aws-amplify.github.io/">the AWS Amplify</a> framework.</li><li>Use the <a href="https://serverless.com/">Serverless</a> framework and define CloudFormation resources, then use the <a href="https://www.npmjs.com/package/serverless-s3-sync">serverless-s3-sync</a> plugin to sync your static files to the S3 bucket.</li><li>Using the <a href="https://github.com/serverless/components">Serverless Component</a>, a new infrastructure provisioning technology to build, compose, and deploy apps in seconds.</li></ul><h4>Let’s Get Started</h4><p>Now, I will show steps to build and deploy a website using <strong>Serverless Component.</strong> Below are the reasons why I selected this approach:</p><ul><li>It is pretty fast, in less minutes you will have a site up and running.</li><li>It is an easy way to apply to our <a href="https://en.wikipedia.org/wiki/Monorepo">Monorepo</a> since we have multiple apps per repo.</li><li>For consistency with our backend framework, we use the <strong>Serverless framework</strong> to build backend services with <strong>AWS Lambda</strong>, <strong>API Gateway</strong>, <strong>Cognito</strong>, and other AWS services.</li></ul><p>Follow <a href="https://github.com/serverless/components/tree/master/templates/website">this guide</a>, you will able to build and deploy your site, however, the <strong>Serverless component</strong> hasn’t provided a way to deploy to multiple environments/stages using the same serverless.yml (or serverless.js) file yet. I have raised <a href="https://github.com/serverless/components/issues/481">this issue</a>, check out this if you want to know more details.</p><p><em>Note, I wrote this post based on suggestments and comments from the above Github issue.</em></p><p>Before getting started to deploy the site, if you haven’t had a domain registered, you might need to:</p><ul><li>Check out <a href="https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/domain-register.html">this article</a> to register a new domain.</li><li>Request a wildcard public cert by following <a href="https://docs.aws.amazon.com/acm/latest/userguide/gs-acm-request-public.html">this article</a>.</li></ul><p>After you had the SSL certificate and Route53 issued and registered, follow the following steps to compose and deploy your site:</p><ul><li>Install Serverless</li></ul><pre>npm install serverless -g</pre><ul><li>Create a sample React application, you can skip this step if you already have your app.</li></ul><pre>npx create-react-app sls-dev-app</pre><ul><li>Install serverless component packages</li></ul><pre>npm install @serverless/core @serverless/template -D</pre><ul><li>Create <em>serverless.js </em>file in the project root directory</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0a3b6d8b4d0f3a68d4e73581a81e70ff/href">https://medium.com/media/0a3b6d8b4d0f3a68d4e73581a81e70ff/href</a></iframe><ul><li>You can modify the serverless.js file based on your requirements. such as replacing your domain name (i.e. change the <em>domain.com</em> to your registered domain name). <strong>Note, right now if you use the full domain name for the bucketName (i.e. </strong><a href="http://www.my-app.domain.com/"><strong>www.my-app.domain.com</strong></a><strong>), you will end up with an error related to CloudFront distribution, that is the reason why I used hyphens (-) instead of using dots (.) for bucket name.</strong></li><li>Deploy</li></ul><pre># --env can be any value for your environment<br>sls --debug --env=dev</pre><pre># then you can deploy to another environment<br>sls --debug --env=prod</pre><p>In a few minutes (it depends on how fast the CloudFront distribution provision and register your site), you will have your site up and running.</p><p>This post is originally published on <a href="https://innomizetech.com/blog/how-do-we-host-a-static-website">our blog</a>.</p><p>Thank you for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b0b60f2a09f2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/innomizetech/how-do-we-host-our-static-website-b0b60f2a09f2">How do we host our static website</a> was originally published in <a href="https://medium.com/innomizetech">INNOMIZE</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building serverless web crawler with Puppeteer on AWS Fargate]]></title>
            <link>https://medium.com/innomizetech/building-serverless-web-crawler-with-puppeteer-on-aws-fargate-1202c8a66ec4?source=rss-a579329b14f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/1202c8a66ec4</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[web-crawler]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[puppeteer]]></category>
            <category><![CDATA[aws-cdk]]></category>
            <dc:creator><![CDATA[Hoang Le]]></dc:creator>
            <pubDate>Sun, 03 Nov 2019 06:42:15 GMT</pubDate>
            <atom:updated>2023-07-28T01:35:59.685Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently our team has been working on a project with data crawling from various sites for pricing comparison. Our team has selected <a href="https://developers.google.com/web/tools/puppeteer">Puppeteer</a> to implement. We have successfully built and delivered this solution to our customer, so I would like to write this article to share and provide some outline steps to help you set up and have a try. I hope you enjoy it!</p><h3>Why Puppeteer?</h3><p>Per Google’s documentation</p><blockquote><strong><em>Puppeteer</em></strong><em> is a Node library which provides a high-level API to control </em><a href="https://developers.google.com/web/updates/2017/04/headless-chrome"><em>headless</em></a><em> Chrome or Chromium over the </em><a href="https://chromedevtools.github.io/devtools-protocol/"><em>DevTools Protocol</em></a><em>. It can also be configured to use full (non-headless) Chrome or Chromium.</em></blockquote><p>There are a couple of reasons why we’ve selected <strong>Puppeteer</strong>:</p><ul><li>Headless supported so easy to run on we can run on any container as <em>serverless</em> such as AWS Lambda, Azure Function, and ECS.</li><li>It is powerful, and provides us with a lot of commands and API.</li><li>Easy to get started, we can automate input and navigation easily with a few lines of code. For our pricing crawler, inputs, actions, and navigation are required, therefore, using <strong>Puppeteer</strong> can help us.</li><li>Node.js + TypeScript supported, we can utilize our automation development with Selenium, Protractor, and Cypress skills.</li><li>And much more, you can find out why people select Puppeteer over other tools by reading <a href="https://www.lucidchart.com/techblog/2018/08/08/why-puppeteer-is-better-than-selenium/"><em>WHY PUPPETEER IS BETTER THAN SELENIUM</em></a><em> or </em><a href="https://flood.io/blog/selenium-vs-puppeteer-for-test-automation-is-a-new-leader-emerging/">Selenium vs. Puppeteer for Test Automation: Is a New Leader Emerging?</a></li></ul><h3>Our case study</h3><p>The idea is we wanted to crawl pricing info from the online shop sites of trade-in mobile devices so that we can compare prices. End-user can select the best site for them. Once we crawled data from the sites, we need to write output in a .csv file and upload it to AWS S3 for archiving, we also need to archive the output in our database for reporting purposes.</p><p>Basically, <strong>Puppeteer</strong> can run on any serverless container such as AWS Lambda or Azure Function, but because of time limitations, we cannot run process longer than <a href="https://aws.amazon.com/about-aws/whats-new/2018/10/aws-lambda-supports-functions-that-can-run-up-to-15-minutes/">15 minutes for AWS Lambda</a> or <a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-scale#consumption-plan">10 minutes for Azure Function that use Consumption plan</a>. Basically, our crapper process took around 1 hour to finish. That is the reason we’ve selected <a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ECS_GetStarted_Fargate.html">AWS Fargate</a> to run our crapper process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*A_JUhOuHCgF7R-aL.png" /><figcaption>Serverless Web Crawler on AWS Fargate Architecture</figcaption></figure><p><strong>Why does AWS Fargate over other services</strong>?</p><p><a href="https://aws.amazon.com/fargate/"><strong>AWS Fargate</strong> </a>allows you to run containers without having to manage servers or clusters. With AWS <em>Fargate</em>, you no longer have to provision, configure, and scale clusters of virtual machines to run containers. Like AWS Lambda, and AWS Fargate, there are no upfront payments and you only pay for the resources that you use. You pay for the amount of vCPU and memory resources consumed by your containerized applications.</p><h3>Let’s get started</h3><p>Configure, and launch a Puppeteer crawler is pretty simple, so I will not mention how to do it in this article. In case you don’t know how to get started, then refer to <a href="https://developers.google.com/web/tools/puppeteer/get-started">this instruction</a> for more details.</p><h3>Example project</h3><p>In order to help you easy to follow this article, I have created a sample project, which you can find it on <a href="https://github.com/innomizetech/ecs-puppeteer-crawler-example">GitHub</a>. This project is different from the above case study, but it is easy to understand and set up. This project contains two simple processes to generate pdfs and screenshots for a URL then upload those files to an S3 bucket.</p><ul><li>First of all, you will need to clone our <a href="https://github.com/innomizetech/ecs-puppeteer-crawler-example">ecs-puppeteer-crawler-example</a> repository from Github:</li></ul><pre>git clone git@github.com:innomizetech/ecs-puppeteer-crawler-example.git</pre><ul><li>Install node modules</li></ul><pre>cd ecs-puppeteer-crawler-example<br>npm install</pre><ul><li>Below is the code of the pdf generator <em>pdf-generator.ts</em> using <strong>Puppeteer</strong> and</li></ul><pre>import { archive } from &#39;./lib/s3-util&#39;;<br>import * as bluebird from &#39;bluebird&#39;;<br>import { emptyDirSync } from &#39;fs-extra&#39;;<br>const argv = require(&#39;yargs&#39;).argv;</pre><pre>const browserless = require(&#39;browserless&#39;)({<br>  headless: !!argv.headless,<br>  ignoreHTTPSErrors: true,<br>  defaultViewport: null,<br>  dumpio: false,<br>  args: [&#39;--disable-setuid-sandbox&#39;, &#39;--no-sandbox&#39;]<br>});</pre><pre>if (!argv.url) {<br>  console.log(&#39;Url is required&#39;);<br>  process.exit(1);<br>}</pre><pre>const devices = browserless.devices.slice(0, 2);<br>const hostname = new URL(argv.url).hostname;</pre><pre>console.time(&#39;Finished in&#39;);</pre><pre>const generatePdf = async () =&gt; {<br>  const generatePdfPerDevice = async device =&gt; {<br>    console.log(<br>      `${new Date().toUTCString()}: Generating pdf for ${device.name} device`<br>    );</pre><pre>    const buffer = await browserless.pdf(argv.url, {<br>      waitUntil: [&#39;load&#39;, &#39;networkidle2&#39;],<br>      fullPage: true,<br>      device: device.name<br>    });</pre><pre>    const fileName = `output/${hostname} on (${device.name}).pdf`;</pre><pre>    return { buffer, fileName };<br>  };</pre><pre>  const data = await bluebird.map(<br>    devices,<br>    device =&gt; generatePdfPerDevice(device),<br>    {<br>      concurrency: 5<br>    }<br>  );</pre><pre>  await bluebird.map(data, item =&gt; archive(item));</pre><pre>  console.timeEnd(&#39;Finished in&#39;);</pre><pre>  process.exit(0);<br>};</pre><pre>emptyDirSync(&#39;output&#39;);<br>generatePdf();</pre><ul><li>You can then generate .pdf for a URL such as <a href="https://www.innomizetech.com/">https://www.innomizetech.com</a> by running the below command:</li></ul><pre># --headless means we want to run without UI<br>env-cmd npx ts-node src/screenshot-generator.ts --url=https://www.innomizetech.com/ --headless</pre><p><em>And here is the console output</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mB6-D9QcfrzuG-9v.png" /><figcaption>Generate pdf console output</figcaption></figure><h3>The steps</h3><p>Now you might wonder how to run, build, deploy, and run your task on AWS ECS either manually or automated. So I wanted to outline the steps we need to perform to set up and run our example project on AWS Fargate.</p><ol><li>Build a docker image and upload it into the ECR repo.</li><li>Create an ECR repo to store docker images. Alternatively, you can use a public <a href="https://hub.docker.com/">docker hub</a>.</li><li>Set up VPC in case you want to run your task under your private network. Otherwise, you can use the default VPC on AWS. <strong>In this project, we use default VPC on a public subnet because our process doesn’t contain any sensitive information, creating a new VPC doesn’t need, even adds more cost if we run under a private subnet.</strong></li><li>Create an S3 bucket for achieving output files.</li><li>Create task definition, ECS cluster, and setup scheduled task to run our task (optional).</li></ol><p>A lot of steps, right? Don’t worry, I will show you how to automate those steps.</p><h3>Infrastructure as code (IaC)</h3><p>There are a couple of ways to automate your infrastructure on AWS cloud such as <a href="https://aws.amazon.com/cloudformation/">AWS CloudFormation</a>, <a href="https://www.terraform.io/">Terraform</a>, and <a href="https://docs.aws.amazon.com/cdk/latest/guide/home.html">AWS CDK</a>. In this project, we use <a href="https://docs.aws.amazon.com/cdk/latest/guide/home.html">AWS CDK</a>, I will have another article to provide more details about AWS CDK and why we use it for our IaC stuff.</p><h3>Pre-requisites</h3><p>Before continuing you need an AWS account. If you do not already have an AWS account, you can utilize their <a href="https://portal.aws.amazon.com/billing/signup">free-tier accounts</a>. Follow <strong>Step 1: Prepare credentials </strong>on <a href="https://blog.innomizetech.com/2019/09/23/serverless-fundamentals-and-how-to-build-test-and-deploy-lambda-function-to-aws-part-2/">my article</a> to configure your credentials to interact with AWS API via CLI. You also need to install <a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html">AWS CLI</a> and <a href="https://docs.docker.com/v17.12/install/">Docker</a> on your machine.</p><h4>Step 1 — Build docker and push to ECR</h4><p>To run <strong>Puppeteer</strong> on AWS Fargate, we need a docker image. Below is our <em>Dockerfile</em> to build our <strong>Puppeteer</strong> code:</p><pre>FROM node:10<br>RUN apt-get update</pre><pre>ENV HOME_DIR /usr/src/app</pre><pre># for https<br>RUN apt-get install -yyq ca-certificates</pre><pre># install libraries<br>RUN apt-get install -yyq libappindicator1 libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6</pre><pre># tools<br>RUN apt-get install -yyq gconf-service lsb-release wget xdg-utils</pre><pre># and fonts<br>RUN apt-get install -yyq fonts-liberation</pre><pre>RUN mkdir -p $HOME_DIR<br>RUN mkdir -p $HOME_DIR/views</pre><pre>WORKDIR $HOME_DIR</pre><pre># Add our package.json and install *before* adding our application files to<br># optimize build performance<br>ADD package.json $HOME_DIR<br>ADD package-lock.json $HOME_DIR</pre><pre># install the necessary packages<br>RUN npm install --unsafe-perm --save-exact --production<br>COPY . $HOME_DIR<br>RUN npm run clean &amp;&amp; npm run build</pre><pre>ENTRYPOINT [&quot;/usr/local/bin/npm&quot;, &quot;run&quot;]<br>CMD [&quot;clean&quot;]</pre><p>To create an ECR repo, build, and push a docker image to AWS ECR, use the <em>build_and_push.sh</em> script. This script also will check and create the repo for you if it doesn’t exist yet.</p><pre>#!/bin/bash</pre><pre># This script is using to build and push docker image to ECR repository</pre><pre>AWS_PROFILE=development<br>REGION=us-east-2<br>REPO_NAME=ecs-puppeteer-crawler-example<br>TAG=latest</pre><pre># Get the account number associated with the current IAM credentials<br>ACCOUNT_ID=$(aws sts get-caller-identity --profile $AWS_PROFILE --query Account --output text)</pre><pre>if [ $? -ne 0 ]<br>then<br>    exit 255<br>fi<br></pre><pre># If the repository doesn&#39;t exist in ECR, create it.<br>echo &#39;Checking repo existance...&#39;<br>aws ecr describe-repositories --region $REGION --profile $AWS_PROFILE --repository-names &quot;${REPO_NAME}&quot; &gt; /dev/null 2&gt;&amp;1</pre><pre>if [ $? -ne 0 ]<br>then<br>    echo &quot;Repo $REPO_NAME doesn&#39;t exist, try to create a new one&quot;<br>    aws ecr create-repository --repository-name &quot;${REPO_NAME} --region $REGION --profile $AWS_PROFILE&quot; &gt; /dev/null<br>fi</pre><pre>echo &#39;Login to ECR Repository...&#39;</pre><pre>$(aws ecr get-login --no-include-email --region $REGION --profile $AWS_PROFILE)</pre><pre>echo &#39;Building and pushing docker image to ECR repository...&#39;<br>docker build -t $ACCOUNT_ID.dkr.ecr.$REGION.amazonaws.com/$REPO_NAME:$TAG .</pre><pre>if [ &quot;$1&quot; != &quot;true&quot; ]; then<br>docker push $ACCOUNT_ID.dkr.ecr.$REGION.amazonaws.com/$REPO_NAME:$TAG<br>fi</pre><pre>echo &#39;Publish docker image completed&#39;</pre><p>Review and update the following parameters on the top of the script file according to your environment and AWS credentials</p><pre>AWS_PROFILE=development<br>REGION=us-east-2<br>REPO_NAME=ecs-puppeteer-crawler-example<br>TAG=latest</pre><p>And then execute the script to create the repo, build docker and push to ECR</p><pre>chmod +x scripts/build_and_push.sh<br>./build_and_push.sh</pre><p>Wait until the script is finished, then you can find your docker image on the <a href="https://us-east-2.console.aws.amazon.com/ecr/repositories?region=us-east-2">AWS ECR</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4jSlEBHZdGTKTPUJ.png" /><figcaption>ECR Docker Image</figcaption></figure><h4>Step 2–5: Provision AWS service and run your task</h4><p>As I have mentioned above, we can automate steps #2 through #5 above by using the <strong>AWS CDK </strong>framework<strong>.</strong> I have created <strong>PuppeteerCrawlerFargateStack</strong> to construct all required resources</p><pre>import cdk = require(&#39;@aws-cdk/core&#39;);<br>import ec2 = require(&#39;@aws-cdk/aws-ec2&#39;);<br>import ecr = require(&#39;@aws-cdk/aws-ecr&#39;);<br>import events = require(&#39;@aws-cdk/aws-events&#39;);<br>import ecs = require(&#39;@aws-cdk/aws-ecs&#39;);<br>import iam = require(&#39;@aws-cdk/aws-iam&#39;);<br>import { EcsTask } from &#39;@aws-cdk/aws-events-targets&#39;;<br>import { PolicyStatement } from &#39;@aws-cdk/aws-iam&#39;;<br>import { Bucket } from &#39;@aws-cdk/aws-s3/lib/bucket&#39;;<br>import { PuppeteerCrawlerFargateStackProps } from &#39;./interfaces&#39;;</pre><pre>export class PuppeteerCrawlerFargateStack extends cdk.Stack {<br>  constructor(<br>    scope: cdk.Construct,<br>    id: string,<br>    props?: PuppeteerCrawlerFargateStackProps<br>  ) {<br>    super(scope, id, props);</pre><pre>    const vpc = this.constructVpc(props);<br>    const cluster = new ecs.Cluster(this, &#39;PuppeteerCrawlerCluster&#39;, { vpc });<br>    const bucket = this.constructArchiveBucket(props);<br>    const taskDef = this.constructTaskDef(props, bucket);</pre><pre>    // Create rule to trigger this be run task<br>    new events.Rule(this, &#39;PuppeteerCrawlerSchedule&#39;, {<br>      schedule: events.Schedule.expression(<br>        props.scheduleExpression || &#39;cron(0/5 * * * ? *)&#39;<br>      ),<br>      description: &#39;Starts the puppeteer crawler job&#39;,<br>      targets: [<br>        new EcsTask({<br>          cluster: cluster,<br>          taskDefinition: taskDef,<br>          subnetSelection: {<br>            subnetType: ec2.SubnetType.PUBLIC<br>          },<br>          containerOverrides: [<br>            {<br>              containerName: &#39;PuppeteerContainer&#39;,<br>              command: [&#39;pdf&#39;]<br>            }<br>          ]<br>        }),<br>        new EcsTask({<br>          cluster: cluster,<br>          taskDefinition: taskDef,<br>          subnetSelection: {<br>            subnetType: ec2.SubnetType.PUBLIC<br>          },<br>          containerOverrides: [<br>            {<br>              containerName: &#39;PuppeteerContainer&#39;,<br>              command: [&#39;screenshot&#39;]<br>            }<br>          ]<br>        })<br>      ]<br>    });<br>  }</pre><pre>  private constructVpc(props: PuppeteerCrawlerFargateStackProps) {<br>    if (props.useDefaultVpc) {<br>      return ec2.Vpc.fromLookup(this, &#39;VPC&#39;, {<br>        isDefault: true<br>      });<br>    }</pre><pre>    return new ec2.Vpc(this, &#39;EcsFargateVPC&#39;, {<br>      cidr: &#39;172.15.0.0/16&#39;,<br>      maxAzs: 1,<br>      // natGateways: 1,<br>      subnetConfiguration: [<br>        {<br>          cidrMask: 16,<br>          name: &#39;Public&#39;,<br>          subnetType: ec2.SubnetType.PUBLIC<br>        }<br>        // In case if you want to run your task under private subnet<br>        // then uncomment below lines and change subnetSelection<br>        // options above to PRIVATE<br>        // {<br>        //   cidrMask: 20,<br>        //   name: &#39;Private&#39;,<br>        //   subnetType: ec2.SubnetType.PRIVATE<br>        // }<br>      ]<br>    });<br>  }</pre><pre>  private constructArchiveBucket(props: PuppeteerCrawlerFargateStackProps) {<br>    return new Bucket(this, &#39;PuppeteerCrawlerArchiveBucket&#39;, {<br>      bucketName: props.bucketName,<br>      removalPolicy: cdk.RemovalPolicy.DESTROY<br>    });<br>  }</pre><pre>  private constructTaskDef(<br>    props: PuppeteerCrawlerFargateStackProps,<br>    bucket: Bucket<br>  ) {<br>    // Role for task<br>    const taskRole = this.constructTaskRole(bucket);<br>    const taskDef = new ecs.FargateTaskDefinition(<br>      this,<br>      &#39;PuppeteerCrawlerTaskDefinition&#39;,<br>      {<br>        memoryLimitMiB: 8192,<br>        cpu: 2048,<br>        taskRole<br>      }<br>    );</pre><pre>    const repo = ecr.Repository.fromRepositoryName(<br>      this,<br>      &#39;PuppeteerCrawlerRepo&#39;,<br>      props.repoName<br>    );</pre><pre>    taskDef.addContainer(&#39;PuppeteerContainer&#39;, {<br>      image: ecs.ContainerImage.fromEcrRepository(repo),<br>      logging: new ecs.AwsLogDriver({<br>        streamPrefix: &#39;puppeteer-data-crawler&#39;,<br>        logRetention: 1<br>      }),<br>      environment: {<br>        S3_BUCKET: bucket.bucketName<br>      }<br>    });</pre><pre>    return taskDef;<br>  }</pre><pre>  private constructTaskRole(bucket: Bucket) {<br>    const taskRole = new iam.Role(this, &#39;EcsTaskRole&#39;, {<br>      assumedBy: new iam.ServicePrincipal(&#39;ecs-tasks.amazonaws.com&#39;)<br>    });</pre><pre>    // Note: we can add more policy here<br>    taskRole.addToPolicy(<br>      new PolicyStatement({<br>        resources: [bucket.bucketArn, `${bucket.bucketArn}/*`],<br>        actions: [&#39;s3:PutObject&#39;]<br>      })<br>    );</pre><pre>    return taskRole;<br>  }<br>}</pre><p>Open the <em>infra/app.ts</em> file and make your desired changes then execute <em>cdk</em> <em>deploy</em> command to deploy and create resources on AWS</p><pre>cd infra<br>cdk deploy</pre><p>An ECS cluster, an S3 bucket, and a CloudWatch schedule will be created automatically, you can find them on <strong>AWS Console Management</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/0*xfQvjV-D3AnLRr3O" /><figcaption>ECS Cluster</figcaption></figure><p>Wait for 5 minutes (default schedule expression from our Github code) then check the ECS Task execution logs on CloudWatch and also S3 bucket</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*ONSDIllTM4uQcbFI" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/593/0*mu_96Tun9NyIlkxP.png" /></figure><p>So far so good, I believe that within 10 minutes you will have a web crawler up and running. You can set up and modify your Puppeteer codes based on your requirement. I also mentioned database archiving (i.e. MySQL or DynamoDB). To implement this, I have some options below:</p><ul><li>Implement directly on the puppeteer code, you can use the <strong>bulkInsert</strong> function of the <em>s3-util</em> to insert bulk records to the database.</li><li>Build a Lambda function trigger object to create the event of the archive S3 bucket.</li></ul><h3>Clean up</h3><p>To avoid increasing your AWS bills, you need to clean up and remove resources on AWS:</p><ul><li>First, you need to empty your S3 bucket.</li><li>Then delete AWS resources by running <strong>destroy</strong> command.</li></ul><pre>cd infra<br>cdk destroy</pre><ul><li>Finally, delete your ECS repo.</li></ul><h3>Summary</h3><p>I know that this article is very long, but I wanted to provide detailed steps to help you understand step by step. Any suggestions and recommendations are welcome.</p><p>Should you run into issues while practicing the steps outlined in this article, I encourage you to reach out to me. You can get in touch with me through my Twitter handle <a href="https://twitter.com/hoangleitvn">@hoangleitvn</a></p><p>Visit our <a href="https://innomizetech.com/blog">blog</a> for more interesting articles. If you have any questions or need help you can contact me via <a href="https://twitter.com/hoangleitvn">Twitter</a>.</p><p>Thank you for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1202c8a66ec4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/innomizetech/building-serverless-web-crawler-with-puppeteer-on-aws-fargate-1202c8a66ec4">Building serverless web crawler with Puppeteer on AWS Fargate</a> was originally published in <a href="https://medium.com/innomizetech">INNOMIZE</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>