Post

Migration Yelp-Camp WebApp from Heroku to AWS Elastic Beanstalk and MongoDB Atlas to AWS DocumentDB

Table of contents

Goal

  • migrate a web app that was built as the main project for a web developer bootcamp udemy class to AWS.
  • The app was built with ExpressJS as the backend and bootstrap for the frontend
  • We want to migrate the following
    • Mongodb to AWS DocumentDB
    • Heroku to Elastic Beanstalk for the hosting of the webapp

Database Migration

Steps

  • backedup the db that was uploaded to mongodb atlas
  • just created a DocumentDB single instance and imported all the data there
  • DocumentDB does not have a public endpoint, meaning that you cannot connect to the db from your local computer it has to be from a vpc

App migration

EB CLI

  • eb documentation

Installing the EB CLI using pip

  • pip install awsebcli
  • The AWS Elastic Beanstalk Command Line Interface (EB CLI) is a command line client that you can use to create, configure, and manage Elastic Beanstalk environments. For more information about the EB
  • Installing the cli

use EB to generate the configuration file

  • eb init --platform node.js --region us-east-2
    • this will require an access key and secret key
      • to create these go into iam and create access keys for a user you would like to use preferrably not the root user
    • This will create a folder in the root directory named .elasticbeanstalk
    • This will create a file under that folder named config.yml
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      
      branch-defaults:
        main:
          environment: YelpCamp-env
      environment-defaults:
        YelpCamp-env:
          branch: null
          repository: null
      global:
        application_name: YelpCamp
        default_ec2_keyname: YelpCamp
        default_platform: Node.js 18
        default_region: us-east-2
        include_git_submodules: true
        instance_profile: null
        platform_name: null
        platform_version: null
        profile: eb-cli
        sc: git
        workspace_type: Application
      

How to access the logs, so helpful

  • explain

Errors Encountered

Environment variables

  • eb setenv
  • eb printenv

See the status of the Elastic Beanstalk

  • eb status

Cloudformation failed multiple times trying to create my stack

  • Errors I would get
  • alt-text

Nginx 502

  • explain
  • created new file .ebextensions/app.config
    • 1
      2
      3
      
      option_settings:
      aws:elasticbeanstalk:application:environment:
      PORT: "8080"
      

Configuring Express app for Elastic Beanstalk

References

This post is licensed under CC BY 4.0 by the author.