# AWS Lambda

## 🔒 Secure Integration Using AWS Lambda

In some cases, for security or internal policy reasons, you may prefer **not to give Aissist direct access** to your information systems.\
A simple solution is to **create a lightweight API** that grants restricted access, controls what data can be retrieved, filters or processes it as needed, and defines exactly what output Aissist can use.

One great tool for this is **AWS Lambda** — a serverless platform that lets you run code without worrying about server management, scaling, or load balancing.\
It’s **cost-effective** (you only pay for what you use) and **easy to set up**, making it a perfect choice for creating a simple RESTful API for Aissist.

In this tutorial, we'll show you how to build a basic AWS Lambda function that fetches booking information from your internal database.

***

## 🛠️ Step-by-Step Guide

<details>

<summary>Step 1: Write Your Data Retrieval Code</summary>

Create a simple Python script to pull booking details using a booking ID:

```python
import mysql.connector

def lambda_handler(event, context):
    secrets = dict()
    with open("secrets.json") as input_fp:
        secrets = json.load(input_fp)
    
    database = mysql.connector.connect(
        host=secrets["host"],
        database=secrets["database"],
        user=secrets["user"],
        password=secrets["password"]
    )

    query = """ SELECT * FROM cr_booking WHERE id = %s """
    cursor = database.cursor()
    cursor.execute(query, (json.loads(event['body'])["booking_id"],))
    
    column_names = [col[0] for col in cursor.description]
    bookings = [dict(zip(column_names, row)) for row in cursor.fetchall()]
    
    return {"book_details": bookings}
```

</details>

<details>

<summary>Step 2: Package Your Code for AWS Lambda</summary>

You'll need to package your code, your `secrets.json` file, and any required Python libraries into a zip file.

1. Install the MySQL connector package:

   ```bash
   pip3 install --target ./packages mysql-connector
   ```
2. Create the deployment package:

   ```bash
   cd ./packages
   zip -r ../deployment_package.zip .
   cd ..
   zip deployment_package.zip lambda_function.py
   zip deployment_package.zip secrets.json
   ```

</details>

<details>

<summary>Step 3: Create Your AWS Lambda Function</summary>

1. Go to the **AWS Lambda Console**.
2. Create a new **Lambda function**.
3. For simplicity, enable **Function URL** and set **Auth Type** to **None** (or use AWS API Gateway for extra security if needed).
4. Upload your **deployment\_package.zip** created in Step 2.
5. After upload, your Lambda function will have a **public URL** — this will act as your new RESTful API.

<figure><img src="/files/PNJ5v891TqTRMxnhLLzr" alt=""><figcaption></figcaption></figure>

✅ Now your lightweight, secure API is ready!

</details>

<details>

<summary>Step 4: Connect Lambda to Aissist</summary>

Finally, connect your new API to Aissist:

* Follow the usual steps for [**Restful API integration**](/integrations/restful-api.md) create integration first then the action
* Use the **Function URL** from Lambda as the API endpoint

</details>

***

## 📌 Why Use AWS Lambda for Integration?

* 🔒 **Secure Access Control** — Only expose the necessary data.
* ⚡ **Fast and Scalable** — Lambda scales automatically with no server setup.
* 💰 **Cost-Effective** — Pay only for the compute time you use.
* 🔧 **Flexible** — Customize your output for exactly what Aissist needs.

***

After setting up the Shopify integration and actions, you can use the [**Action Debugger**](/integrations/action-debugger.md) to test and verify that everything is working correctly.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.aissist.io/integrations/aws-lambda.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
