-
-
Save supunsandeeptha/089297f505f687b65c73d9ffaf659d3a to your computer and use it in GitHub Desktop.
generate a self signed certificate with AWS Lambda
This file contains 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
const exec = require('child_process').exec; | |
const fs = require("fs"); | |
exports.handler = function(event, context) { | |
console.log("creating certificate"); | |
exec('openssl req -x509 -newkey rsa:4096 -keyout /tmp/key.pem -out /tmp/cert.pem -subj "/C=DE/ST=Bavaria/L=Munich/O=apimeister org/OU=org unit/CN=apimeister.com" -days 45 -nodes', (error, stdout, stderr) => { | |
if (error) { | |
throw error; | |
} | |
console.log("reading certificate"); | |
var output = {}; | |
//read cert file | |
var cbytes = fs.readFileSync("/tmp/cert.pem"); | |
var cb64 = new Buffer(cbytes).toString('base64'); | |
output.cert={filename:"cert.pem",fileContent:cb64}; | |
//read key file | |
var kbytes = fs.readFileSync("/tmp/key.pem"); | |
var kb64 = new Buffer(kbytes).toString('base64'); | |
output.key={filename:"key.pem",fileContent:kb64}; | |
context.succeed(output); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment