---
schema_version: "1"
id: 4eadb68ad2098c1c6e407014355ba6fdb2b14d2d921d350597fdd0f5749cef95
title: Amazon Lambda Connector 1.0 Examples
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/amazon-lambda-connector/1.0/amazon-lambda-connector-examples.md
canonical_url: https://docs.mulesoft.com/amazon-lambda-connector/1.0/amazon-lambda-connector-examples
source_site: docs.mulesoft.com
content_type: documentation
content_hash: b16384f15359302cbd616deb8b27188ec3ee435c31b4c8c17f0bfa6687ef1e35
description: MuleSoft Documentation Site
release: "1.0"
latest: false
---
---
product: Amazon Lambda Connector
version: 1.0
---

# Amazon Lambda Connector 1.0 Examples

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

This example shows how to use the Anypoint Connector for Amazon Lambda (Amazon Lambda Connector) to
invoke a synchronous call and get results from AWS Lambda.

## Before You Begin

Verify that Amazon Lambda Connector is added to your Mule project in Anypoint Studio. If it’s not,
follow the instructions in
[Add the Connector to Your Mule Project](https://docs.mulesoft.com/amazon-lambda-connector/1.0/amazon-lambda-connector-studio#add-connector-to-project).

## Synchronous Invocation Flow

This example shows a simple AWS Lambda function call that is invoked using an HTTP listener. When
the `http://localhost:8081/invoke` URL is called, the Lambda **Invoke** operation is performed, and
the result is returned directly to you.

### Create the Configuration File

1.  In Studio, go to the **Package Explorer** view and right-click the `/src/main/resources` folder
    in your project.

2.  Select **New > File**.

3.  Name the file `environment.properties`.

4.  Edit the file to define the properties and values you need.

### Configure HTTP Listener

Configure an HTTP Listener source to initiate the Amazon Lambda Connector **Invoke** operation flow
each time it receives a request on the configured host (`localhost`) and port (`8081`):

1.  In **Mule Palette**, select **HTTP > Listener**.

2.  Drag **Listener** to the Studio canvas.

3.  Click **+** next to **Connector configuration** to configure a global element that can be used
    by all instances of the HTTP Listener source in the app.

4.  In the **General** tab, specify connection information for the connector.

5.  Click **Test Connection** to confirm that Mule can connect with the specified server.

6.  Click **OK**.

### Configure the Invoke Operation

1.  In **Mule Palette**, select **Amazon Lambda Connector > Invoke**.

2.  Drag **Invoke** to the Studio canvas to the right of the **Listener** source:

    ![Simple invoke example flow in Studio](/mulesoft/current/en-us/amazon-lambda-connector/1.0/_images/amazon-lambda-simple-invoke-example.png)

3.  Configure the **Invoke** operation:

    ![Simple invoke operation General properties configuration](/mulesoft/current/en-us/amazon-lambda-connector/1.0/_images/amazon-lambda-simple-invoke-example-properties.png)

    In this example, the function name is supplied in the `environment.properties` file as
    `$config.functionName`.

    The payload from the HTTP Listener is passed directly into the body of the **Invoke** operation,
    which is specified as `REQUEST_RESPONSE`. This tells AWS Lambda that it does not need to store
    any logs for this operation and effectively makes this a synchronous call, which waits until the
    AWS Lambda function is finished processing before it returns its results.

    Alternatively, you can set **Invocation Type** to `EVENT`, which acts like an asynchronous call
    and returns an empty response immediately while AWS Lambda performs its action in the
    background.

### Create an AWS Lambda Function

Depending on your Lambda function, when you run this flow, you might need to send in a request body.
For example, you can create a Python 3.8 Lambda function like this:

```python
def lambda_handler(event, context):
    message = 'Hello {} {}!'.format(event['first_name'], event['last_name'])

	return {'message' : message}
```

Consult the official AWS documentation if you don’t know how to create a new AWS Lambda function.

This function takes the fields `first_name` and `last_name` from the input in JSON format and sends
a greeting using the specified first and last names.

Call the `http://localhost:8081/invoke` endpoint with a JSON body like this:

```json
{
  "first_name": "<first_name>",
  "last_name": "<last_name>"
}
```

The Mule flow responds with a Code 200 message:

{ "message": "Hello <first\_name> <last\_name>!" }

## XML for the Invoke Example

Paste this code into the Studio XML editor to quickly load the flow for this example into your Mule
app:

```xml
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:amazon-lambda="http://www.mulesoft.org/schema/mule/amazon-lambda" xmlns:http="http://www.mulesoft.org/schema/mule/http"
	xmlns="http://www.mulesoft.org/schema/mule/core"
	xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/amazon-lambda http://www.mulesoft.org/schema/mule/amazon-lambda/current/mule-amazon-lambda.xsd">
	<flow name="amazon-lambda-invoke-example">
		<http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/invoke"/>
		<amazon-lambda:create20150331-functions-invocations-by-function-name doc:name="Invoke" config-ref="Test_Aws_Config" functionName="${config.functionName}" xAmzInvocationType="REQUEST_RESPONSE">
		</amazon-lambda:create20150331-functions-invocations-by-function-name>
	</flow>
</mule>
```

### See Also

- [Introduction to Anypoint Connectors](https://docs.mulesoft.com/connectors/introduction/introduction-to-anypoint-connectors)

- [Anypoint Connector Configuration](https://docs.mulesoft.com/connectors/introduction/intro-connector-configuration-overview).

- [Amazon Lambda Connector Reference](https://docs.mulesoft.com/amazon-lambda-connector/1.0/amazon-lambda-connector-reference).

- [Salesforce Help](https://help.salesforce.com)
