This project shows how to use nbb with an AWS Node.js lambda. Also, it demonstrates lambda function URLs. More details could be found in the post.
The project consists of two modules:
This module describes the serverless stack that creates presigned urls for file uploads.
It consists of a Node.js lambda implemented using nbb
, API Gateway that provides an endpoint and IAM role.
In order to deploy the stack follow these steps:
- install dependencies for this module execute the following:
cd lambda-api-gw/
npm install
- provision the stack use the following command:
sls deploy
Make sure you've set correct values for the region
, buckets
and accounts
parameters in serverless-common.yml.
If provisioned successfully the output should be similar to:
endpoint: GET - https://nhhx4a5v4k.execute-api.eu-west-1.amazonaws.com/dev/upload-url/{env}/{folderName}/{fileName}
functions:
presigned-upload-url: s3-presigned-upload-api-gw-url-dev-presigned-upload-url (3.4 MB)
- verify that the lambda is working:
https://nhhx4a5v4k.execute-api.eu-west-1.amazonaws.com/dev/upload-url/dev/folder1/file1.csv
The output should look like:
nbb-lambda successful response
{
"url": "https://s3.eu-west-1.amazonaws.com/dev-docs-upload-bucket",
"fields": {
"key": "folder1/file1.csv",
"bucket": "dev-docs-upload-bucket",
"X-Amz-Algorithm": "AWS4-HMAC-SHA256",
"X-Amz-Credential": "ASXXXXXXXXXXXXXXXXXX/20220411/eu-west-1/s3/aws4_request",
"X-Amz-Date": "20220411T141801Z",
"X-Amz-Security-Token": "IQoJb3JpZ2luX2VjEIf//////////wEaCWV1L...",
"Policy": "eyJleHBpcmF0aW9uIjoiMjAyMi0wNC0xMVQxNDoyM...",
"X-Amz-Signature": "831a06ca70b..."
}
}
- to remove the stack use the following command:
sls remove
This module describes the serverless stack that creates presigned urls for file uploads.
It consists of a Node.js lambda implemented using nbb
and IAM role. This module leverages recently announced AWS Function URLs feature.
In order to deploy the stack follow these steps:
- install dependencies for this module execute the following:
cd lambda-url/
npm install
- provision the stack use the following command:
sls deploy
Make sure you've set correct values for the region
, buckets
and accounts
parameters in serverless-common.yml.
If provisioned successfully the output should be similar to:
endpoint: https://kafts7qbofkzbbvxbxxzavlv6i0aelqr.lambda-url.eu-west-1.on.aws/
functions:
presigned-upload-lambda-url: s3-presigned-upload-lambda-url-dev-presigned-upload-lambda-url (3.4 MB)
- verify that the lambda is working with the following command:
curl https://kafts7qbofkzbbvxbxxzavlv6i0aelqr.lambda-url.eu-west-1.on.aws/dev/folder1/file1.csv
The output should look like:
nbb-lambda successful response
{
"url": "https://s3.eu-west-1.amazonaws.com/dev-docs-upload-bucket",
"fields": {
"key": "folder1/file1.csv",
"bucket": "dev-docs-upload-bucket",
"X-Amz-Algorithm": "AWS4-HMAC-SHA256",
"X-Amz-Credential": "ASXXXXXXXXXXXXXXXXXX/20220411/eu-west-1/s3/aws4_request",
"X-Amz-Date": "20220411T141801Z",
"X-Amz-Security-Token": "IQoJb3JpZ2luX2VjEIf//////////wEaCWV1L...",
"Policy": "eyJleHBpcmF0aW9uIjoiMjAyMi0wNC0xMVQxNDoyM...",
"X-Amz-Signature": "831a06ca70b..."
}
}
- to remove the stack use the following command:
sls remove