Ludwig Tutorial 6: Another Subnet

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.


Let’s Go!

We’ll begin with the work from the last tutorial.


import Fugue.AWS as AWS
import Fugue.AWS.EC2 as EC2

my-vpc: {
  cidrBlock: "",
  region: AWS.Us-west-2

subnet1: {
  cidrBlock: '',
  vpc: my-vpc,
  availabilityZone: AWS.A,
  mapPublicIpOnLaunch: True

Here, a second subnet is added. Note that the availability zone differs from the first subnet, so we can distribute our services across AZs. After the subnet, everything is the same as we had in the previous tutorial.

subnet2: {
  cidrBlock: '',
  vpc: my-vpc,
  availabilityZone: AWS.B,
  mapPublicIpOnLaunch: True

my-igw: {
  vpc: my-vpc

route-table: {
    vpc: my-vpc,
    routes: [ {
            destinationCidrBlock: "",
            target: EC2.GatewayTarget(my-igw)
    associations: [subnet1]

my-instance: {
    instanceType: EC2.T2_micro,
    subnet: subnet1,
    image: "ami-7172b611",
    securityGroups: [public-ec2-sg]

public-ec2-sg: {
    description: "Allow traffic from the internet",
    ipPermissions: [
    vpc: my-vpc

Running and Compiling the Composition

You can run this composition with the following command:

fugue run Tutorial6.lw

This will create the following infrastructure in your AWS account:

  • VPC
  • 2 subnets
  • Internet gateway
  • Route table
  • EC2 instance
  • Security group

Optionally, if you have a process running from previous tutorials, you can simply update the process like this:

fugue update [ALIAS or FID] Tutorial6.lw

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

lwc Tutorial6.lw