Skip to content

aws-node-signed-uploads

Directory actions

More options

Directory actions

More options

Latest commit

 

History

History

aws-node-signed-uploads

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

README.md

AWS Node Signed Uploads

Requirements

  • Node.js 24
  • npm which comes with Node.js
  • yarn

Introduction

The approach implemented in this service is useful when you want to use Amazon API Gateway and you want to solve the 10MB payload limit.

The service is based on the serverless framework. The service is uploading objects to a specific S3 bucket using a pre-signed URL, generated with @aws-sdk/s3-request-presigner's getSignedUrl.

The package targets the nodejs24.x AWS Lambda runtime.

Settings

If you prefer to use a different region or stage, change these:

$ export AWS_STAGE=
$ export AWS_REGION=

Defaults are dev and eu-central-1.

The upload bucket name defaults to ${self:service}-${sls:stage}-${aws:accountId} (service, stage, and account qualified, so it's globally unique and safe to deploy without collisions). Override it in custom.bucketName if you want a different name:

custom:
  bucketName: my-own-bucket-name

File name to sign

The file you want to upload is signed via x-amz-meta-filekey header.

How to use

Get dependencies with yarn or npm install. The following examples will assume the usage of yarn.

Issue a GET request to get the signed URL:

curl --request GET \
  --url https://{serviceID}.execute-api.{region}.amazonaws.com/dev/upload \
  --header 'x-amz-meta-filekey: the-road-to-graphql.pdf'

If your bucket is called foo, and you upload the-road-to-graphql, after receiving the signed URL, issue a PUT request with the information you have signed:

curl --request PUT \
  --url 'https://foo.s3.eu-central-1.amazonaws.com/the-road-to-graphql.pdf?X-Amz-SignedHeaders=host&X-Amz-Signature=the-signature&X-Amz-Security-Token=the-token&X-Amz-Expires=30&X-Amz-Date=20181210T113015Z&X-Amz-Credential=something10%2Feu-central-1%2Fs3%2Faws4_request&X-Amz-Algorithm=AWS4-HMAC-SHA256' \
  --data 'somemething-awesome'

Integrations

Here's a short list of possible integrations I found making a quick Google search:

Develop locally

Starting a local dev server and its endpoint for receiving uploads:

$ yarn start

Deployment

Setup your AWS credentials.

Run the following the fire the deployment:

$ yarn deploy

After running deploy, you should see output similar to:

Deploying "aws-node-signed-uploads" to stage "dev" (eu-central-1)

✔ Service deployed to stack aws-node-signed-uploads-dev (48s)

endpoint: GET - https://xxxxxxxxxx.execute-api.eu-central-1.amazonaws.com/dev/upload
functions:
  upsert-objects: dev-aws-node-signed-uploads-upload (1.4 kB)