Skip to content

Instantly share code, notes, and snippets.

@pratheekhegde
Created August 10, 2018 05:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pratheekhegde/3bc8ecc02737fc5e2ea09d6bc94dca90 to your computer and use it in GitHub Desktop.
Save pratheekhegde/3bc8ecc02737fc5e2ea09d6bc94dca90 to your computer and use it in GitHub Desktop.
Lamda function for taking manual RDS snapshot.
var AWS = require('aws-sdk');
const rdsConfig = {
apiVersion: '2014-10-31',
accessKeyId: process.env.ACCESS_KEY,
secretAccessKey: process.env.SECRET_KEY,
region: process.env.REGION
}
const rds = new AWS.RDS(rdsConfig);
exports.handler = (event, context, callback) => {
const currentDate = new Date();
const params = {
DBInstanceIdentifier: 'my-db', /* DB instance name */
DBSnapshotIdentifier: `my-db-${currentDate.toDateString().replace(/\s+/g, '-').toLowerCase()}-snapshot-manual-by-lamda`, /* DB Snapshot name */
};
rds.createDBSnapshot(params, function(err, data) {
if (err) {
console.log(err, err.stack); // an error occurred
callback(err)
}
else {
callback(null, data);// successful response
console.log("Snapshot Created ...");
}
});
}
@navdeepkumarhostbooks
Copy link

what runtime need to select for run this

@snacks-lord
Copy link

I can't get this to work. Keeps timing out for some reason.
Also, do I need to add any layers?

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