cloudsoft.io

Saving and composing with the Library

This tutorial will walk you through creating a fairly simple reusable component, and configure some of the commonly-used items. We will save it to the local library catalog so we can re-use it.

A reusable AutoScaling Group component

We’re going to define an autoscaling group of EC2 instances which will run a simple web server. The server is going to be set up using user data to display a welcome page. In a later tutorial, we’ll reuse this group and add an Elastic Load Balancer to access it.

In Visual Composer, open the “CFN Composer” module. It shows a canvas containing a single item captioned “New Application”. Start by dragging an “AWS AutoScaling Group” from the palette onto the “New Application”. (Tip: if you use the “simplified” filter on the left, this becomes easy to find; alternatively type into the palette’s search box “AutoScalingGroup”).

The left-hand panel will change to show the properties of the newly added AutoScaling Group. (Tip: click on the entity in the canvas to view and edit its properties).

This “AWS AutoScaling Group” has all the properties of that CloudFormation resource (tip: to see all of the properties, change the Configuration section’s filter to ‘All’). If you’re familiar with CloudFormation, you can add a Launch Configuration (from the palette) and refer to it.

However, in this tutorial we will use a simplified way to set the Launch Configuration: we will use the extra configuration option, named “Member spec”, to define that the Auto-Scaling Group will provision EC2 instances when scaling. We will do all of this within the Auto-Scaling Group’s configuration.

Setting an ASG spec

We’re going to configure the “Member spec” to be an EC2 instance. Under the covers, the AWS::AutoScaling::LaunchConfiguration and AWS:EC2:Instance configuration are very similar. Therefore the graphical composer allows you to define the “members” of the group as EC2 instances. When we generate the CloudFormation, it will produce the multiple resources required, including the Launch Configuration.

Initially the member spec field will show “(no spec set)”. Click on that text to open a new palette where you can search for the item to be used as the spec. (Tip: Hovering over the “i” circle on a palette item will show more information on it.) Find and select an “EC2 Instance”.

Editing the EC2 Instance

Configuring an EC2 Instance

The EC2 Instance is now selected in the canvas and you can edit its properties. Set the following values:

  • Image ID: ami-467ca739 (the Amazon Linux AMI) is a good choice in us-east-1, but you can use any AMI you like.
  • Instance Type: t3.micro is suggested for this demo.
  • Security Groups: select an existing security group that allows access from items in the security group to port 8080; it can allow wider access but that is the minimal required. This will secure the instances so later only the load-balancer can access it. You may need to create this security group from the AWS console - ensure you create it in the same VPC as where the VMs will be. (It can be created as part of this CloudFormation template but to keep things simple we are skipping this.)
  • User Data (plain text): this provides a way that a script can be run on the server when it boots. It will be encoded correctly for CloudFormation (i.e. the lines joined, and Base64 encoded). There is also the option to provide Base64 content. This option is not shown by default: to show it, click the filter icon at the top of the configuration properties and select ‘all’. This composer also allows supplying JSON/YAML values as described under Tips. For this demo, enter the following, which creates a very simple web site:

    #!/bin/bash -xe
    mkdir site ; cd site
    echo Hello world. > index.html
    nohup python -m SimpleHTTPServer 8080 &
    

    Edit the message if you wish.

Your EC2 Instance configuration is now complete.

Configuring an AutoScaling Group

Now click on the AutoScaling Group to configure its other settings:

  • Min Size: 2 (increase this so we have more redundancy)
  • Max Size: 4 (a value for this is always required; we’re not expecting much traffic here though!)
  • Desired Capacity: 3 (or leave blank to use “Min Size”)
  • VPC Zone Identifiers (Subnet IDs): choose at least two subnets in the same VPC, ideally corresponding to different availabililty zones, as this is where the ASG will create its instances

ASG Configuration

Saving

Now you’re done configuring this resource, you can save it to the local library catalog. Click the “Save to Library” button at the bottom right of the page. A pop up window appears with the following fields:

  • BundleId: e.g. tutorial-autoscaling-bundle. Adding a blueprint to the library automatically creates a bundle. In this tutorial, the bundle will contain only this one blueprint, but more generally a bundle can include multiple blueprints, icons and scripts. Choose a name that clearly identifies what is in the bundle.
  • Version: e.g 1.0.0. If you change and and again save the blueprint, it will require you to increase the version number. Alternatively, include the suffix “SNAPSHOT”, such as “1.0.0.SNAPSHOT”, to be able to override the existing version.
  • Blueprint symbolic name: e.g. tutorial-autoscaling-group. This identifies the blueprint. In a later tutorial, we will use this name to refer to the blueprint, thus re-using it in a larger blueprint. Again choose a name that identifies what the blueprint does.
  • Blueprint type: Choose Entity.

Once all the fields are filled in click “Save” and your blueprint will be available on the palette and in the catalog.

ASG Save

Saving blueprints makes them available as reusable building blocks when composing new blueprints. This decreases duplication, and also makes blueprint authoring more manageable by splitting it up into bite-sized pieces. These pieces can also be maintained and updated independently. It also allows best practices to be captured in the saved blueprints, so that other blueprints can re-use it with the guarantee that these best practices are being followed every time.

After you save, click to create a new blueprint, and proceed to the next tutorial.