Currently hosted at: pipelines.yeolab.com
Steps for deployment using Elastic Beanstalk:
1. Install and configure the aws cli
- For this application, it shouldn't matter which version (v1 or v2) is installed. For more information, see documentation
- Add access and secrete access keys to an 'eb-cli' profile:
aws configure --profile eb-cli
. You can generate/find these keys using the AWS console.
- Default region name: select the region closest to you (e.g. us-west-1)
- Default output format: text/JSON, not super important for this app
2. Install the elastic beanstalk cli (eb) with pip:
pip install awsebcli --upgrade --user
- You can do this outside of the application environment to avoid conflicts.
eb init
- Use CodeCommit? I'd choose "No" and stick with Github. Main difference I can see is security/access (CodeCommit is integrated with AWS IAM roles etc. whereas Github is not).
- Create an ssh key/pair? Choosing "Yes" creates a pub/private key pair in your ~/.ssh/. I'd recommend to create one so you can login to your instance via ```eb ssh```
eb create
- DNS CNAME prefix. Use something that makes sense for this application (e.g. metadata-db-prod)
- Load balancer type: application (2). Likely doesn't make any difference with this app
- ensure that the 'global:profile' setting matches the profile from step 1. This ties the application and its environment to your AWS account.
- you can check/modify the size of the instance used as well. For this application, the smallest instance should be good enough.
- This config file allows us to run custom commands during the deployment process.
- Importantly, we will need to migrate changes made to the database
- See django.config -> container_commands -> 01_migrate for an example
- In the AWS console, under your environment go to 'Configuration'. Scroll down to Database and press the 'Edit' button. Choose all defaults and create a username and password (this will be used in the future in settings.py)
- Deploying the main code:
- Commit changes to the main or master branch
eb deploy metadata-db-test
- Deploying uncommited code in case you just want to test:
- Add changes with
git add
eb deploy --staged
(this deploys staged changes as opposed to committed ones)- Sometimes you may need to include the environment name as well:
eb deploy metadata-db-test --staged
- Add changes with
TLDR: fix deployment using either the log files or by poking around with eb ssh
/var/log/cp_log
(tracks issues related to the Django application)/var/log/cfn-init-cmd.log
(tracks issues related to eb deployment)
-
In Route53, lookup and select a valid domain name and purchase one.
-
In elastic beanstalk console under 'environments', copy the URL (*.elasticbeanstalk.com)
-
Once you have a valid domain, you will need to point the domain to your EB instance.
- Under Route53 -> Hosted zones -> DOMAIN, create a CNAME record (name = your domain name, value = elastic beanstalk URL)
-
Now, add SSL protection (HTTPS)
-
Go to the AWS Certificate Manager (ACM) and request a new (public) certificate
-
Add your domain and select a validation method. If you choose DNS validation, you will need to add another CNAME record. This proves that you own the domain.
-
Once verified, a certificate will be granted. Then, go to your elastic beanstalk environment console, and under
Elastic Beanstalk -> Environments -> Your Environment -> Configuration -> Load Balancer:
Add a new HTTPS listener.
Attach the appropriate certificate corresponding to your domain.
443 is typically the default port to use.
And as of 09/22 the recommended ELB Policy is ELBSecurityPolicy-2016-08
-
- replace host with "localhost"
- source file with secrets