# AWS Lambda - Python

## What is AWS Lambda?

AWS Lambda is a service offered by Amazon Web Services that offers a serverless computing platform for creating event-driven pieces of code. Lambda automatically manages any computing resources required for the code, so there is no configuration or development environment required by the end user.

In this guide, we’ll use Lambda for creating a PutObject function using Python. This can be modified for a variety of different API requests, such as GetObject and CreateBucket, and can be used with different SDKs and Runtimes. For a list of supported SDKs and associated API request examples, check out our SDK documentation [here](https://docs.filebase.com/configurations/code-development).

Read below to learn how to configure AWS Lambda functions for use with Filebase.

{% hint style="success" %}

### Prerequisites:

* [x] Have an [AWS Account](https://console.aws.amazon.com/console/home?nc2=h_ct\&src=header-signin\&region=us-east-1) configured to be used on the `us-east-1` region.
* [x] [Sign up](https://filebase.com/signup) for a free Filebase account.&#x20;
* [x] Have your Filebase Access and Secret Keys. Learn how to view your access keys [here](https://docs.filebase.com/getting-started-guides/getting-started-guide#working-with-access-keys).
* [x] Create a Filebase Bucket. Learn how to create a bucket [here](https://docs.filebase.com/getting-started-guides/getting-started-guide#creating-and-working-with-buckets).
  {% endhint %}

### 1. Login to the AWS Management Console. Search for ‘Lambda’ and select the Lambda service.

![](/files/2YaJ8CiSqHbdheqbxKCm)

### 2. Select ‘Create Function’.

![](/files/F3hSRFth7L3AOtVX5Ulg)

### 3. Enter the following configuration parameters for your Lambda function:

![](/files/Q95PuLVNt4yFgsXwDTBe)

* **Function Name:** Filebase-PutObject
* **Runtime:** Python 3.6
* **Architecture:** x86\_64

### 4. In the Code Source, enter the following code:

```python
import json
import boto3

s3 = boto3.client('s3',
endpoint_url = 'https://s3.filebase.com',
aws_access_key_id='filebase-access-key',
aws_secret_access_key='filebase-secret-key')

def lambda_handler(event, context):
    bucket="lambda-bucket"
    
bucket="lambda-bucket"

Company = {}
Company['Company Name'] = 'Filebase, Inc.'
Company['Address'] = '6 Liberty Square Suite 446 Boston, MA 02109'

fileName = 'Filebase' + '.json'
uploadByteStream = bytes(json.dumps(Company).encode('UTF-8'))
s3.put_object(Bucket=bucket, Key=fileName, Body=uploadByteStream)
print('Put Complete')
```

Replace the following values:

* **aws\_access\_key\_id:** Filebase Access Key
* **aws\_secret\_access\_key**: Filebase Secret Key
* **bucket**: Filebase bucket

### 5. After entering the function’s code, select ‘Test’ to create a new test environment.

![](/files/rH06FMSiiaY8Z0WqqHRL)

### 6. Create a new test environment with the event template ‘hello-world’ and give the test event a name.

![](/files/ZlmslPINE7WjTBMHQImG)

### 7. Before running your test, select the ‘Configuration’ tab.

![](/files/ark3QAN8F0eNwk9bfSlW)

### 8. Select ‘Edit’

![](/files/64gQUdzKO3JTMsLVcMiS)

### 9. Change the timeout to 30 seconds.

![](/files/PmbLpNOZyoBJlQrnPGrT)

### 10. Save the configuration, then go back to the code tab. Select 'Deploy' to deploy your code's changes.

![](/files/UyFwUyNKXDedfSiy3kK3)

### 11. Select ‘Test’ to run your code.

![](/files/t4RTfTTY2kL3hWPcXmHY)

### 12. Your code should provide the following execution result:

![](/files/Q3q8ocvPCPcMiEJQRIk3)

### 13. You can confirm that it works by checking your Filebase bucket.

There should be a file called ‘Filebase.json’ that got put into the configured bucket.

![](/files/4vcOLLtIR8QwXQ0RAwZh)


---

# 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://docs.filebase.com/code-development-+-sdks/code-development/aws-lambda-python.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.
