References to Resources Made Easy

This tutorial will cover:

  • Cross-references between entities (i.e. between CloudFormation resources)
  • Simplified entities, which are each designed to make a common usage pattern simpler
  • Using items from the local library

This will be done using Route 53 DNS, an Elastic Load Balancer (ELB), and the AutoScaling Group created in the previous tutorial. The end result will be a CloudFormation template for an auto-scaling load-balanced cluster of EC2 instances, each running a simple web-server.

Referring to a Load Balancer from Route 53 DNS

Start by adding Route 53 DNS (AWS::Route53::RecordSet) from the palette (either drag it onto “New application” in the canvas or click on it and select “Add to application”). Then repeat the process with an Elastic Load Balancer, AWS-ElasticLoadBalancing-LoadBalancer-SingleTarget. (ensuring it is added to the application, not to the Route53 RecordSet if it is selected).

Blueprint with entities added

The Route 53 RecordSet can be configured with ResourceRecords or an AliasTarget. This can be configured with JSON objects such as { !Ref: ... }.

An easier way in Visual Composer is to configure the Route 53 RecordSet to refer to the Elastic Load Balancer, and have the composer generate automatically the desired AliasTarget value in CloudFormation. This will reference the ELB’s CanonicalHostedZoneID and DNSName.

To do this, click the Route 53 entity to select it and then click “Target (entity)” in the configuration section. Click the lightning-bolt icon to choose the target reference.

Configuring lightning-bolt

This opens a wizard for choosing the target value. Use the search box to filter the targets, and click on the desired one (in this case the Load Balancer). Then Click ‘Done’.

Configuring using the DSL editor

The only other thing you need to do for the Route 53 Record Set is to supply a hostname. In the generated CloudFormation, this requires the properties HostedZoneName and Name. We will use a Visual Composer convenience of setting the Hostname, from which it can infer these two values. For example, given the Hostname “”, it will generate the Name “tutorial” and the HostedZoneName “”. The hosted zone is the DNS domain that your AWS account is configured to manage, and the Record Set tells DNS how you want traffic to be routed for that domain.

Alternatively, if you don’t have a hosted zone in your account, simply delete the Route 53 Record Set item and proceed with the tutorial - the Elastic Load Balancer can be reached directly via its address, rather than via the Route 53 address. (Tip: to delete, click on the item in the canvas, then in the right panel use the dropdown in its top-right corner and choose ‘Delete’)

Configuring Route 53

Adding the AutoScaling Group

We will use the AutoScaling Group created in the previous tutorial, where we added a blueprint to the local library.

References library palette section

At the left of the palette are three buttons. Click the second one to show the library and locate the Auto Scaling Group you created in the previous tutorial. Drag it onto the canvas in the same way as you added the other components.

These blueprints are composable: by adding the item from the library, the generated CloudFormation will include all of the resources and configuration defined in that item.

Configuring the Elastic Load Balancer

The Elastic Load Balancer ‘single target’ is designed to simplify the common usage pattern of creating an ELB with a single Listener and a single Target Group. With this one item from the palette, it will create all these CloudFormation resources.

(Alternatively, you can use the standard AWS::ElasticLoadBalancingV2::LoadBalancer and create the AWS::ElasticLoadBalancingV2::Listener and AWS::ElasticLoadBalancingV2::TargetGroup yourself. However, the rest of this tutorial assumes you are using the ‘single target’ approach.)

We want the Elastic Load Balancer to load-balance across the members of our AutoScaling Group. Within CloudFormation, the way to do this is to configure the AutoScaling Group to refer to the Target Group, so that it updates the target group each time its members change.

However, in Visual Composer there is a convenience of configuring the ELB to point at what you want it to load balance. Select the ELB in the canvas, click ‘Target’ in the configuration section and click the lighting bolt to open the wizard (as you did for the Route 53 Record Set). Select your Auto Scaling Group from the list and click ‘Done’. The target should now show the name of your Auto Scaling Group.

We also need to set a few more fields:

  • VPC ID: This field offers a dropdown so you can select which one you wish to use. Choose the VPC corresponding to the one the AutoScaling Group is in.

Configure VPC Dropdown

  • Subnet IDs: For a public-facing ELB, chose public subnets. These should be in the same availability zones and same VPC as the subnets used by the AutoScaling Group.

  • Security groups. For brevity, this tutorial assumes security groups have already been created within your VPC. Enter the ids of the two security groups needed:

    • The first should allow ingress access to port 8080 of the EC2 instances - use the same security group as was set for the EC2 instances in the previous tutorial.
    • The second should allow public access to port 80, for your target audience (e.g. to the world).

Creating a CloudFormation Stack

Now download CloudFormation: click “Generate CloudFormation” and save the downloaded CloudFormation template YAML to your local disk

You can then deploy this to create a stack using the AWS console, or using the AWS CLI. For example, use the command below:

aws cloudformation create-stack --stack-name tutorial-hello-three-tier \
    --region us-east-1 --template-body file://<path-to-downloaded-yaml>


You now have a good understanding of how to compose CloudFormation templates with this tool.

Best of luck designing your own CloudFormation templates. Please let us know if there are features you’d like to see or things that aren’t clear.