Skip to content

DrFujiBot on AWS

EverOddish edited this page Jan 16, 2023 · 5 revisions

Django on Elastic Beanstalk

  1. Edit ~/.aws/credentials to add access key in new profile named pchal
  2. cd DrFujiBot_Django
  3. eb init --profile pchal
  4. Open DrFujiBot_Django/settings.py and verify that local is set to False
  5. Edit .ebextensions/db-migrate.config to uncomment the 02_createsuperuser block
  6. eb create drfujibot-env (creates environment and uploads source)
  7. Edit DrFujiBot_Django/settings.py to add the environment URL to ALLOWED_HOSTS
  8. In the AWS Console, open the new environment, click "Configuration", then find "Database" and click "Edit"
  • Engine: postgres
  • Engine version: 14.5
  • Instance class: db.t4g.micro
  • Storage: 5 (GB)
  • Availability: Low (one AZ)
  • Database retention policy: Retain
  1. Run eb deploy with updated ALLOWED_HOSTS

IRC on ECS

  1. Click "Clusters" and then "Create cluster", all default settings (Fargate)
  2. Click "Amazon ECR" on the left, create a repository ("Get started"), private, name "drfujibot"
  3. Open the new repository and click "View push commands"
  4. Copy and run the aws ecr command to log in with docker, and include --profile pchal in the copied aws ecr command
  5. cd DrFujiBot_IRC and ./build_image.sh to build and push to ECR
  6. Go back to ECS, then Task Definitions on the left, then "Create new task definition"
  • Task definition family: DrFujiBot
  • Container name: DrFujiBotIRC
  • Image URI: (image URI from ECR)
  • Remove any port mappings
  • Set environment variables:
    • DJANGO_URL
    • TWITCH_OAUTH_TOKEN
    • TWITCH_CHANNEL
  • App environment: AWS Fargate (serverless)
  • Operating system: Linux/X86_64
  • CPU: .5 vCPU
  • Memory: 1 GB
  • Uncheck "Use log collection"
  1. Go back to ECS, then Services, then Deploy
  • Compute options: Launch type
  • Launch type: FARGATE
  • Platform version: Latest
  • Application type: Service
  • Desired tasks: 1

Database migration

Need to add an inbound rule on the Elastic Beanstalk security group to allow the IP address from which you run psql

  • pg_dump -U drfujibot -h localhost -f /home/everoddish/fuji_backup/drfujibot2.sql drfujibot
  • psql --host=<instance>.us-east-2.rds.amazonaws.com --port=5432 --username=drfujibot --dbname=ebdb --password < ~/fuji_backup/drfujibot2.sql