问题
In Params for the status variable what i have to write to take the status of snapshot as the input.
Expected Output:
Hello Team, The manual Snapshot of RDS Instance has Started Successfully DB Instance : mysql Region : undefined Latest Snapshot : mysql-test STARTED-TIME : 11/26/2019, 3:03:52 PM status : Creating Thanks & Regards AWS Lambda.
var AWS = require('aws-sdk');
const awsConf = {
region: process.env.REGION
};
const rdsConfig = {
apiVersion: '2014-10-31',
... awsConf
};
const snsConfig = {
apiVersion: '2010-03-31',
... awsConf
};
var rds = new AWS.RDS(rdsConfig);
var sns = new AWS.SNS(snsConfig);
function notifyUser(data, callback){
const params = {
Message: data.message,
Subject: data.subject,
TopicArn: process.env.SNS_TOPIC_ARN
};
sns.publish(params, callback);
}
exports.handler = (event, context, callback) => {
const params = {
DBInstanceIdentifier: 'mysql', /* required */
DBSnapshotIdentifier: 'mysql-test', /* DB Snapshot name */
status: /*what to write here to take the status of snapshot as input*/
};
function calcTime(city, offset) {
var d = new Date();
var utc = d.getTime() + (d.getTimezoneOffset() * 60000);
var nd = new Date(utc + (3600000*offset));
return nd.toLocaleString();
}
rds.createDBSnapshot(params, function(err, data) {
if (err) {
console.log(err, err.stack); // an error occurred
notifyUser({
subject: "[AWS] RDS Manual Snapshot Failed",
message: `
Hello Team,
The manual Snapshot of RDS Instance has been failed for the Following Reason.
DBINSTANCE : ${params.DBInstanceIdentifier}
REGION : ${awsConf.region}
ERROR : ${err.stack}
FAILED-TIME : ${calcTime('MUMBAI', '+5.5')}
Thanks & Regards,
AWS Lambda
`
}, callback) }
else {
notifyUser({
subject: "[AWS] RDS Manual Snapshot Started",
message: `
Hello Team,
The manual Snapshot of RDS Instance has Started Successfully
DB Instance : ${params.DBInstanceIdentifier}
Region : ${awsConf.region}
Latest Snapshot : ${params.DBSnapshotIdentifier}
STARTED-TIME : ${calcTime('MUMBAI', '+5.5')}
Status : ${param.status}
Thanks & Regards
AWS Lambda
`
}, callback) } // successful response
});
};
来源:https://stackoverflow.com/questions/59063715/how-to-take-rds-snapshot-status-as-input-in-aws-lambda-function-written-in-nodej