Last active
May 24, 2018 13:28
-
-
Save fhinkel/422392439229630690975a62e9f1e534 to your computer and use it in GitHub Desktop.
Create minimal Compute Engine instance with Node.js
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
// Run `npm install @google-cloud/compute` first. | |
const Compute = require('@google-cloud/compute'); | |
const compute = new Compute(); | |
// Creates a new VM using the latest Ubuntu image. | |
(async () => { | |
try { | |
const zone = await compute.zone('us-central1-a'); | |
const data = await zone.createVM( | |
'ubuntu-instance', | |
{ os: 'ubuntu' } | |
); | |
const operation = data[1]; | |
await operation.promise(); | |
// Virtual machine created. | |
} catch (error) { | |
console.error(error); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See Manage Google Compute Engine with Node.js on Medium.