Created
February 12, 2016 18:00
-
-
Save ijin/26afca1e9b03ecaf4d8e to your computer and use it in GitHub Desktop.
ssh from lambda using keys fetched from KMS-SSE backed s3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
from botocore.client import Config | |
import boto3 | |
import paramiko | |
print('Loading function') | |
s3 = boto3.client('s3', config=Config(signature_version='s3v4')) | |
def lambda_handler(event, context): | |
s3.download_file('cs-test-data', 'id_rsa', '/tmp/id_rsa') | |
client = paramiko.SSHClient() | |
client.load_system_host_keys() | |
client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | |
host='ec2-52-192-221-60.ap-northeast-1.compute.amazonaws.com' | |
client.connect(host, username='ec2-user', key_filename='/tmp/id_rsa') | |
stdin, stdout, stderr = client.exec_command('uptime') | |
error = stderr.read() | |
output = stdout.read() | |
print("err:" + error) | |
print("out:" + output) | |
return output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment