Ludwig Tutorial 5: EC2 Instance, Security Group

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.


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

my-igw: {
  vpc: my-vpc

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

With this function, an EC2 instance is added.

my-instance: {

As with regions in AWS, instance types are enumerated in the EC2 module.

instanceType: EC2.T2_micro,
subnet: subnet1,
image: "ami-7172b611",

Note that the value here, a list of SecurityGroup values, refers to a value that comes later in the source code (public-ec2-sg). In Ludwig, all values and references are read before any dereferencing or evaluation, so the order of bindings does not matter.

    securityGroups: [public-ec2-sg]

With this function, a Security Group is added.

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

A little more complex function. The http function creates a rule for TCP port 80, and EC2.IpPermission.Target.all is a convenience value in the standard library for the CIDR block

    vpc: my-vpc

Running and Compiling the Composition

You can run this composition with the following command:

fugue run Tutorial5.lw

This will create the following infrastructure in your AWS account:

  • VPC
  • Subnet
  • 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] Tutorial5.lw

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

lwc Tutorial5.lw