AWS Lambda
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:

  • Have an AWS Account configured to be used on the us-east-1 region.
  • Have Your Filebase Access and Secret Keys. Learn how to view your access keys here.
  • Create a Filebase Bucket. Learn how to create a bucket here.

1. Login to the AWS Management Console. Search for IAM and select the IAM services result.

2. From the left side bar menu, select the ‘Roles’ option, then select ‘Create Role’.

3. Select AWS Service for the Trusted Entity Type, then Lambda for the Use Case:

4. From the Add Permissions screen, select ‘Create Policy’.

This will open a new tab for policy creation.

5. In the policy editor, select the following options for your new policy:

  • Service: S3
  • Actions: PutObject
  • Resources: All Resources

6. Select Next, then give your policy a name and select ‘Create Policy’.

7. Return to the Create Role window, and under the ‘Add Permissions’ options, select your newly created policy.

8. Next, provide a name for your role and finish creating it by adding a description and verifying the permission policy has been set correctly:

9. Create your role. You will receive a banner message confirming the role creation. Select ‘View role’ from this banner.

10. From the role menu, select ‘Add permissions’, then select ‘Attach policies’:

11. Add the AWSLambdaBasicExecutionRole policy to your role.

12. Next, search for ‘Lambda’ and select the Lambda service.

13. Select ‘Create Function’.

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

  • Function Name: Filebase-PutObject
  • Runtime: Python 3.6
  • Architecture: x86_64
  • Execution Role: Use an Existing Role
  • Existing Role: Filebase-PutObject-Role

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

1
import json
2
import boto3
3
4
s3 = boto3.client('s3',
5
endpoint_url = 'https://s3.filebase.com',
6
aws_access_key_id='filebase-access-key',
7
aws_secret_access_key='filebase-secret-key')
8
9
def lambda_handler(event, context):
10
bucket="lambda-bucket"
11
12
bucket="lambda-bucket"
13
14
Company = {}
15
Company['Company Name'] = 'Filebase, Inc.'
16
Company['Address'] = '6 Liberty Square Suite 446 Boston, MA 02109'
17
18
fileName = 'Filebase' + '.json'
19
uploadByteStream = bytes(json.dumps(Company).encode('UTF-8'))
20
s3.put_object(Bucket=bucket, Key=fileName, Body=uploadByteStream)
21
print('Put Complete')
Copied!
Replace the following values:
  • aws_access_key_id: Filebase Access Key
  • aws_secret_access_key: Filebase Secret Key
  • bucket: Filebase bucket

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

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

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

19. Select ‘Edit’

20. Change the timeout to 30 seconds.

21. Save the configuration, then go back to the code tab. Select ‘Test’ to test your code.

22. Your code should provide the following execution result:

23. 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 [email protected]
Copy link
Contents
What is AWS Lambda?
1. Login to the AWS Management Console. Search for IAM and select the IAM services result.
2. From the left side bar menu, select the ‘Roles’ option, then select ‘Create Role’.
3. Select AWS Service for the Trusted Entity Type, then Lambda for the Use Case:
4. From the Add Permissions screen, select ‘Create Policy’.
5. In the policy editor, select the following options for your new policy:
6. Select Next, then give your policy a name and select ‘Create Policy’.
7. Return to the Create Role window, and under the ‘Add Permissions’ options, select your newly created policy.
8. Next, provide a name for your role and finish creating it by adding a description and verifying the permission policy has been set correctly:
9. Create your role. You will receive a banner message confirming the role creation. Select ‘View role’ from this banner.
10. From the role menu, select ‘Add permissions’, then select ‘Attach policies’:
11. Add the AWSLambdaBasicExecutionRole policy to your role.
12. Next, search for ‘Lambda’ and select the Lambda service.
13. Select ‘Create Function’.
14. Enter the following configuration parameters for your Lambda function:
15. In the Code Source, enter the following code:
16. After entering the function’s code, select ‘Test’ to create a new test environment.
17. Create a new test environment with the event template ‘hello-world’ and give the test event a name.
18. Before running your test, select the ‘Configuration’ tab.
19. Select ‘Edit’
20. Change the timeout to 30 seconds.
21. Save the configuration, then go back to the code tab. Select ‘Test’ to test your code.
22. Your code should provide the following execution result:
23. You can confirm that it works by checking your Filebase bucket.