node.js - How to use AWS.CloudFront.Signer in Lambda function -
i'm trying use lambda generate , return signed cookie ios app can use cookie access restricted files via cloudfront.
i think should possible using signer class: http://docs.aws.amazon.com/awsjavascriptsdk/latest/aws/cloudfront/signer.html
on basis have written following lambda function:
var aws = require('aws-sdk'); var keypairid = 'apk...'; var privatekey = 'miie...'; var signer = new aws.cloudfront.signer(keypairid, privatekey); exports.handler = function(event, context) { var options = {url: "https://xxxxxx.cloudfront.net", expires: 1357100000}; signer.getsignedcookie(options, function(err, data) { if (err) { context.fail(err); } else { context.succeed('success'); } }); };
however, not work. keep getting error 'process exited before completing request'. have tried many permutations format of 'options' parameter, none of make difference.
any appreciated.
it turns out private key format incorrect. needs include '-----begin rsa private key-----' wording , new line characters, (private key mangled obvious reasons):
var privatekey = '-----begin rsa private key-----' + '\n' + 'miieogibaakcaqeagaqmpqz2qlhlx7pmgubmr32+dlpq7hrxn92z+qlblgqkldpu' + '\n' + 'd/llaymk5tyozxljrelziwgibla8ftcqbvt1feg9xbwjvvbkqbkzzhr7xb47lvud' + '\n' + 't8zatnhhqngxkfv/yy+rav9xn3e6gacxn02cgkbf14pqwfbjdjdcquq1yf8/b9i7' + '\n' + 'joroyyarxyxxyparp1hxsdazkjm5wc0geok7v4ccgyb5chk6carv5wx9yzvyurvq' + '\n' + 'kjxpidxv2ae4mgtkg8uek7gphizjiikrpmvfm/rmirc9nvrchztsvwk0mvwdhruh' + '\n' + 'iatrormpvqa6czyodamjxxxxxxsreg2s4+6xkzh/cylb1ytowkikwnyzeatuyabk' + '\n' + 'bbswvdo8vlokqoouh71ktqkbgf1sr4/btri2wivwwneaorjo6+3pekm4xyibaopo' + '\n' + 'yarsy3koqetuur9wg6dewcexbkbfte1dk/dizes7fppypexqu7virlmoc1gxek+6' + '\n' + 'k1hwclakghqafvvshssuziukbusoo4gktxnrl/epd5gpgt9tspt/d1kqww5sxfrl' + '\n' + 'dm+faogacr0qqhdgea5oec0fqgfzkgsqz3ojdx43kwxxr5jl+4zijtboyqgge+dl' + '\n' + 'qjx1i9fqruhhn02hxxx+etolot4gdv2lf6uhhqphwgv4k3u/7xb35pumn/x2e8vb' + '\n' + 'xrrsk3kxdyaq+i9mpjykizl2eswnikotfjr+3o179/vpsfpiacg=' + '\n' + '-----end rsa private key-----';
with change works fine.
Comments
Post a Comment