
## Deploy Lambda function to AWS

URL: https://docs.atlan.com/product/capabilities/build-apps/sdks/python/events/how-tos/aws-lambda/deploy-lambda

> Deploy AWS Lambda functions with the Atlan Python SDK (pyatlan) for event-driven metadata processing and real-time integrations.

# Deploy your code

You should now be in a position to deploy your code.

## Package code

Before uploading the code, first package it.

### Java

To make sure any of your logging statements reach the AWS CloudWatch logs, build your Java code to a jar file that includes log bindings for SLF4J. For example, you could use logback as follows in Gradle:

```groovy showLineNumbers title="build.gradle"
plugins {
 id 'java'
 id "com.github.johnrengelman.shadow" version "7.1.2"
}

shadowJar {
 archiveClassifier = 'jar-with-dependencies'
 dependencies {
 include(dependency('ch.qos.logback:logback-classic:.*'))
 include(dependency('ch.qos.logback:logback-core:.*'))
 }
}

task buildZip(type: Zip)
}
```

Then, by running `./gradlew buildZip` you will have a ready-to-upload zip file with your code under the `build/distributions` directory of your codebase.

:::tip[Not necessary to include the Java SDK itself]
Note that you don't need to bundle the Java SDK itself as part of your code package. The SDK will be used automatically via the AWS Lambda layer we created earlier.
:::

### Python

We recommend just copying and pasting your code to the default `lambda_function.py` file set up for you when configuring the AWS Lambda function. Alternatively, when your code relies on other libraries (that you don't have other layers providing), you can review [AWS's own documentation for building an archive for Python code](https://docs.aws.amazon.com/lambda/latest/dg/python-package.html) that will bundle all of those dependencies with your code.

:::tip[Not necessary to include the Python SDK itself]
Note that you don't need to bundle the Python SDK itself as part of your code package. The SDK will be used automatically via the AWS Lambda layer we created earlier.
:::

## Upload code

1. Navigate back to your [AWS Lambda functions console](https://console.aws.amazon.com/lambda/home#/functions).
2. From the *Functions* list, click the function you want to deploy your code into.
3. On the **Code** tab:

 **Java**

1. In the upper-right of the *Code source* table, click **Upload from** and then **.zip or .jar file**.
2. Use the **Upload** button to select the zip file containing your code.
3. In the lower-right of the dialog click the **Save** button to deploy your code.
4. Scroll down to the *Runtime settings* table and in the upper-right click the **Edit** button.
5. Change the *Handler* to the canonical class name for the new class you wrote that extends `AbstractLambdaHandler` and implements `AtlanEventHandler`.
6. In the lower-right, click the **Save** button.

 **Python**

1. In the *Code source* table you can either:

 - (Recommended) Copy / paste the code from your new module (file) into the editor window for **lambda_function.py**.
 - In the upper-right, click **Upload from** and choose the location of your code.

2. Towards the middle of the *Code source* table, click the **Deploy** button to deploy your code.
3. If you uploaded your own code:
 1. Scroll down to the *Runtime settings* table and in the upper-right click the **Edit** button.
 2. Change the *Handler* to the module (file) name for the new module you wrote that extends `AtlanEventHandler` and implements the simple `lambda_handler(event, context)` function. The value should be: `<module_name>.lambda_handler`.
 3. In the lower-right, click the **Save** button.

## Unit test code

Finally, to confirm your code is all set up to work as expected, you can run a quick test.

1. Change to the **Test** tab of your AWS Lambda function.
2. For *Event name* enter something like `webhook-validation`.
3. In the *Event JSON* code area, paste in the following payload:

```json showLineNumbers title="Event JSON"
{
 "version": "2.0",
 "routeKey": "$default",
 "rawPath": "/",
 "rawQueryString": "",
 "headers": {
 "content-length": "85",
 "x-amzn-tls-cipher-suite": "ECDHE-RSA-AES128-GCM-SHA256",
 "x-amzn-tls-version": "TLSv1.2",
 "x-amzn-trace-id": "Root=1-64931f85-02856e0b115997577ed16d97",
 "x-forwarded-proto": "https",
 "host": "uo8rokyifhnhubgagp106xhrpvgmuqhx.lambda-url.us-east-1.on.aws",
 "x-forwarded-port": "443",
 "content-type": "text/plain; charset=utf-8",
 "x-forwarded-for": "34.194.9.164",
 "accept-encoding": "gzip",
 "user-agent": "go-resty/1.12.0 (https://github.com/go-resty/resty)"
 },
 "requestContext": {
 "accountId": "anonymous",
 "apiId": "uo8rokyifhnhubgagp106xhrpvgmuqhx",
 "domainName": "uo8rokyifhnhubgagp106xhrpvgmuqhx.lambda-url.us-east-1.on.aws",
 "domainPrefix": "uo8rokyifhnhubgagp106xhrpvgmuqhx",
 "http": {
 "method": "POST",
 "path": "/",
 "protocol": "HTTP/1.1",
 "sourceIp": "34.194.9.164",
 "userAgent": "go-resty/1.12.0 (https://github.com/go-resty/resty)"
 },
 "requestId": "27539f31-d444-419e-b1ad-4382657b7e04",
 "routeKey": "$default",
 "stage": "$default",
 "time": "21/Jun/2023:16:04:21 +0000",
 "timeEpoch": 1687363461544
 },
 "body": "{\"atlan-webhook\": \"Hello, humans of data! It worked. Excited to see what you build!\"}",
 "isBase64Encoded": false
}
```

4. In the upper-right of the *Test event* table, click the **Test** button.
5. This first time the code runs it may take a number of seconds to complete.

When completed, you should see a dialog at the top of the **Test** tab similar to the following, indicating a successful run and including log output:

> *Executing function: suceeded (logs ) — see full content on the documentation site.*

---
