Start creating infrastructure on AWS like a PRO

Start creating infrastructure on AWS like a PRO

Defining and setting up a cloud infrastructure is usually a challenging and time-consuming task, especially when you have to work out all the infrastructural elements, where to store them so they are easy to use, organize build and deployment processes and so on.

Microtica abstracts the complex cloud setup and automation on AWS, using best practices. This means that you define the infrastructure you need without having to worry about the details of how this infrastructure will be deployed into the cloud.

Microtica is structured into projects, components, and stages. Creating a component is the first step toward creating an infrastructure to run on the cloud.

Components provide the ability to define a custom Cloud infrastructure setup (clusters, DBs, networks, etc.) that fits your own needs. Components are isolated by their nature which allows them to be independent, reusable and easy to test. It’s kinda like a microservice for infrastructure.

To kick start infrastructure setup on AWS, Microtica offers ready-to-use components (VPC, MySQL, EKS, DynamoDB, Redis, S3) which can be found directly in the portal and available on GitHub. You can also create your own custom components to cover a part of the cloud infrastructure that you might need for a project. In this article, we will cover how to create a custom component from scratch.

In the current version of Microtica, we support AWS CloudFormation as a way to write cloud infrastructure setup in a declarative way (infrastructure-as-a-code). In the future, we plan to add support for Terraform as well.

Get started

The first thing you need to do is add your Git account in Microtica. You can do this is Settings — Git Accounts tab. We support GitHub and BitBucket as git sources. When you’ve connected your Git account, you should create a repository that will hold your component’s code. We will be using the repository URL in the next steps of the creation process.

In the AWS accounts menu you should connect your AWS account, since will be using that to store your build artifacts and deploy your infrastructure.

Connected GitHub account

Create a component

To make writing custom components easier for developers, we provide a (component generator)[npmjs.com/package/@microtica/generator-micr.. — a scaffolding module which can be found on NPM. In order to use the generator follow the instructions:

1. Install Yeoman as a global module

sudo npm install -g yo

2. Install Microtica component generator

sudo npm install -g @microtica/generator-microtica-component

3. Scaffold new component

Go to the root folder where you want to place the component. A component folder will be automatically created. There execute:

yo @microtica/microtica-component

This command will ask you a couple of questions, including your Git repository URL. Paste the repository URL that you’ve created previously.

After the setup is complete, you need to push the code that was just created onto the repository to be able to then use it in Microtica portal. Just navigate to the component folder and execute:

git push origin master

The git repository should now be populated with the files generated with microtica-component-generator. The component should contain these definition files in the source code root folder:

  1. microtica.yamlfor build pipeline definition (required)
  2. schema.jsonfor validation (input/output parameters). What a component expects as a configuration and what it returns as an output that can be referenced by other components (required)
  3. index.js — component handler. Handles create/update of the component (required)
  4. index.json — cloud infrastructure definition (AWS CloudFormation template) (required)
    {
     "AWSTemplateFormatVersion": "2010-09-09",
     "Description": "test",
     "Parameters": {
         "stageId": {
             "Type": "String",
             "Description": "Unique ID of Microtica stage"
         },
         "resourceId": {
             "Type": "String",
             "Description": "Unique ID of Microtica resource"
         }
     },
     "Resources": {
         "S3Bucket": {
             "Type": "AWS::S3::Bucket",
             "Properties": {
             }
         }
     },
     "Outputs": {
         "bucketName": {
             "Value": {"Ref": "S3Bucket"},
             "Description": "Name of the S3 bucket"
         }
     }
    }
    
    This example of a cloud formation template is creating an S3 bucket, but you can define anything that cloud formation supports.

cloudformation template

With this, you have the setup of a simple component 👏 . You can follow our example on how to create an API Gateway component if you like the challenge.

Deploy the infrastructure

Navigate to your project in Microtica, under Components — Create Component and import the component you’ve just created. Choose the Git account and repository where we pushed the code, and then select the AWS account where your build artifacts will be stored. You can enable automated build trigger, which means a build will be triggered on every push onto the selected branch filter. You can also choose to build your component manually.

Create My Simple Component

For the purposes of this article, we will build our component-simple manually in the portal. For each build, we can follow the logs and see what is happening in real-time with our build. If our build fails, we will see that marked with red on our screen and the error will be shown in the logs.

build details and logs

With our successful build we have a workable version of our component, which means we now have a workable infrastructure. The next step would be to deploy it in the cloud.

For this, we need to create a stage, which is actually an environment in which you’ll deploy your infrastructure. Create a stage following the wizard on Microtica and then continue Add components. This will lead you to a screen which we call Stage Details.

On the right side, you will see the component we’ve just created. Selecting the component will open configurations modal, with all the input parameters that the component needs populated in order to function in the cloud. These input parameters are defined in the schema.json file mentioned earlier.

Our component-simple doesn’t require inputs at the moment, so just enter a name for the resource, e.g. Simple. You can also choose which version of the component you’d like to deploy.

stage details

After you create the resource, you can deploy your stage by clicking Create Plan. Here you will see a detailed listing of the resources that are about to be added to the environment. Confirming will initiate the deployment and lead you to a page where you can follow the logs and events that are happening.

stage deployment status and logs

And now you have a deployed infrastructure running on the cloud! Bravo!

Bonus: Cleanup

To remove all the resources we created on your AWS account go to stage details and in the menu select Undeploy. This will cleanup the resources created on AWS, but you will still have the configuration in Microtica in case you want to Deploy it in the cloud again.

stage details

As you were able to see — Microtica lets you focus completely on the code you write in Cloud Formation, while abstracting the integration with AWS and automating the build and deployment process.