Forum Posts

avidani_ilan
Jun 16, 2019
In Cloud
The steps: Create EB Python Environment Setup ‘awsebcli’ on your Machine Commit your code on AWS CodeCommit (optional) Deploy your code Create EB Python Environment: 📷 Here we are going to create an Application and Environment for Python with basic Server Configurations. On AWS Console, perform below steps: Choose Elastic Beanstalk from services. Click on Create New Application and give Name and Description. 📷 3. You have no environment in this application yet, click on Create one nowand select Web server environment as a tier. 📷 4. In the next page you will see auto-filled environment name, here fill/leave the domain, from platform select ‘Pre-configured > Python’(it will install Python 3.6), choose Sample application because this way at least we can verify after environment creation, later we can upload our code. Click on Configure More options button next. 📷 5. We need to setup key-pair. If you already have a key-pair then select that else create a new one(Don’t forget to download). We need this key-pair linked with our environment because it will be required to connect local machine with EB application. 📷 📷 6. Once done you can see the application dashboard with Health ‘ok’, and if your click on application URL you can see the default application page. 📷 Setup ‘awsebcli’ on your Machine awsebcli is EB Command Line Interface which will enable you to handle EB Application and the environment from your Local Machine. Follow below steps: pip install awsebcli Set environment variable path for this, If you don’t know how: Got to System Properties > Advanced > ‘Environment Variables’ > Path (Edit) > New > Paste(C:\Users\{UserName}\AppData\Roaming\Python\Python36\Scripts) Here your path may differ from mine. Once done. Start a new Command Line and run eb -- version. If you face any failure, then you must have set the incorrect environment variable path for EB. Commit your code on AWS CodeCommit (optional) It is not exactly required but is good to have a code backup on AWS CodeCommit. Just make sure you have IAM account created before proceeding with below steps else you will get 403 error: In the project directory, run: eb init  It will ask for a region, select accordingly, In my case, it was 14. Next, it will ask for ‘aws-access-id’ and ‘aws-secret-key’. You must have downloaded a file containing these credentials when created these keys at the first place, if not then create a new one from My Security Credentialssection from Navigation. Once entered, It will ask you to select/create an application. Select the one we created above. Next, it will ask if you wish to commit your code on CodeCommit, go ahead and enter ‘y’. Once done it will ask for Repository and then Branch name, once done it will create a repository, branch and will add git URL in your remote list. Now, you can add, commit and push your code on this remote branch. Deploy your code Few standards needs to be followed to successfully deploy your application on EB. Those who have followed my first post to create this application have already followed these standards and can directly jump to 4th step, others follow all: The server configuration file must be named as application.py and must be placed at the root of your project folder otherwise you have to modify WSGIPath from EB’s option_settings. Inside application.py file, we must have an application variable containing the instance of Flask application. application = Flask(__name__) # run application if __name__ == “__main__”: application.run() 3. We must have the requirements.txt file, containing all the dependencies, on our root. 4. If application.py and requirements.txt files are in place then AWS Server does environment setup on its own. We should create .ebignore file on our root to ignore all the file/folders that are related to virtual environment and additional configurations including README.md and .gitignore because it is not going to be viewed/used by other than AWS Server. My .ebignore file looked like this: Include/ Lib/ Scripts/ xgboost/ .vscode/ .gitignore pip-selfcheck.json pyvenv.cfg README.md 5. To deploy your code, you need to have the key-pair, that we linked with our EB application, inside local system’s home/.ssh directory. For Windows users, the path might be C:/Users/{UserName}/.ssh 6. Now once you have followed above steps, you are ready to execute deploy command: eb deploy It will take a minute or two depending on your project size and will update you with terminal logs once done. We can also use ‘Upload and Deploy’ feature from our application dashboard on Elastic Beanstalk, for that all we need to do is zip the project and upload. Once deployment gets done you should be able to see your application running on your domain or EB default URL (****.elasticbeanstalk.com). Credit for Amardeep Chauhan
2
2
67
avidani_ilan
More actions