<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Edgar Gonzalez</title>
    <description>The latest articles on Forem by Edgar Gonzalez (@edgargonzalez525).</description>
    <link>https://forem.com/edgargonzalez525</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F378148%2F48f4e356-a1ae-4774-8c0d-303153e1093e.png</url>
      <title>Forem: Edgar Gonzalez</title>
      <link>https://forem.com/edgargonzalez525</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/edgargonzalez525"/>
    <language>en</language>
    <item>
      <title>Free Exchange rate API</title>
      <dc:creator>Edgar Gonzalez</dc:creator>
      <pubDate>Sat, 09 May 2020 20:24:16 +0000</pubDate>
      <link>https://forem.com/edgargonzalez525/free-exchange-rate-api-3h8a</link>
      <guid>https://forem.com/edgargonzalez525/free-exchange-rate-api-3h8a</guid>
      <description>&lt;p&gt;Hey guys, right now I'm looking for an API that allows you to convert from one currency to another, this is for a personal project so I'm looking for something free at the moment, I found several APIs that offer a free version but they all limit the number of requests per month, and is usually a very small amount.&lt;/p&gt;

&lt;p&gt;Any help would be very appreciated.&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to deploy your app on AWS with Docker</title>
      <dc:creator>Edgar Gonzalez</dc:creator>
      <pubDate>Sun, 03 May 2020 05:17:49 +0000</pubDate>
      <link>https://forem.com/edgargonzalez525/how-to-deploy-your-app-on-aws-with-docker-1gfp</link>
      <guid>https://forem.com/edgargonzalez525/how-to-deploy-your-app-on-aws-with-docker-1gfp</guid>
      <description>&lt;p&gt;I will be explaining how to deploy your dockerized app in AWS using a Fargate instance, the process for an EC2 instance should be very similar, so this guide will also work for you.&lt;/p&gt;




&lt;p&gt;In a previous &lt;a href="https://dev.to/edgargonzalez525/how-to-easily-dockerize-your-nestjs-app-46nf"&gt;article&lt;/a&gt;, I explained how to dockerize a NestJs app, for the purpose of this guide I will be using the same codebase to create the Docker image that will be deployed in AWS.&lt;/p&gt;

&lt;p&gt;To follow these steps I will assume you have the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A Docker script to build your image.&lt;/li&gt;
&lt;li&gt;The &lt;a href="https://aws.amazon.com/cli/"&gt;AWS cli&lt;/a&gt; configured in your machine.&lt;/li&gt;
&lt;li&gt;Some basic knowledge of AWS and Docker.&lt;/li&gt;
&lt;/ol&gt;




&lt;h1&gt;
  
  
  Step 1 - Docker repository
&lt;/h1&gt;

&lt;p&gt;You need to create a Docker repository in your AWS account, it can be done executing the command below:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;aws ecr create-repository --repository-name=&amp;lt;YOUR_REPOSITORY_NAME&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After your repository is created go to &lt;code&gt;Elastic Container Service -&amp;gt; Amazon ECR -&amp;gt; Repositories&lt;/code&gt; in your AWS account. There look for your newly created repository and click on it. Once your repo is opened click on the &lt;code&gt;View push commands&lt;/code&gt; button. You will get something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--x0OGB-eN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/2lc79v2ndd5cusm1fszx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--x0OGB-eN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/2lc79v2ndd5cusm1fszx.png" alt="View push commands"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Copy all these commands, as you will need them later on to build, push and deploy your app.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To avoid copying these commands every time we build our app, we can create some scripts in our &lt;code&gt;package.json&lt;/code&gt; to automate the process.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you are not deploying a JS app, you can use a shell script or some other tool you feel comfortable with.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h1&gt;
  
  
  Step 2 - Automated script
&lt;/h1&gt;

&lt;p&gt;To make our lives easier we will setup the following scripts in the &lt;code&gt;package.json&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"aws:login"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin &amp;lt;ID&amp;gt;.dkr.ecr.us-west-2.amazonaws.com/nestjs"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"docker:build"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"docker build -t nestjs ."&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"docker:tag"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"docker tag nestjs:latest &amp;lt;ID&amp;gt;.dkr.ecr.us-west-2.amazonaws.com/nestjs:latest"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"docker:push"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"docker push &amp;lt;ID&amp;gt;.dkr.ecr.us-west-2.amazonaws.com/nestjs:latest"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Remember to replace all these commands with the ones you copied from your repository.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let me explain what each one of these commands do:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;aws:login&lt;/code&gt; - Executed the login command so you can properly authenticate with your AWS cli.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;docker:build&lt;/code&gt; - Build your Docker image using your local &lt;code&gt;Docker&lt;/code&gt; script.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;docker:tag&lt;/code&gt; - Tag your recently created image with the name you copied from your repository.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;docker:push&lt;/code&gt; - Push your image to the AWS server.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I will also add a new script, to execute all the previous commands in secuence (yes, I'm a bit lazy, I don't want to type all those commands every time I build my image).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"aws:build"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"npm run aws:login &amp;amp;&amp;amp; npm run docker:build &amp;amp;&amp;amp; npm run docker:tag &amp;amp;&amp;amp; npm run docker:push"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now if you run the &lt;code&gt;aws:build&lt;/code&gt; command (&lt;code&gt;npm run aws:build&lt;/code&gt;), you will build, tag and push your Docker image into your AWS account. We will use this on the next steps to deploy your app. After executing the command this is how my repository looks:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--o9cNMysN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/nr1nst5fb4ha576hf3vj.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--o9cNMysN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/nr1nst5fb4ha576hf3vj.jpg" alt="Repository images"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  Step 3 - Create Task Definition
&lt;/h1&gt;

&lt;p&gt;Before creating your task definition make sure you have a role with the &lt;a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_execution_IAM_role.html"&gt;AmazonECSTaskExecutionRolePolicy&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Now, you need to create a Task definition that will be later used by a service to create the instances of your Docker image. To create a Task definition go to &lt;code&gt;Elastic Container Service -&amp;gt; Amazon ECS -&amp;gt; Task Definitions&lt;/code&gt;, and click on the &lt;code&gt;Create new Task Definition&lt;/code&gt; button and follow the next steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Select launch type compatibility - Fargate.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--46wEqcv0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/bxiikf205sqddbvdasrv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--46wEqcv0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/bxiikf205sqddbvdasrv.png" alt="Task definition type"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Set your task name and execution role.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4wFhy8x3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/3scralxwj6i3pws3p8ox.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4wFhy8x3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/3scralxwj6i3pws3p8ox.png" alt="Task creation"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Set task size (this will change depending on your needs).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5uoyJ5fi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/piwfpf6vv2cxr8vtw7oo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5uoyJ5fi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/piwfpf6vv2cxr8vtw7oo.png" alt="Task size"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create task container (for the purpose of the guide I won't go deep on each of the options you can specify here, I will keep it simple for now).&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;For the Image field you need to specify the URL of your repository.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yrY_jx1S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/u60bjxosiqk03tu6gdov.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yrY_jx1S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/u60bjxosiqk03tu6gdov.png" alt="Task container"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Save your task.&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  Step 4 - Create Cluster
&lt;/h1&gt;

&lt;p&gt;On this step you will create the cluster that will be used to create the services to deploy your app.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Select Networking Only cluster as we will be creating Fargate instances.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UJRbL5Qs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/82dfumggzc6op8fojb6x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UJRbL5Qs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/82dfumggzc6op8fojb6x.png" alt="Cluster creation"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Set cluster name, check the "Create VPC" checkbox and save.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pIBrTPsz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/wrxctv2yot87lb3lz4gs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pIBrTPsz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/wrxctv2yot87lb3lz4gs.png" alt="Cluster name"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  Step 5 - Create Service
&lt;/h1&gt;

&lt;p&gt;Go to the services tab inside your recently created cluster and click on the &lt;code&gt;Create&lt;/code&gt; button.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Set your service type as Fargate, your task definition and cluster as the ones you created, for the service name I usually have the &lt;code&gt;-service&lt;/code&gt; suffix to identify them easier. And for this case we will set the number of instances as 1 (this will depend on your needs).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vttirjnu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cgls5gzi7i065inrmx48.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vttirjnu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cgls5gzi7i065inrmx48.png" alt="Fargate service"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Set the VPC value with the one that was created with the cluster and set some subnets where your service will be available, also set the "Auto-assign public IP" property to "Enabled". For the rest of the fields you can keep them as their default values and click the &lt;code&gt;Next step&lt;/code&gt; button.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EM9fZ4lL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/oxqn1q37gsjuuxxpnqs8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EM9fZ4lL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/oxqn1q37gsjuuxxpnqs8.png" alt="Service creation"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;For the Auto-scaling options, keep the default values and click the &lt;code&gt;Next step&lt;/code&gt; button.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click &lt;code&gt;Create Service&lt;/code&gt; and wait for your service to be created.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now that you have created your service, let's check our deployed app. First you need to go to the task that was created by your service.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jX49eURL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0pvfo9jl86zvxvzwote3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jX49eURL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0pvfo9jl86zvxvzwote3.png" alt="Service Task"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here you can find the Public IP address of your instance. And looking for that IP directly on your browser should show your running APP.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YuKiWyJD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/o67djzbvoqntttxz62mh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YuKiWyJD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/o67djzbvoqntttxz62mh.png" alt="Service Task IP"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Running APP&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0c-7S5bd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ydwlpubwhr34luqxr521.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0c-7S5bd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ydwlpubwhr34luqxr521.png" alt="Running App"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;NOTE: if your app is not running on the port &lt;code&gt;80&lt;/code&gt; you will need to open the port your container is exposing on the security group that your service is using, this can be done on your security group inbound rules.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Awesome!! You made it!! now your app is running on a Fargate container in AWS, but, what if we need to make some changes in our app? How do we update our Docker image and re-deploy the new changes?. I will talk about it in the next step.&lt;/p&gt;




&lt;h1&gt;
  
  
  Step 6 - Re-Deploy your app with new changes.
&lt;/h1&gt;

&lt;p&gt;Imagine that we got a new requirement for a new feature on our app, and we need to push those changes to our Fargate container, for that there are a couple of steps we need to follow:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Build Docker image with new changes.&lt;/li&gt;
&lt;li&gt;Tag Docker image.&lt;/li&gt;
&lt;li&gt;Push Docker image.&lt;/li&gt;
&lt;li&gt;Deploy container with the new changes.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The first 3 steps we got them covered on the scripts we created before, we only need one last script.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"aws:deploy"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"aws ecs update-service --cluster test-cluster --service nestjs-service --force-new-deployment --region=&amp;lt;YOUR_REGION&amp;gt;"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This command will force your service to re-create with the latest changes from the Docker image. After making new changes on your app you can run the following command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm run aws:build &amp;amp;&amp;amp; npm run aws:deploy&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command will build, tag, push and re-create the container with the latest changes.&lt;/p&gt;

&lt;p&gt;You can find the source code for this guide &lt;a href="https://github.com/edgargonzalez525/nestjs-cron"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>docker</category>
      <category>devops</category>
      <category>aws</category>
      <category>showdev</category>
    </item>
    <item>
      <title>How to easily Dockerize your NestJs App</title>
      <dc:creator>Edgar Gonzalez</dc:creator>
      <pubDate>Sat, 02 May 2020 19:22:18 +0000</pubDate>
      <link>https://forem.com/edgargonzalez525/how-to-easily-dockerize-your-nestjs-app-46nf</link>
      <guid>https://forem.com/edgargonzalez525/how-to-easily-dockerize-your-nestjs-app-46nf</guid>
      <description>&lt;p&gt;In this &lt;a href="https://dev.to/edgargonzalez525/how-to-schedule-a-cron-job-with-nestjs-in-less-than-5-mins-cmi"&gt;previous article&lt;/a&gt; I talked about how to create cron jobs with a NestJs application, now I'm going to take that same app and create a Docker script that we can use to deploy it on a production environment like AWS.&lt;/p&gt;

&lt;p&gt;You can find the source code for this guide &lt;a href="https://github.com/edgargonzalez525/nestjs-cron"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I will assume you have some basic knowledge of how Docker works for this guide.&lt;/p&gt;

&lt;p&gt;To Dockerize our app we are going to be using the following Docker file:&lt;/p&gt;

&lt;p&gt;You can also find a gist for this Docker script &lt;a href="https://gist.github.com/edgargonzalez525/1313af5d7e44a8437acc58184ba469c9"&gt;here&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="s"&gt; node:12.15.0-alpine&lt;/span&gt;

&lt;span class="c"&gt;# Create app directory&lt;/span&gt;
&lt;span class="k"&gt;WORKDIR&lt;/span&gt;&lt;span class="s"&gt; /usr/src/app&lt;/span&gt;

&lt;span class="c"&gt;# Copy package files&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; package*.json ./&lt;/span&gt;

&lt;span class="c"&gt;# Install npm packages&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt;

&lt;span class="c"&gt;# Bundle app source&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; . .&lt;/span&gt;

&lt;span class="c"&gt;# Build our app for production&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;npm run build

&lt;span class="k"&gt;EXPOSE&lt;/span&gt;&lt;span class="s"&gt; 3000&lt;/span&gt;
&lt;span class="k"&gt;CMD&lt;/span&gt;&lt;span class="s"&gt; [ "npm", "run", "start:prod" ]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;I will go through each of the lines on the file and explain what they mean.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;FROM node:12.15.0-alpine&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this line we are telling Docker to use as a base image the node:12.15.0-alpine, this node version was enough for the purpose of our app, I recommend always using a fixed version for your Docker scripts and not the latest o stable one, because when those versions change something can break on your app. So manual version updated are preferred by me.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;WORKDIR /usr/src/app&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is the directory where we will copy and build our app.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;COPY package*.json ./&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A wildcard is used to ensure both package.json AND package-lock.json are copied where available (npm@5+)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;RUN npm install&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here we will install all npm dependencies. It is recommended to use &lt;code&gt;npm ci&lt;/code&gt; instead for prod environment, but I had some trouble to make that work properly with NestJs build command so I kept it simple with the usual &lt;code&gt;npm install&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;COPY . .&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Copy the rest of the app files. To avoid copying unwanted files, like the local dist folder or node_modules folder use a &lt;code&gt;.gitignore&lt;/code&gt; file.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;RUN npm run build&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Execute the build command of our project, this will internally execute the NestJs build command and will generate the distribution files of our app.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;EXPOSE 3000&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This line is to expose port 3000 on the Docker instance that will be created. This port will depend on the port your app runs.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;CMD [ "npm", "run", "start:prod" ]&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Finally, execute our app and keep it running in the Docker instance.&lt;/p&gt;

&lt;p&gt;To test the Docker script you can execute the following commands on the root of the project, remember to create the Docker and the &lt;code&gt;.dockerignore&lt;/code&gt; files.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Build docker image &lt;code&gt;docker build -t nestjs-cron .&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Run docker instance on port 3010 of our local machine &lt;code&gt;docker run --name nestjs-cron -p 3010:3000 nestjs-cron&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As you saw it is very simple to dockerize our NestJs app. See you the next time.&lt;/p&gt;

</description>
      <category>docker</category>
      <category>javascript</category>
      <category>showdev</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to schedule a cron job with NestJs in less than 5 mins</title>
      <dc:creator>Edgar Gonzalez</dc:creator>
      <pubDate>Sat, 02 May 2020 19:20:33 +0000</pubDate>
      <link>https://forem.com/edgargonzalez525/how-to-schedule-a-cron-job-with-nestjs-in-less-than-5-mins-cmi</link>
      <guid>https://forem.com/edgargonzalez525/how-to-schedule-a-cron-job-with-nestjs-in-less-than-5-mins-cmi</guid>
      <description>&lt;p&gt;Yes, I know you can setup a cron job directly with Linux, or with plain node libraries, but, in my case coming from and angular background developing with NestJs made things much simpler, also, I think it is really fun trying new approaches just for the sake of it. Taking that into account let's continue.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Creating cron this way is not at OS level, it will only be at app level, so if your app stops the cron won't execute anymore. &lt;/p&gt;

&lt;p&gt;This is particularly useful when you don't have access to change or set OS level configurations.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A couple of days ago I was in the need of developing a very simple app, that fetched some information from an API every minute and posted the results in a Slack channel (you can read about the slack part over &lt;a href="https://dev.to/edgargonzalez525/how-to-create-a-slack-robot-in-3-easy-steps-cho"&gt;here&lt;/a&gt;). I have developed a couple of apps with NestJs in the past and wanted to give it a try this time.&lt;/p&gt;

&lt;p&gt;The first thing you need to do is to install NestJs cli (if you haven't already), with the following command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm i -g @nestjs/cli&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You can also use &lt;a href="https://www.npmjs.com/package/npx"&gt;npx&lt;/a&gt; if you don't want to install the cli globally.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;After that you can create your project with this command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;nest new project-name&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;There is already a built-in Scheduler module inside NestJs we can use, and it uses &lt;a href="https://github.com/kelektiv/node-cron"&gt;node-cron&lt;/a&gt; package internally, you can install it with the following command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install --save @nestjs/schedule&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Once you have installed the package add it to the &lt;code&gt;app.module&lt;/code&gt; like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Module&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@nestjs/common&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ScheduleModule&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@nestjs/schedule&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Module&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;imports&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nx"&gt;ScheduleModule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;forRoot&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;AppModule&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now, you need to create a service and provide it in your &lt;code&gt;app.module&lt;/code&gt; as well, that will be as simple as running the following command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;nest generate service cron&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now that you have the service ready let me explain some types of crons you can create with the Schedule module.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Custom cron expressions, something similar to &lt;code&gt;10 * * * *&lt;/code&gt;, that will run your cron every 10 minutes or &lt;code&gt;0 20 * * *&lt;/code&gt;, that will run your cron every day at 8:00 PM. You can read more about cron expressions &lt;a href="https://github.com/kelektiv/node-cron"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Predefined expressions from the &lt;code&gt;CronExpression&lt;/code&gt; enum, something like &lt;code&gt;CronExpression.EVERY_MINUTE&lt;/code&gt; or &lt;code&gt;CronExpression.EVERY_2_HOURS&lt;/code&gt;, this enum contains common human-readable cron expressions you can use.&lt;/li&gt;
&lt;li&gt;Crons that runs only once after X milliseconds, something like &lt;code&gt;run 5 minutes after the app started&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Custom cron expressions
&lt;/h2&gt;

&lt;p&gt;To set custom cron expressions, you need to use the &lt;code&gt;@Cron&lt;/code&gt; decorator over the method that will be executed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Cron&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;*/10 * * * * *&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;runEvery10Seconds&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Every 10 seconds&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Predefined cron expressions
&lt;/h2&gt;

&lt;p&gt;To use predefined expressions you also need to use the &lt;code&gt;@Cron&lt;/code&gt; decorator, but instead of writing the expression yourself you will take it from the &lt;code&gt;CronExpresion&lt;/code&gt; enum:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Cron&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;CronExpression&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;EVERY_MINUTE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;runEveryMinute&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Every minute&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;You can find all Predefined expressions &lt;a href="https://github.com/nestjs/schedule/blob/master/lib/enums/cron-expression.enum.ts"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Run once after x milliseconds
&lt;/h2&gt;

&lt;p&gt;If you ever come to a scenario that you need to execute a method some time after your app started, and only once, you can use the &lt;code&gt;@Timeout&lt;/code&gt; decorator like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Timeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;15000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;onceAfter15Seconds&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Called once after 15 seconds&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Once you run &lt;code&gt;npm run start:dev&lt;/code&gt;, you will see something similar to this in your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Every 10 seconds
Called once after 15 seconds
Every 10 seconds
Every 10 seconds
Every 10 seconds
Every 10 seconds
Every minute
Every 10 seconds
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Those are all the types I will cover on this post, there are other cool functionalities for creating cron jobs dynamically using Schedule modules API. You can take a deeper look &lt;a href="https://docs.nestjs.com/techniques/task-scheduling"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can find the source code for this example &lt;a href="https://github.com/edgargonzalez525/nestjs-cron"&gt;here&lt;/a&gt;. See you the next time.&lt;/p&gt;

&lt;p&gt;And if you are interested on how to dockerize your NestJs app, you can check this &lt;a href="https://dev.to/edgargonzalez525/how-to-easily-dockerize-your-nestjs-app-46nf"&gt;article&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>showdev</category>
    </item>
    <item>
      <title>How to create a Slack robot in 3 easy steps</title>
      <dc:creator>Edgar Gonzalez</dc:creator>
      <pubDate>Sat, 02 May 2020 16:04:28 +0000</pubDate>
      <link>https://forem.com/edgargonzalez525/how-to-create-a-slack-robot-in-3-easy-steps-cho</link>
      <guid>https://forem.com/edgargonzalez525/how-to-create-a-slack-robot-in-3-easy-steps-cho</guid>
      <description>&lt;p&gt;Hey guys a few days ago I needed to create a Slack app to fetch details from one API and post into a Slack channel if there were any changes. I'm going to explain an easy step by step on how to create your own Slack app and post custom messages on a channel.&lt;/p&gt;

&lt;h1&gt;
  
  
  Step 1 - Get your APP token
&lt;/h1&gt;

&lt;p&gt;The first thing you need is to do is creating a Slack app. You can do that going &lt;a href="https://api.slack.com/apps"&gt;here&lt;/a&gt;. Once you have your app ready, you need to give it the correct permissions to post messages in a channel (&lt;em&gt;for the purpose of this guide, I'm going to assume you only need to post messages to a particular channel, and you also know the channel ID as this was also my case&lt;/em&gt;).&lt;/p&gt;

&lt;p&gt;Requesting these permissions is as easy as:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Load up the settings for your app from the &lt;a href="https://api.slack.com/apps"&gt;app management page&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;In the navigation menu, choose the OAuth &amp;amp; Permissions feature.&lt;/li&gt;
&lt;li&gt;Scroll down to the Scopes section, and pick &lt;code&gt;chat:write&lt;/code&gt; from the drop-down menu.&lt;/li&gt;
&lt;li&gt;Scroll back to the top of this page and look for the button that says 5. &lt;em&gt;Install App to Workspace&lt;/em&gt; (or &lt;em&gt;Reinstall App&lt;/em&gt; if you've done this before). Click it.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You'll now see a permission request screen to install your app to its original workspace.&lt;/p&gt;

&lt;p&gt;If you had already installed your app to its original workspace before, you might still see the permissions screen if the scopes you just added weren't previously granted to your app.&lt;/p&gt;

&lt;p&gt;Authorize your app and you should see a success message. On the OAuth &amp;amp; Permissions settings page you're brought back to, you should now see an OAuth access token available.&lt;/p&gt;

&lt;p&gt;Grab this token and store it for later, as we'll use that token to make some Web API calls.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you want to read more about all the scopes you can add to your app and the details, you can click &lt;a href="https://api.slack.com/scopes"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Step 2 - Add your app in the channel
&lt;/h1&gt;

&lt;p&gt;One important step also, is to add your recently created app to your channel, go to your channel details and click on "Add apps"&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1caGsjaR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gz7ugarsuq0g5dvao822.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1caGsjaR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gz7ugarsuq0g5dvao822.png" alt="Add app to slack channel"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Find your app and click on the "Add" button&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--V8eRhf6D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/6z5qiqqegu4s8ym7ubx5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--V8eRhf6D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/6z5qiqqegu4s8ym7ubx5.png" alt="Add app to slack channel"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Step 3 - Post messages in a Slack channel
&lt;/h1&gt;

&lt;p&gt;Copy your app access token:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RnSs_2gq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/x585l4zbo0z5hn88l34m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RnSs_2gq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/x585l4zbo0z5hn88l34m.png" alt="Slack access token"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Find the channel ID you will be posting the messages into, you can find it here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kPdd1mS_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cn2zak9me1m5mugxox6k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kPdd1mS_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cn2zak9me1m5mugxox6k.png" alt="Slack channel ID"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After you have completed previous steps, is only a matter of making a post request to this API:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;POST https://slack.com/api/chat.postMessage
Content-type: application/json
Authorization: Bearer YOUR_TOKEN_HERE
{
  "channel": "YOUR_CHANNEL_ID",
  "text": "Hello, world"
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In my case it was something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;POST https://slack.com/api/chat.postMessage
Content-type: application/json
Authorization: Bearer &amp;lt;my-app-token&amp;gt;
{
  "channel": "test-channel",
  "text": "Hello, world"
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You will get something similar to the image below on your channel:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--U0rTmAWn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1jhrewfz37vlzzjov4ro.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--U0rTmAWn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1jhrewfz37vlzzjov4ro.png" alt="Slack robot message"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And that will be all guys, if you want to make more complex messaging interactions I recommend you going to the &lt;a href="https://api.slack.com/messaging"&gt;Slack documentation&lt;/a&gt; and read more about it.&lt;/p&gt;

&lt;p&gt;See you next time.&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
