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
lambda-local -l app.js -e event.json -E {\"MONGODB_ATLAS_CLUSTER_URI\":\"mongodb://lambdauser:[email protected]:27017\,lambdademo-shard-00-01-7xh42.mongodb.net:27017\,lambdademo-shard-00-02-7xh42.mongodb.net:27017/$DATABASE?ssl=true\&replicaSet=lambdademo-shard-0\&authSource=admin\"} |
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 kms = new AWS.KMS(); | |
kms.decrypt({ CiphertextBlob: new Buffer(uri, 'base64') }, (err, data) => { | |
if (err) { | |
console.log('Decrypt error:', err); | |
return callback(err); | |
} | |
atlas_connection_uri = data.Plaintext.toString('ascii'); | |
processEvent(event, context, callback); | |
}); |
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
function processEvent(event, context, callback) { | |
console.log('Calling MongoDB Atlas from AWS Lambda with event: ' + JSON.stringify(event)); | |
var jsonContents = JSON.parse(JSON.stringify(event)); | |
//date conversion for grades array | |
if(jsonContents.grades != null) { | |
for(var i = 0, len=jsonContents.grades.length; i < len; i++) { | |
//use the following line if you want to preserve the original dates | |
//jsonContents.grades[i].date = new Date(jsonContents.grades[i].date); | |
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
'use strict' | |
var MongoClient = require('mongodb').MongoClient; | |
let atlas_connection_uri; | |
let cachedDb = null; | |
exports.handler = (event, context, callback) => { | |
var uri = process.env['MONGODB_ATLAS_CLUSTER_URI']; | |
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
'use strict' | |
const AWS = require('aws-sdk'); | |
var MongoClient = require('mongodb').MongoClient; | |
let atlas_connection_uri; | |
exports.handler = (event, context, callback) => { | |
var uri = process.env['MONGODB_ATLAS_CLUSTER_URI']; | |
if (atlas_connection_uri != null) { |