AWS Lambda - Python

Learn how to configure AWS Lambda functions for use with Filebase.

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.

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

Prerequisites:

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

2. Select ‘Create Function’.

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

  • Function Name: Filebase-PutObject

  • Runtime: Python 3.6

  • Architecture: x86_64

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

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.

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

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

8. Select ‘Edit’

9. Change the timeout to 30 seconds.

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

11. Select ‘Test’ to run your code.

12. Your code should provide the following execution result:

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.

If you have any questions, please join our Discord server, or send us an email at hello@filebase.com

Last updated