Ludwig Tutorial 1: VPC

This tutorial is actually a Ludwig composition. You can download it here and fugue run it like you would any other composition. You can use lwc, the Ludwig compiler, to compile the composition.

If you’re interested in text editor plug-ins, you can find them here. Click here to return to the Tutorial table of contents.

Ready?

Let’s Go!

Before we begin, we’ll place the entire composition for this example in one code block so you can easily see it in context.

1
2
3
4
5
6
7
composition
import Fugue.AWS as AWS
import Fugue.AWS.EC2 as EC2
my-vpc: EC2.Vpc.new {
  cidrBlock: "10.0.0.0/16",
  region: AWS.Us-west-2
}

Now, let’s examine it line by line.

First things first. This is a composition. Such Ludwig files are denoted by the composition keyword. Only a composition can be run by the fugue run command.

composition

Next, here are a couple imports. This composition is written for AWS specifically, so the AWS module is imported.

import Fugue.AWS as AWS

The composition’s first bits will include the VPC service, which is a subservice of EC2, so the EC2 module is imported.

import Fugue.AWS.EC2 as EC2

Next, there’s a VPC declaration. In this case, the declaration will be broken down word for word.

First, there is a binding. Bindings follow the form of name: value. A binding is basically like a variable, but it can’t be changed – just assigned once and then done.

Bindings must begin with a lowercase letter. Values can be lots of things; one of Ludwig’s many data types, or a function that returns one of those types. In this case, the value is the return of the function EC2.Vpc.new.

This function (as with most in Ludwig) is called using named parameter syntax. Named parameter syntax looks exactly like a record in Ludwig. It’s basically like a dictionary or hashmap in other languages you’ve used.

The up-shot is that you write a record with a name in front of it that tells you what kind of thing it is.

my-vpc: EC2.Vpc.new {

This is the cidrBlock parameter of the Vpc.new constructor.

cidrBlock: "10.0.0.0/16",

This is the region parameter, also of the Vpc.new constructor. Note that this is not a string, but a member imported from the AWS module. You will see more like this later.

region: AWS.Us-west-2

This closing bracket ends the scope of the function call.

}

That’s most of what you need to know to use Ludwig. Try editing this composition and introducing some errors to see how the compiler responds to your changes.

Running and Compiling the Composition

You can run this composition with the following command:

fugue run Tutorial1.lw

This will create a VPC in your AWS account.

To just check compilation, invoke lwc, the Ludwig compiler:

lwc Tutorial1.lw