4 Programming your infrastructure: The command line, SDKs, and CloudFormation

 

This chapter covers

  • Starting a virtual machine with the command-line interface (CLI)
  • Starting a virtual machine with JavaScript SDK for Node.js
  • Understanding the idea of infrastructure as code
  • Using CloudFormation to start a virtual machine

Imagine that we want to provide room lighting as a service. To switch off the lights in a room using software, we need a hardware device like a relay connected to the light circuit. This hardware device must have some kind of interface that lets us send commands via software. With a relay and an interface, we can offer room lighting as a service.

To run a virtual machine, we need a lot of hardware and software—power supply, networking gear, host machine, operating system, virtualization layer, and much more. Luckily, AWS runs the hardware and software for us. Even better, we can control all of that with software. AWS provides an application programming interface (API) that we can use to control every part of AWS with HTTPS requests. In the end, you can write software that spins up VMs on AWS as well as in-memory caches, data warehouses, and much more.

Calling the HTTP API is a low level task and requires a lot of repetitive work, like authentication, data (de)serialization, and so on. That’s why AWS offers tools on top of the HTTP API that are easier to use. Those tools follow:

4.1 Automation and the DevOps movement

4.1.1 Why should you automate?

4.2 Using the command-line interface

4.2.1 Installing the CLI

4.2.2 Configuring the CLI

4.2.3 Using the CLI

4.2.4 Automating with the CLI

4.3 Programming with the SDK

4.3.1 Controlling virtual machines with SDK: nodecc

4.3.2 How nodecc creates a virtual machine

4.3.3 How nodecc lists virtual machines and shows virtual machine details

4.3.4 How nodecc terminates a virtual machine