requirements : Docker desktop(optional), git
Deploy your bot on AWS ECS
This Demo requires exprience of running bot user(a.k.a bot server) with python
This repositoty is a basic template for AWS CI/CD
by following this, you could develop bot running 24/7 via CI/CD
This file is the key part of CI/CD
After you clone or copy paste this repo, change your component name.
I made every values(name) used in yml as agrs so it could prevent typo
Before running Github Action
you must fill in Github repo Secrets
Once you paste this value, you will not be able to read secret again
Save it some where safe just in case.
required secrets:
-
AWS_ACCESS_KEY_ID
- access key id, you will get this when making
AWS - IAM - USER
- access key id, you will get this when making
-
AWS_SECRET_ACCESS_KEY
- access key id, you will get this when making
AWS - IAM - USER
- access key id, you will get this when making
-
AWS_DEFAULT_REGION
- Your AWS region, could check this when you access
AWS - Management Console
(when you are logged in)
- Your AWS region, could check this when you access
in my case, it's ap-northeast-2
- DISCORD_BOT_TOKEN
- your bot app token check this at discord/developers/applications
you will see
This is a recipe how to set up environment and run your code
at the bottom, the enrty point, if your main script name is main.py
then change to CMD ["python", "main.py"]
Dockerfile for development in local environment.
I wrote how to use at Dockerfile.dev
in local machine(Docker desktop)
it's recommanded to test with dockerfile before deploying at AWS ECS.
This is used for AWS ECS and could use for final test, before running github action
As we are not going to host database server docker container, we don't configure other docker images.
Before testing in local enviornment, you should add env
args in powershell
Make a file named env-secrets.txt
# env-secrets.txt
$env:AWS_ACCESS_KEY_ID="<Your IAM USER KEY ID>"
$env:AWS_SECRET_ACCESS_KEY="<Your IAM User Secret Acces Key>"
$env:AWS_DEFAULT_REGION="<Your AWS region>"
$env:AWS_CONTAINER_NAME="<Your ECR Container name>"
$env:DISCORD_BOT_TOKEN="<Your discord bot app token"
fill in the requirements, and paste it at powershell(or shell in case of Linux/MacOS)
it will look like this if you are using PowerShell in Windows
then run docker-compose up --build
it could take some mintues for installing requirements
If you see Attaching to my-ecr-demo...
go check your bot to see it is online
Then you are ready to deploy at AWS
Once you deployed a bot to AWS, make sure to run test with test-bot token
because after releasing your bot will run 24/7 and you'll not want to run same bot user at the same time.
Since pycord
didn't released 2.x.x to pypi we have to pull from repository.
other dependencies will be installed, defined at pycord/requirements.txt
Main entry point of your bot user.
import your other scripts from ./src
paste from AWS-ECS-Task Definition
not like any other AWS ECS flask demo apps, we don't need port forwarding, discord bot user is client to discord
and we don't need load balancer (AWS ELB, Elastic Load Balancer)
because pycord(discord.py) is event based
If your bot serves hundreds of server, take account of Auto scaling of AWS EC2 instance
Change region and ECR, ECS services name at .github/workdlows/aws.yml
before running
MIT
Released under MIT by @ccppoo.
badges used - michaelcurrin/badge-generator