Running deepl-for-slack bot using docker on EC2 Instance
Tags: docker, vscode, slack
Published: 2022-08-29 09:04:41

**Overview**
Hi! I am is Akshay Rao.
The slack bot translates the text that is posted in slack channel by reacting different country's flag emojis to that post.The bot will reply with the translated text in thread.I tried to run bot on AWS platform using tools like VS Code, Docker, EC2 instance and GitHub. 

The code for the app is in this GitHub repository - https://github.com/seratch/deepl-for-slack. 

**Let's Start**
First we will have to Create a slack app which will communicate with the deepl server for translating the text. Sign-in in slack api-> create new app-> give name ->give workspace name In OAuth&permission-> scopes->add all the OAuth scope which is given in the pic below. Install the app in your slack channel.

![Image 1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hpd4rntgyftljtqz1bxs.png)

- Cloning the repository

We will have to get the app code from the GitHub repository, for that we will have to clone the repository in VS Code. Before that make sure that git and docker desktop is installed. Put the repository url and choose the folder in which the repository has to be cloned.Now we have cloned the repository.
![Image 2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5tmqo6vcffetp1ab2khd.png)

- Building a docker image

Create a new file and name it Dockerfile,[when u type this name docker symbol will appear] and make sure that is not saved in any other format.We will have to write the commands which will run our container.
This is the code for Dockerfile.
![Image 3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g2m8b9tfugpt45cu6jeb.png)
Install docker in VS Code by clicking on the extension icon[fourth icon from the top left,it has three boxes one box out].
Put the slack bot token, signing secret, deep authentication token in .env file and please verify it throughly before building a image.
![Image 4](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rcvsb2nltkb47bet0mvv.png)
Now we will build the image by running the command “docker build . -t name of the image”, this command will build and also -t will tag the image with a name. It will be easier to identify the image while handling many images.It will take time to build, then the pointer will come back to your folder, now put “docker images” the images that have been created will appear.
![Image 5](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/10wz16ha9314qdwsvzvy.png)
Now will have to push the image to the docker remote repository, so the we can pull this image to the instance.click on -> docker symbol->click on connect Registry->select docker Hub->put Docker ID and Password.
![Image 6](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f7yckag0if559dvgbhks.png)
The docker remote repository will be connected(if it does not work re-enter the credentials), now we will push the latest image to the docker hub. Right click on latest -> push.
The image will appear in the docker desktop(it will take time).
![Image 7](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j0qv1v35xetevufklb2j.png)

- Deploy on EC2 Instance

Login in to your AWS account and launch a linux instance, add a security group rule of custom TCP->port 3000->source from 0.0.0.0/0 and ::/0.Can set up session agent in the instance so that entering in the instance will be easy or directly is connect or can ssh also if connect is not working.
In the instance execute the below commands.
![Image 8](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zf4f6desa2ox2hbf6u1m.png)
The container is successfully deployed
If it shows some error try “docker ps” or “docker logs (container ID) | head” in this log we can see where the error is occurring and fix it.
![Image 9](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y9bsiq8zw9b2v49gpslz.png)
Take the instance public IPv4 address and put it in this format -http://(IP address):3000/slack/events in the event subscription, get it verified.
![Image 10](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/khxydq789yv55cgis2n3.png)
In your workspace/channel where slack bot is deployed and type hello and react with any country’s flag, in the reply the translation of hello in that country’s language will appear.
![Image 11](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u6f51z4txinvb6suvpbr.png)
**Conclusion**

I am very thankful to Kazuhiro Sera (seratch) from slack, who has built this amazing app.
I hope this blog has helped you in practical aspects of EC2 instance and docker.