Building an environment to execute python programs on AWS EC2

I tried to run .py in my local environment, but I couldn't understand Python3, pip3, Python, and Pip, so I decided to run it on AWS.

How to do it : zap: Comments welcome: zap:

1. Register with AWS

Googling with aws and creating an account Just enter your email address and password

2. Select EC2

There are various services, but click EC2

3. Create a new instance

You can set it according to AWS Getting Started. All free guy

After selecting this, click the blue button "Review & Launch Instance"

A pop-up asking you to save the key pair will appear, so select "Create New Key Pair" and save the .pem file.

4. Connect to instance

Go to the EC2 Dashboard and click the checkbox next to instance → "Connect"

A pop-up will appear, so select the best one to connect with your browser (I think other things are fine, but I'm not sure about SSH, so I chose a browser)

image.png

If you see a black screen in your browser, it's ok

5. Environment construction

From here, we will build an environment for executing python programs. @ Kenta1984's article

things to do: --Insert python3 --Insert git

git uses gist when transferring Python files to an EC2 instance, so put it in I don't need anyone to use scp

#Update the included package for the time being
sudo yum update -y
#Insert Python3
sudo yum install python3 -y
#Insert git (optional)
sudo yum install git

By the way, ** If you include Python3, pip3 will also be included ** So you don't have to insuko pip3 separately

Reference: https://git-scm.com/download/linux

6. Create a file → send to EC2 instance

The reality is that you just put the file on gist and clone it to your instance.

: bulb: gist can be cloned and pulled just like git

6-1. Make a gist

https://gist.github.com/

If you paste the code written in VS Code etc., it's ok : warning: Please include the extension in the file name

6-2. Clone gist

At: arrow_down :, select Clone via HTTPS → Copy image.png

On the black screen (browser tab opened in 4) connecting to the EC2 instance, clone gist like always clone git repository

$ git clone <gist URL>

6-3. Program execution

#Move to gist directory
cd my-gists #Directory names vary from person to person, if you don't know, ls
#Program execution
python3 hoge.py #Change the file name to your own

Summary

  1. Create an instance on EC2
  2. Connect to the instance with a browser
  3. Put python3 and git in the instance with sudo yum install
  4. Paste the python program code into gist
  5. Clone gist
  6. Program execution

Recommended Posts

Building an environment to execute python programs on AWS EC2
Building an environment to run ChainerMN on a GPU instance on AWS
[2020 version] How to install Python3 on AWS EC2
Introduction to Python "Re" 1 Building an execution environment
I easily built an operating environment for Python3 + Tornado on AWS EC2.
# 2 Build a Python environment on AWS EC2 instance (ubuntu18.04)
Execute python3 system with PHP exec () on AWS EC2
Posted as an attachment to Slack on AWS Lambda (Python)
Building a Python environment on Mac
Let's get started with Python ~ Building an environment on Windows 10 ~
xgboost (python) on EC2 Spot instance environment prepared by AWS Lambda
# 3 Build a Python (Django) environment on AWS EC2 instance (ubuntu18.04) part2
Create an AWS Cloud9 development environment on your Amazon EC2 instance
Things to note when running Python on EC2 from AWS Lambda
Everything from building a Python environment to running it on Windows
[Python] Building an environment with Anaconda [Mac]
Steps to install Python environment on Ubuntu
Create an OpenCV3 + python3 environment on OSX
Building an environment for "Tello_Video" on Raspbian
Building an environment for "Tello_Video" on Windows
[Definitive Edition] Building an environment for learning "machine learning" using Python on Windows
Build python environment with pyenv on EC2 (ubuntu)
Building an environment that uses Python in Eclipse
Building an environment for executing Python scripts (for mac)
Building an Anaconda environment for Python with pyenv
Python development on Ubuntu on AWS EC2 (using JupyterLab)
Periodically execute Python Script on AWS Data Pipeline
Building an environment for matplotlib + cartopy on Mac
[Node-RED] Execute Python on Anaconda virtual environment from Node-RED [Anaconda] [Python]
Building a Python environment on a Sakura VPS server
Notes from installing Homebrew to building an Anaconda environment for Python with pyenv
How to build an environment for using multiple versions of Python on Mac
Building an environment to comply with the Python coding standard (PEP8) with Eclipse + PyDev
How to run GUI programs such as tkinter in Python environment on WSL2
Deployment procedure on AWS (2) Server (EC2 instance) environment settings
Building an environment for "Tello_Video" on Mac OS X
Building an environment for natural language processing with Python
Procedure for building a CDK environment on Windows (Python)
I want to AWS Lambda with Python on Mac!
[AWS EC2] How to install Maven on Amazon Linux 2
How to build a Python environment on amazon linux 2
Building an environment to use CaboCha with google colaboratory
Build an environment for machine learning using Python on MacOSX
How to build a new python virtual environment on Ubuntu
Build an Ubuntu python development environment on Google Cloud Platform
Building a Python environment on a Mac and using Jupyter lab
Summary from building Python 3.4. * From source to building a scientific computing environment
Build Python environment on Windows
Update python on Mac to 3.7-> 3.8
Building a Python virtual environment
[Introduction to AWS] A memorandum of building a web server on AWS
Build python environment on windows
Python --Install MySQLDB on EC2
[AWS EC2] Settings you want to do on Amazon Linux 2
An introduction to Python Programming
Building a Python virtual environment
[Python] Allow pip3 packages to be imported on AWS Lambda
[Django] Memo to create an environment of Django + MySQL + Vue.js [Python]
Sample script to monitor Load Average on CloudWatch on AWS EC2
Until building a Python development environment using pyenv on Ubuntu 20.04
How to easily create an environment where python code runs on Jupyter without polluting the local environment