node.js - AWS Lambda: How to store secret to external API? -


i'm building monitoring tool based on aws lambda. given set of metrics, lambdas should able send sms using twilio api. able use api, twilio provide account sid , auth token.

how , should store these secrets?

i'm thinking use aws kms there might other better solutions.

here i've come with. i'm using aws kms encrypt secrets file upload code aws lambda. decrypt when need use them.

here steps follow.

first create kms key. can find documentation here: http://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html

then encrypt secret , put result file. can achieved cli with:

aws kms encrypt --key-id some_key_id --plaintext "this scret want encrypt" --query ciphertextblob --output text | base64 -d > ./encrypted-secret 

you need upload file part of lambda. can decrypt , use secret in lambda follow.

var fs = require('fs'); var aws = require('aws-sdk'); var kms = new aws.kms({region:'eu-west-1'});  var secretpath = './encrypted-secret'; var encryptedsecret = fs.readfilesync(secretpath);  var params = {   ciphertextblob: encryptedsecret };  kms.decrypt(params, function(err, data) {   if (err) console.log(err, err.stack);   else {     var decryptedscret = data['plaintext'].tostring();     console.log(decryptedscret);   } }); 

i hope you'll find useful.


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -