MuleSoft Integration with AWS Lambda

Shubham Chaurasia
Another Integration Blog
5 min readMar 2, 2024
MuleSoft Integration with AWS Lambda

In the fast-paced world of modern technology, integration between various platforms and services has become essential for businesses seeking to optimize their operations. MuleSoft, a leading integration platform, offers robust solutions for connecting disparate systems, applications, and data sources. AWS Lambda, on the other hand, provides serverless computing capabilities, allowing developers to run code without managing servers.

Combining the power of MuleSoft with the scalability of AWS Lambda can significantly enhance an organization’s agility and efficiency. In this article, we’ll provide a step-by-step walkthrough on integrating MuleSoft with AWS Lambda.

Key Points to Remember

• AWS Lambda is a regional service.
Serverless compute service: AWS Lambda allows you to run code without provisioning or managing servers.
Event-driven: Executes code in response to events such as HTTP requests, file uploads, database changes, etc.
Auto-scaling: Automatically scales to handle incoming requests without manual intervention.
Pay-per-use pricing: You only pay for the compute time consumed by your code.
Supports multiple languages: Code can be written in languages like Python, Node.js, Java, and more.
Seamless integration: Easily integrates with other AWS services like S3, DynamoDB, API Gateway, etc.
Stateless execution: Each Lambda function invocation is independent and stateless.
Fast deployment: Allows rapid deployment and updates of code without downtime.
Built-in monitoring and logging: Provides monitoring and logging through AWS CloudWatch.
Security: Offers IAM roles for fine-grained access control and security.

❒ Meetup Session/ YouTube Recording

I have delivered a Meetup on this topic. You can watch it on YouTube below. You can watch the step-by-step changes you need to do in the code in the below video.

👉 MuleSoft Integration with AWS Lambda

Step 1: Setup AWS Lambda Function

  1. Log in to your AWS Management Console.
  2. Navigate to the Lambda service.
  3. Click on “Create function” and choose the “Author from scratch” option.
  4. Provide a name for your function, select the preferred runtime (e.g., Node.js, Python, Java), and configure the execution role. (Select Python for this walkthrough)

5. Write or upload your code, and define the handler function.(Use the below code for this walkthrough)

import json
def lambda_handler(event, context):
data = json.dumps(event['country'])
print("Event ", data)
message="I Love my country "
return message

6. Set up any additional configurations, such as environment variables or triggers.

7. Click on “Save” to create your Lambda function.

Get AWS Credentials

You will get a prompt to save the Access Key & Secret Keys when you create your AWS Account. But if you lost it, follow the steps below

  1. Go to top-right corner and click on your account name and click on security credentials

2. Go to Access Keys row and click on Create Access Key.

3. Click on UseCase CLI Option and create access key. Save the access key and secret access key as it will not be visible again.

Step 2: Configure MuleSoft Anypoint Platform

By Default, we don`t have AWS Lambda connector available in Mule Palette, so we will download it from exchange.

  1. Click on Add Modules, and search for AWS Lambda and add it.

These 4 functions are available with AWS Lambda Connector

2. Configure the AWS Lambda connector config — provide the required authentication credentials (Access Key & Secret Key) created in the last step and select the region where you have created your AWS Lambda function.

3. Drop the Invoke connector from the palette and create a flow like below

4. Provide the function name and other parameters.

Qualifier — Specify a version or alias to invoke a published version of the function.

X Amz Invocation Type — Enumeration, one of (EVENT,REQUEST_RESPONSE,DRY_RUN)

RequestResponse (default): Invoke the function synchronously. Keep the connection open until the function returns a response or times out. The API response includes the function response and additional data.

Event: Invoke the function asynchronously. Send events that fail multiple times to the function’s dead-letter queue (if it’s configured). The API response only includes a status code.

DryRun: Validate parameter values and verify that the user or role has permission to invoke the function.

X Amz Log Type — Enumeration, one of: (NONE,TAIL)
Set to TAIL to include the execution log in the response.

X Amz Client Context
Up to 3583 bytes of Base64-encoded data about the invoking client to pass to the function in the context object.

5. Run the application and pass this in POST Request Body

{
"country": "India"
}

By following the above steps, organizations can seamlessly integrate MuleSoft with AWS Lambda to create powerful, scalable, and secure integration solutions. Whether it’s connecting enterprise systems, automating business processes, or building innovative applications, the combined capabilities of MuleSoft and AWS Lambda provide a flexible and reliable foundation for digital transformation initiatives.

This completes the demonstration of the MuleSoft integration with AWS Lambda.

Important Link For References

Please provide feedback. It will help to improve the content.

Thank you for reading this article! If you found this response useful, please consider giving it a ‘clap’ and Follow me for more helpful articles and insights in the future.

--

--

Shubham Chaurasia
Another Integration Blog

MuleSoft Ambassador | Mule Certified Architect & Developer | 11x Salesforce| 4x AWS | 2x GCP | 2x Solace | 2xAzure | https://linkedin.com/in/shubhamchaurasia1/