Skip to content

Instantly share code, notes, and snippets.

@jolexa
Created January 27, 2017 18:15
Show Gist options
  • Save jolexa/c777da83c71dfdda863e952f64bd31e8 to your computer and use it in GitHub Desktop.
Save jolexa/c777da83c71dfdda863e952f64bd31e8 to your computer and use it in GitHub Desktop.
Using unicreds in AWS Lambda (python)
from subprocess import Popen, PIPE, STDOUT
import os
region = os.environ['region'] # Pass region in as a Lambda env variable
# Of course this assumes that your lambda has IAM permission to the KMS Key and DDB Table
def getSecret(key):
# unicreds is written in go, it is self-contained so, in your zip file include the package. One implementation of that is:
# curl -sL https://github.com/Versent/unicreds/releases/download/1.5.1/unicreds_1.5.1_linux_amd64.tar.gz | tar zx
cmd = "./unicreds -r {0} get -n {1}".format(region, key)
p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT,
close_fds=True)
output = p.stdout.read()
return output
def lambda_handler(event, context):
key = getSecret('credstash_key_name')
# This does nothing useful except printing the secret out
print key
@jolexa
Copy link
Author

jolexa commented Feb 2, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment