forked from aws-samples/aws-step-functions-ebs-snapshot-mgmt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CountSnapshots.js
52 lines (45 loc) · 1.17 KB
/
CountSnapshots.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
// Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT-0.
*/
var AWS = require('aws-sdk');
var ec2 = new AWS.EC2();
exports.handler = (event, context, callback) => {
console.log(JSON.stringify(event));
//Pull the volume id from the request
var volume_id = event.originalVolumeId;
console.log("volumeId: " + volume_id);
var params = {
Filters: [
{
Name: 'tag:OriginalVolumeId',
Values: [
volume_id
]
},
{
Name: "tag-key",
Values: [
"AutomatedSnapName"
]
}
]
};
var numSnapshots;
console.log("describeSnapshots parameters: " + params);
ec2.describeSnapshots(params, function(err, data) {
if (err)
{
console.log(err, err.stack); // an error occurred
callback('Error in Finding Number of Snapshots');
}
else
{
numSnapshots = data.Snapshots.length;
console.log("Number of snapshots found = " + numSnapshots);
data.numSnapshots = numSnapshots;
//return the list of snapshots and the number of snapshots
callback(null, data);
}
});
};