LocalStack and MuleSoft

I recently discovered LocalStack, a fully functional AWS services emulation for local development and testing. First I was a bit skeptical if this really works like AWS services, but as the installation went super easy, it convinced me by its awesome developer experience.

This article is for MuleSoft developers, who develop APIs and Integration for AWS services using the MuleSoft Anypoint Platform. LocalStack is easy-to-use local testing and mocking deployment for all AWS services without the need to connect to the AWS cloud. It comes with 3 types of flavor.

  • Free edition – the open source edition, which comes up with fully function base services such as Simple Queue Service (SQS), AWS S3, Elasticsearch, etc.
  • Pro edition – for professionals with alot more extended services (EKS, ECS, Glue, IoT, etc.) and support
  • Enterprise edition – for companies with all Pro features, CI Integration and dedicated support

See the full feature coverage here.

LocalStack for MuleSoft Anypoint Studio

The LocalStack configuration in this article are referring to MacOS.

In order to use LocalStack for MuleSoft Anypoint Studio and its AWS connectors, you need to set it up on the working machine/laptop. Use the following link to install LocalStack on your machine. You will find all pre-requisites for installing LocalStack on the Getting started section.

Once LocalStack is installed on your machine, you can start with the configuration of the AWS CLI. If you don’t have the AWS CLI installed on your machine, install it first, before using LocalStack.

If you are a Pro / Enterprise user of LocalStack, make sure to enter the API Key into the environment variable LOCALSTACK_API_KEY or execute the following command in your terminal:

export LOCALSTACK_API_KEY=<your-api-key>

Start LocalStack on your machine

Open the Terminal.app to start LocalStack via CLI by executing the following command:

localstack start

LocalStack will be started with the default configuration on port 4566.

LocalStack CLI started.

LocalStack AWS CLI configuration

Once LocalStack is running, you need to configure the AWS CLI by executing the following command:

aws configure

Enter an AWS Access Key Id and AWS Secret Access Key for LocalStack. This could be everything, e.g. mule in both cases. Additionally, define the default region and output format.

aws cli configuration

To work with LocalStack as a mocking service for AWS CLI, you always need to define the endpoint-url when executing any command from the command line. For example:

aws --endpoint-url http://localhost:4566 s3 ls

The –endpoint-url flag must be present in all commands. Alternatively, you can set an alias for aws on MacOS.

alias aws="aws --endpoint-url http://localhost:4566"

This will ensure that all aws commands from the command line include the flag –endpoint-url for LocalStack

MuleSoft Anypoint Studio Configuration

In order to work with Anypoint Studio, it is important to always set a custom service endpoint in the AWS connector configuration. In the following, 2 example configurations for Simple Queue Service (SQS) and AWS S3 Connectors on Anypoint Studio.

Amazon Simple Queue Service (SQS)

When creating a configuration for AWS SQS in Anypoint Studio, refer to the configuration set previously in this article. In the SQS configuration, provide the previously configured Access Key and Secret Access Key for the AWS CLI.

Access Key and Secret Access Key Id for SQS connector

Once the Access & Secret Key is provided, click on the Advanced Tab and enter the Custom SQS Endpoint.

Custom SQS Endpoint

The Custom SQS Endpoint should be referring to the LocalStack local SQS endpoint, which is on http://localhost:4566.

Amazon S3

Similar to the SQS connector, provide the Access & Secret Key must be provided as defined for the AWS CLI.

Access Key and Secret Key

Once the Access & Secret Key is provided, set the Custom Service Endpoint for LocalStack service for S3 running on http://localhost:4566 by default.

Custom Service Endpoint for LocalStack

This allows you to completely develop and test the AWS services using Anypoint Studio locally without connecting to the AWS cloud.

Learn more

MuleSoft and LocalStack

Veröffentlicht von Amir Khan

Life is too short to update bios.... get in touch directly.

Hinterlasse einen Kommentar

Erstelle eine Website wie diese mit WordPress.com
Jetzt starten