Reading Time: 4 minutes

When working with AWS infrastructure, it can be difficult to keep track of the provisioning of resources and potentially lead to security risks and unaccounted costs. With MuleSoft, it is easy to automate the deployment of AWS Resources using the CloudFormation APIs. AWS CloudFormation is a service that helps you model and set up your AWS resources. The resources are defined by the AWS CloudFormation template. Here is a short four step guide to automating the deployment of EC2 using MuleSoft and AWS Cloud formation APIs: 

Step 1: Parametrize CloudFormation template

When you use AWS CloudFormation, you manage resources as a single unit called a Stack. Parameterize the CloudFormation template to include the values you would like to customize in your resource Stack. These values can be passed as inputs from MuleSoft while calling the APIs. 

latest report
Learn why we are the Leaders in API management and iPaaS

For example: Instance Type, SSH Key, VPC CIDR block. 

Step 2: Generate AWS Signature Version 4 

To communicate with AWS APIs it is necessary to authenticate the incoming requests with AWS. The signature request consists of an access key ID and a secret access key with an AWS Signature V4. MuleSoft has developed a custom connector to easily compute the signature value for making AWS requests, making this process much simpler.

The required parameters to create a signature are visible in the screenshot of the custom connector below:

See documentation on how to generate the signature. 

This AWS Signature Connector can be reused to call any AWS API.

Step 3: Create Stack 

Create an orchestration in MuleSoft to create Stack. This API call below can be configured in the Request Listener and parameterized to input custom values:

GET / ?Action=CreateStack& StackName=MyStack& TemplateURL=https://s3-external-1.amazonaws.com/cf-templates-vc5likubc2zh-us-east-1/2020014OXA-ec2.jsoni78mxxd8l2l& Parameters.SSHKeyName.ParameterKey=SSHKeyName& Parameters.SSHKeyName.ParameterValue=tokenization 

Step 4: Delete Stack 

Create a Delete Stack API Flow and schedule the cleanup of stacks on a weekly/monthly cadence based on user specification.

DELETE /?Action=DeleteStack& StackName=ec2

Conclusion 

This simple project demonstrates how MuleSoft can easily connect to AWS and orchestrate deployment of infrastructure. These orchestrations can be further expanded to support a multi-cloud environment

For more developer resources, check out our developer tutorials.