The lambda_build_worker is a Lambda function that handles build requests by downloading files from a local file server and uploading them to the global-builds S3 bucket.
When a POST request is made to the /builds endpoint, the lambda function:
- Parses the request body to extract the
commitvalue - Downloads the file from
http://host.docker.internal:3000/<commit> - Uploads the file to the
global-buildsS3 bucket with metadata - Returns a success response with file details
- Method: POST
- Path:
/builds - Request Body: JSON with
commitfield (required) - Content-Type:
application/json - Example:
{ "commit": "abc123" }
Request Validation: The API Gateway validates that:
- The request body is present
- The
commitfield is provided and is a string - The content type is
application/json
{
"message": "Build processed successfully",
"commit": "abc123",
"fileName": "abc123.zip",
"fileSize": 1024,
"s3Location": "http://localhost:4566/global-builds/abc123.zip",
"timestamp": "2024-08-17T17:06:00.000Z"
}{
"message": "Error processing build request",
"error": "Commit value is missing from request body",
"timestamp": "2024-08-17T17:06:00.000Z"
}aws-sdk: For S3 operationsaxios: For HTTP requests to the local file server
The lambda function is configured to work with LocalStack:
- S3 Endpoint:
http://localhost:4566 - Access Key:
test - Secret Key:
test - Region:
us-east-1
Files are uploaded to S3 with the naming pattern: <commit>.zip
Each uploaded file includes the following metadata:
commit: The commit value from the requestuploaded-by: Identifier for the lambda functionupload-timestamp: ISO timestamp of when the file was uploaded
The function handles various error scenarios:
- Missing request body
- Missing commit value
- File download failures
- S3 upload failures
To test the function locally:
-
Install dependencies:
cd src/lambda_build_worker npm install -
Run the test script:
node ../../test-build-worker.js
The function is deployed as a ZIP package containing:
index.js- Main function codenode_modules/- Dependenciespackage.json- Package metadata
The lambda function is integrated with:
- API Gateway: Exposes the
/buildsendpoint - S3 Bucket:
global-buildsbucket for file storage - IAM Permissions: S3 PutObject, GetObject, and ListBucket permissions
For local development and testing:
- Ensure LocalStack is running
- The local file server should be accessible at
http://host.docker.internal:3000 - Test with the provided test script or via API Gateway