AWS
Connecting to Linux Instance from Windows Using PuTTY
convert AWS .pem to .ppk for putty/WinSCP
To convert your private key
Start PuTTYgen (for example, from the Start menu, choose All Programs > PuTTY > PuTTYgen).
Under Type of key to generate, choose RSA.

If you're using an older version of PuTTYgen, choose SSH-2 RSA.
Choose Load. By default, PuTTYgen displays only files with the extension
.ppk. To locate your.pemfile, select the option to display files of all types.
Select your
.pemfile for the key pair that you specified when you launched your instance, and then choose Open. Choose OK to dismiss the confirmation dialog box.Choose Save private key to save the key in the format that PuTTY can use. PuTTYgen displays a warning about saving the key without a passphrase. Choose Yes.
Note
A passphrase on a private key is an extra layer of protection, so even if your private key is discovered, it can't be used without the passphrase. The downside to using a passphrase is that it makes automation harder because human intervention is needed to log on to an instance, or copy files to an instance.
Specify the same name for the key that you used for the key pair (for example,
my-key-pair). PuTTY automatically adds the.ppkfile extension.
Your private key is now in the correct format for use with PuTTY. You can now connect to your instance using PuTTY's SSH client.
Check Opened/Closed port
-lor--listeningshows only the sockets currently listening for incoming connection.-aor--allshows all sockets currently in use.-tor--tcpshows the tcp sockets.-uor--udpshows the udp sockets.-nor--numericshows the hosts and ports as numbers, instead of resolving in DNS and looking in /etc/services.
netstat -atn # For tcp
netstat -aun # For udp
netstat -atun # For bothCheck which specific processes (Python scripts) are running
pgrep -lf pythonThis, however, does not list the whole command line. If you have a recent version of pgrep you can use -a to do this:
pgrep -af pythonKill running processes
e.g. Kill all running python processes
pkill -9 pythonPython Installation
In order to use "sudo pip XXX"
sudo apt-get update
sudo apt-get install python-pipsudo pip install XXXRunning a Flask app on AWS EC2
https://www.datasciencebytes.com/bytes/2015/02/24/running-a-flask-app-on-aws-ec2/
Running a Flask app with Linux startup
Create service configuration
sudo nano /etc/init/flask.confdescription "flask"
start on stopped rc RUNLEVEL=[2345]
respawn
exec python /home/user/server.pyCreate flask.service
sudo nano /lib/systemd/system/flask.service[Unit]
Description=Flask web server
[Install]
WantedBy=multi-user.target
[Service]
User=root
Group=root
PermissionsStartOnly=true
ExecStart=/usr/bin/python3 /home/ubuntu/NLPv3/main.py
TimeoutSec=600
Restart=on-failure
Run flask.service
sudo systemctl start flask
sudo systemctl stop flask
sudo systemctl status flaskREF:
sudo systemctl start flask.
REF:
Running Python in AWS Lambda
https://stackoverflow.com/questions/53686252/api-gateway-lambda-proxy-python-internal-server-error
Example Code
AWS serverless app example in github
https://github.com/aws-samples/serverless-app-examples/tree/master/python
https://github.com/crazyfan5566/aws_lambda_for_python_example/tree/master/example
access dynamo database
building fb messenger chatbot
MySQL
https://www.isc.upenn.edu/accessing-mysql-databases-aws-python-lambda-function
Last updated