Skip to content

Use AWS Lambda and Python to expose the contents of an S3 bucket via HTTP.

Notifications You must be signed in to change notification settings

kiinoda/expose-s3-bucket

Repository files navigation

Expose S3 Bucket over HTTPS using AWS Lambda and the Serverless Framework

This code allows you to expose, read-only, an S3 bucket over HTTPS.

Usage

Local setup

Clone code, bring in dependencies and customize configuration file.

$ git clone [email protected]:kiinoda/expose-s3-bucket.git expose-s3-bucket
$ cd expose-s3-bucket
$ cp serverless.yml.sample serverless.yml
... update ENV vars to reflect your situation
... make sure the prefix DOES NOT START with a /
... make sure the prefix ENDS with /
$ npm install

Deployment

$ npx sls deploy
...

After deploying, you should see output similar to:

Deploying expose-s3-bucket to stage dev (eu-west-1)

✔ Service deployed to stack expose-s3-bucket-dev (50s)

api keys:
  bk_key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
endpoints:
  GET - https://XXXXXXXXXX.execute-api.eu-west-1.amazonaws.com/dev/list
  GET - https://XXXXXXXXXX.execute-api.eu-west-1.amazonaws.com/dev/get
functions:
  list: expose-s3-bucket-dev-list (541 kB)
  get: expose-s3-bucket-dev-get (541 kB)

Invocation

After successful deployment, you can list the files in the bucket via HTTP:

curl -sH 'x-api-key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' https://XXXXXXXXXX.execute-api.eu-west-1.amazonaws.com/dev/list?date=2023

Which should result in response similar to the following:

{
  "files": [
    {
      "file": "2023/01/31/test.json",
      "size": 10
    },
    {
      "file": "2023/01/31/test1.json",
      "size": 10
    }
  ]
}

You should then be able to retrieve one of the files you're interested by issuing a get like this:

curl -sH 'x-api-key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' https://XXXXXXXXXX.execute-api.eu-west-1.amazonaws.com/dev/get?file=2023/01/31/test.json

That's about it. Enjoy!

About

Use AWS Lambda and Python to expose the contents of an S3 bucket via HTTP.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages