Skip to content

Instantly share code, notes, and snippets.

@nikolaymatrosov
Last active November 12, 2020 20:12
Show Gist options
  • Save nikolaymatrosov/15375b1b3712eb792b4cdd16336be3b8 to your computer and use it in GitHub Desktop.
Save nikolaymatrosov/15375b1b3712eb792b4cdd16336be3b8 to your computer and use it in GitHub Desktop.
Yandex Cloud Cron Snapshot
import {DiskService, SnapshotService} from "yandex-cloud/api/compute/v1";
const FOLDER_ID = process.env.FOLDER_ID;
export async function handler(event, context) {
const snapshotService = new SnapshotService();
const diskService = new DiskService();
const diskList = await diskService.list({
folderId: FOLDER_ID,
});
const snapshotOperations = [];
for (const disk of diskList.disks) {
if ('snapshot' in disk.labels) {
const op = snapshotService.create({
folderId: FOLDER_ID,
diskId: disk.id
});
snapshotOperations.push(op);
}
}
// await Promise.all(snapshotOperations);
}
{
"name": "functions",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"yandex-cloud": "~1.1.1"
}
}
{
"compilerOptions": {
"module": "commonjs",
"target": "es2018",
"sourceMap": true
},
"exclude": [
"node_modules"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment