Running deepl-for-slack bot using docker on EC2 Instance

Overview

Hi! I am is Akshay Rao, currently working in Annotation Japan.
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. null

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.

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.

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
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.
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
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)

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

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.
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.
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.

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.