Search
Close this search box.
GitKon

Continuous Integration Workflow

Building Automated Continuous Integration Workflows for Your Cloud & Serverless Applications

With the rise of cloud & serverless application development, engineers have been running into the tedious problem of local development. Today’s cloud development is slow, tedious, and costly, and there’s a lack of options to emulate cloud services that are mostly bound to a proprietary cloud provider. 

These challenges limit the options available to engineers, forcing them to rely upon mock testing tools to emulate a local cloud infrastructure that can run locally and on continuous integration (CI) pipelines.

LocalStack is a cloud service emulator that can run in a single container on your local machine or your CI environment and lets you run your cloud and serverless applications without connecting to an Amazon Web Services account.

With LocalStack, all cloud resources your application depends on are available locally. It allows you to run automated application tests in an AWS environment without needing costly AWS developer accounts, slow re-deployments, or transient errors from remote connections.

showing a continuous integration workflow in LocalStack

Getting Started with Continuous Integration Workflows with LocalStack

You can get started with LocalStack by installing the official command line interface via pip.  You can address the CLI directly to create your LocalStack instance, containing all the AWS services inside a single Docker container.

Once installed, you can interact with these local AWS services via the official AWS CLI or use a third-party integration like Terraform, CDK, and much more.

getting started with the LocalStack CLI

LocalStack & Terraform Integration

Let’s look at the Terraform integration with LocalStack. There is a  sample Terraform script that takes a NodeJS-based Lambda and deploys it as an AWS Lambda Function URL.

These function URLs can then be triggered as REST APIs using standard HTTP requests. Terraform is an Infrastructure as Code framework that creates a plan which is then applied to create resources. We can use the same Terraform configuration to deploy over AWS in production and on LocalStack locally, or in CI.

To use LocalStack with Terraform’s AWS provider, you can use a provider.tf file with the local AWS endpoints defined or LocalStack’s tflocal script. 

Here is what it looks like to apply the Terraform configuration to create a Lambda function locally:

Terraform and LocalStack integration

As you can see in the example above, Terraform created the entire infrastructure locally using LocalStack with just a single running Docker container. Now, let’s review how we can run this over a continuous integration provider.

Running LocalStack with GitHub Actions

LocalStack is supported across all significant continuous integration providers to deploy and test your AWS apps. Engineers use LocalStack with CI providers to ensure they’re testing on a mock environment rather than calling actual AWS APIs. The latter is costly and should ideally be used only in production.

To get started with a CI provider like GitHub Actions, you must pull the LocalStack image and download the LocalStack CLI to get started. Here is a sample workflow you can use inside your .github/workflows directory to begin testing your AWS cloud and serverless apps without using any real APIs to emulate your stack.

GitHub Actions and LocalStack integration

GitKraken’s legendary Git tools will help you level-up your continuous integration workflow. Try GitKraken tools free today: GitKraken Client for the desktop; GitLens for VS Code; and Git Integration for Jira

Make Git Easier, Safer & more Powerful

With the #1 Git GUI + Git Enhanced CLI

Visual Studio Code is required to install GitLens.

Don’t have Visual Studio Code? Get it now.