Skip to content

Instantly share code, notes, and snippets.

@JensWalter
Last active July 18, 2022 07:17
Show Gist options
  • Save JensWalter/8eab250f28360f696caa8e8c616f0dd8 to your computer and use it in GitHub Desktop.
Save JensWalter/8eab250f28360f696caa8e8c616f0dd8 to your computer and use it in GitHub Desktop.
generate a self signed certificate with AWS Lambda
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);
});
}
@ozbillwang
Copy link

    "/bin/sh: openssl: command not found",

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