import paramiko, base64
import io
import os
key = paramiko.RSAKey.from_private_key(io.StringIO(str(os.environ.get
    ('AWS_PRIVATE_KEY'))))
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(str(os.environ.get('EC2_PUBLIC_DNS')), username='ec2-user',
    pkey=key)
stdin, stdout, stderr = ssh.exec_command('ps')
for line in stdout:
    print('... ' + line.strip('\n'))
ssh.close()
How to store private key on Heroku?