Skip to content

Instantly share code, notes, and snippets.

@seLain
Last active May 7, 2021 05:30
Show Gist options
  • Save seLain/dd7b7f142260f4508144743f6a3f1f33 to your computer and use it in GitHub Desktop.
Save seLain/dd7b7f142260f4508144743f6a3f1f33 to your computer and use it in GitHub Desktop.
Django on AWS
## useful refs
* https://realpython.com/deploying-a-django-app-to-aws-elastic-beanstalk/#Create.the.Admin.User
* https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html
## CLI approach
1. Enter your project root (versioned with Git)
2. install awsebcli
2.1 if encountering trouble installing PyYAML, using prepackages wheel:
3. > eb init
4. > eb create
5. > eb deploy
6. > eb list (to check)
7. > eb open
8. > eb terminate
9. If some css/js effect not showing out...
9.1 set settings.py
'''
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = 'static'
'''
9.2 > python manage.py collectstatic
9.3 > add collected static to git repo
9.4 > eb deploy
reference for createsuper user command:
https://realpython.com/deploying-a-django-app-to-aws-elastic-beanstalk/#Create.the.Admin.User
10 > eb open
If encountered 'attempt to write a readonly database' exception while login,
it's probably caused by permission issue againt db.sqlite3 (if using default db.sqlite3 database)
solution(1) : > db ssh to login in AWS, and cd to /opt/python/current/app , chown wsgi db.sqlite3
solution(2) : add chown command to config just behind the migrate command, do > eb deploy
'''
02_chown_sqlitedb:
command: "sudo chown wsgi db.sqlite3"
leader_only: true
'''
## AWS Console approach
1. Create EB isntance on AWS console
2. local, pip install awsebcli
2.1 if encountering trouble installing PyYAML, using prepackages wheel:
3. Enter your project root (versioned with Git)
4. > eb init
4.1 input creditials: generated and retrieved from https://console.aws.amazon.com/iam/home?#/security_credential
4.2 on win, need to install openssh if you would like to set SSH during eb init
5. > eb create my-env (rename as needed)
6. package all files needed as .zip
7. upload .zip to EB isntance and wait for running
* YAML validator: http://yaml-online-parser.appspot.com/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment