Isn't it really annoying to build a server environment or create a deployment tool? This time, I would like to easily build and deploy a server using the AWS service "Elastic Beans Talk" (hereafter EB) that solves such problems. Also, I would like to use the EB CLI that allows you to operate EB from the command line without using the AWS managed console.
I would like to use the minimum configuration Django for the Django environment. http://qiita.com/yu-sa/items/26e413987efa0debc9d7
If you don't have an AWS environment, you can try building the environment for free using qwikLabs. https://qwiklabs.com/focuses/2356
mac os x 10.9.5 EB CLI 3.7.6 AWS CLI 1.10.26
Django & python python 2.7.10 Django 1.9
I'll clone the Django environment.
# git clone https://github.com/yu-sa/my_site.git
The folder structure is
my_site(Work folder)
├─my_site
│ ├─ __init__.py
│ ├─settings.py
│ ├─templates
│ │ └─index.html
│ ├─urls.py
│ ├─views
│ │ ├─__init__.py
│ │ ├─index.py
│ │ └─urls.py
│ └─wsgi.py
├─requirements.txt
└─manage.py
Please move to the above work folder and perform the subsequent work.
Set up the AWS CLI. Set which account to access and use the service to execute commands with the EB CLI.
# aws configure
AWS Access Key ID [********************]: xxxxxxxxxxxx #Access key ID
AWS Secret Access Key [********************]: xxxxxxxxxxxxxxxxxxxxxxxxx #Secret access key
Default region name [ap-northeast-1]: ap-northeast-1 #Tokyo region
Default output format [json]: json
Also configure the EB CLI.
# eb init -i
Select a default region
1) us-east-1 : US East (N. Virginia)
2) us-west-1 : US West (N. California)
3) us-west-2 : US West (Oregon)
4) eu-west-1 : EU (Ireland)
5) eu-central-1 : EU (Frankfurt)
6) ap-southeast-1 : Asia Pacific (Singapore)
7) ap-southeast-2 : Asia Pacific (Sydney)
8) ap-northeast-1 : Asia Pacific (Tokyo)
9) ap-northeast-2 : Asia Pacific (Seoul)
10) sa-east-1 : South America (Sao Paulo)
11) cn-north-1 : China (Beijing)
(default is 3): 8
Select an application to use
1) my_site
2) [ Create new Application ]
(default is 1): 1
It appears you are using Python. Is this correct?
(y/n): y
Select a platform version.
1) Python 3.4
2) Python
3) Python 2.7
4) Python 3.4 (Preconfigured - Docker)
(default is 1): 3
Do you want to set up SSH for your instances?
(y/n): y
Select a keypair.
1) qwikLABS-L98-469340
2) [ Create new KeyPair ]
(default is 2): 2
Type a keypair name.
(Default is aws-eb): aws-eb
Generating public/private rsa key pair.
/Users/xxxxxxxxx/.ssh/aws-eb already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase): (Enter without filling in anything)
Enter same passphrase again: (Enter without filling in anything)
You can customize the settings by adding .ebextensions in the AWS Elastic Beanstalk configuration file. Make additional changes to use the Django environment we're using this time.
The configuration file is created by extending .config.
# mkdir .ebextensions
# vi .ebextensions/django.config
Enter the following in [.ebextensions / django.conf].
option_settings:
"aws:elasticbeanstalk:application:environment":
DJANGO_SETTINGS_MODULE: "my_site.settings"
"aws:elasticbeanstalk:container:python":
WSGIPath: "my_site/wsgi.py"
Since all the settings etc. are completed, let's create an EB environment and automatically build a web server environment.
# eb create my-site-dev --timeout 9000
If you hit this command, the environment construction will start as it is. It may take 10 minutes or more to complete the environment construction, so please leave it for a while.
If you want to check if the environment has been built, please check the environment created in Elastic Beanstalk of the AWS managed console.
Once the environment is built, I would like to check the corresponding page.
# eb open my-site-dev
When you hit this command, the browser will open and the following page will be displayed.
If you add / views / to the above URL, the following page will be displayed.
This completes the environment construction.
The above only builds the web server environment, not the DB environment. I would like to write about using RDS etc. to use the mysql environment again.
After that, I will post the module that has the environment such as eb environment setting on github, so if you want to use it, please clone it. https://github.com/yu-sa/my_site/tree/elasticbeanstalk
Also, if you update the source, you can also deploy with ʻeb deploy my-site-dev` after going to commit with git. It takes about 5 minutes.
Recommended Posts