---
title: Using Cfhighlander to create reusable AWS CloudFormation templates
description: Learn how to create reusable CloudFormation templates for managing AWS resources in a modular way. This developer workshop covers creating a VPC, deploying bastion and ECS components, and more. | How-to tech post | Code sample
---

[Secure SaaS Delivery, Cloud & DevOps | base2Services](https://blog.base2services.com)

# [Using Cfhighlander to create reusable AWS CloudFormation templates](https://blog.base2services.com/using-cfhighlander-to-create-reusable-and-modular-aws-cloudformation-templates)

 Written by [Angus Vine](https://blog.base2services.com/author/angus-vine) | Jul 20, 2022, 8:43:00 AM

I recently co-hosted a developer workshop at the Melbourne AWS Programming & Tools Meetup that I wanted to share with anybody who wants to learn how to create reusable CloudFormation templates for managing AWS resources in a modular way.

The workshop focussed on how to create a VPC with both private and public subnets, and how to deploy bastion and ECS components into these subnets, using Cfhighlander, a feature rich tool & DSL for infrastructure coders that came out of the base2Services R&D lab. Additionally, the workshop covered how to deploy a single nginx service into an ECS cluster using CloudFormation.

More advanced users can also try and deploy a custom-built image to ECR, and then configure ECS service component to use it.

Try it for yourself. You can follow the workshop by visiting the GitHub link below, and completing the steps outlined on this page.

Workshop: [github.com/theonestack/cfhighlander-workshops/tree/master/ecs-nginx](https://github.com/theonestack/cfhighlander-workshops/tree/master/ecs-nginx)

### Preperation

For successfull completion of all of the steps you will need the Docker image theonestack/workshop-tools:light. If you wish to go the extra step (advanced) section below, you will need the theonestack/workshop-tools:full Dockerfile.

To pull the docker image, execute below from your shell

```
docker pull theonestack/workshop-tools:light
```

To start the docker container from the image with interactive prompt, execute below from your shell. It will mount your AWS credentials to the container

```
docker run -it -e AWS_REGION=ap-southeast-2 -e AWS_DEFAULT_REGION=ap-southeast-2 -w /src -v $PWD:/src -v $HOME/.aws:/root/.aws theonestack/workshop-tools:light bash
```

You will also need the latest cfhighlander gem. Install it using gem command:

```
gem install cfhighlandercfhighlander helpcfhighlander cfcompile
```

 

### Step 2

- Create local key and upload to AWS
- Add bastion component
- Configure bastion component with custom keypair
- Deploy, update stack, and login to bastion via SSH

 

### Step 3

- Add ECS component
- Add Loadbalanacer component
- Deploy, update stack, visit the web url

 

### Step 4

- Add Nginx as service on ECS component
- Deploy, update stack, visit the web url

 

### Extra Step

- Build custom docker image & push to ECR
- Configure ECS Service component to use custom docker images

 

### Available resources

- [Cfhighlander](https://github.com/theonestack/cfhighlander)
- [Cfhighlander Workshops](https://github.com/theonestack/cfhighlander-workshops)
- [ECS + nginx Workshop](https://github.com/theonestack/cfhighlander-workshops/tree/master/ecs-nginx)

[View full post](https://blog.base2services.com/using-cfhighlander-to-create-reusable-and-modular-aws-cloudformation-templates)

```json
{
  "@context" : "http://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Angus Vine"
  },
  "dateModified" : "2023-09-06T13:19:53.325Z",
  "datePublished" : "2022-07-20T08:43:00Z",
  "headline" : "Using Cfhighlander to create reusable and modular AWS CloudFormation templates",
  "image" : {
    "@type" : "ImageObject",
    "height" : 400,
    "url" : "https://5667837.fs1.hubspotusercontent-na1.net/hubfs/5667837/cfhighlander.jpg",
    "width" : 600
  },
  "mainEntityOfPage" : "https://blog.base2services.com/using-cfhighlander-to-create-reusable-and-modular-aws-cloudformation-templates",
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "height" : 60,
      "url" : "/hs/hsstatic/content_shared_assets/static-1.4092/img/default-amp-logo.png",
      "width" : 60
    },
    "name" : "Secure SaaS Delivery, Cloud & DevOps | base2Services"
  }
}
```