Ad

Setting Secret Key In Google Cloud Functions

I need to sftp into an amazon ec2 instance to send files from data farmed from a firestore data base. I'm trying to open the connection but I need to have access to the ec2 secret key file in the cloud functions.

I've done slightly similar things such as with stripe and the secret key so I believe this should be possible. How do I upload my secret key file so I can have access to in the function below?

return sftp.connect({
    host: 'xxxxxxxxxxxx',
    port: 'xxxx',
    username: 'xxxxxx',
    privatekey: 'filepath'
    })
Ad

Answer

I simply put the secret key in the main directory and read it into the environment with

var privateKey = require('fs').readFileSync('./xxxxxxx.pem', {'encoding':'utf8'});

I may ask another question later to see if this is secure but I don't see why not.

Ad
source: stackoverflow.com
Ad