Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/activescott/serverless-aws-static-file-handler
Easily serve static files with the Serverless Framework on AWS Lambda.
https://github.com/activescott/serverless-aws-static-file-handler
aws-lambda binary nodejs serverless serverless-architectures serverless-framework serverless-functions serverless-plugin
Last synced: about 2 months ago
JSON representation
Easily serve static files with the Serverless Framework on AWS Lambda.
- Host: GitHub
- URL: https://github.com/activescott/serverless-aws-static-file-handler
- Owner: activescott
- License: mit
- Created: 2018-01-07T09:07:10.000Z (about 7 years ago)
- Default Branch: main
- Last Pushed: 2024-05-01T22:32:00.000Z (10 months ago)
- Last Synced: 2024-10-11T21:25:46.330Z (4 months ago)
- Topics: aws-lambda, binary, nodejs, serverless, serverless-architectures, serverless-framework, serverless-functions, serverless-plugin
- Language: JavaScript
- Size: 6.54 MB
- Stars: 52
- Watchers: 5
- Forks: 14
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[](https://www.npmjs.com/package/serverless-aws-static-file-handler)
[](https://www.npmjs.com/package/serverless-aws-static-file-handler)
[](https://github.com/activescott/serverless-aws-static-file-handler/actions)
[](https://coveralls.io/github/activescott/serverless-aws-static-file-handler)
[](https://github.com/activescott/serverless-aws-static-file-handler/blob/master/LICENSE)
[](https://github.com/activescott/serverless-aws-static-file-handler)# serverless-aws-static-file-handler
Host the front-end of your web applications on [Serverless framework](https://github.com/serverless/serverless) on AWS Lambda right alongside the API.
It is a fast and easy way to get started and makes it trivial to deploy your web applications. If you need better response time in the future and get concerned about AWS costs of using Lambda to static content, you put CloudFront in front of your Serverless endpoints service static content.
- [Usage / Quick Start](#usage--quick-start)
- [Prerequisites / Usage Requirements](#prerequisites--usage-requirements)
- [Install](#install)
- [Features](#features)
- [Contributing 🤝](#contributing-🤝)
- [Show your support](#show-your-support)
- [Release Process (Deploying to NPM)](#release-process-deploying-to-npm)
- [License 📝](#license-📝)## Usage / Quick Start
Import & initialize:
const StaticFileHandler = require('serverless-aws-static-file-handler')
# configure where to serve files from:
const clientFilesPath = path.join(__dirname, "./data-files/")
const fileHandler = new StaticFileHandler(clientFilesPath)Define a handler in your code as follows:
module.exports.html = async (event, context) => {
event.path = "index.html" // forcing a specific page for this handler, ignore requested path. This would serve ./data-files/index.html
return fileHandler.get(event, context)
}In your `serverless.yml` file, reference the handler function from above to provide routes to your static files:
functions:
html:
handler: handler.html
events:
- http:
path: /
method: get# Note Binary files work too! See configuration information below
png:
handler: handler.png
events:
- http:
path: png
method: get# The following example uses a path placeholder to serve all files directly in the /binary/ directory:
binary:
handler: handler.binary
events:
- http:
path: /binary/{pathvar+}
method: getTo serve binary content make sure that you setup the plugin in your serverless.yml like so:
plugins:
- serverless-aws-static-file-handler/plugins/BinaryMediaTypescustom:
apiGateway:
binaryMediaTypes:
- "image/png"
- "image/jpeg"Some additional real-world examples are demonstrated in the [examples/basic/](examples/basic) directory as well as a [serverless-offline](https://github.com/dherault/serverless-offline)-specific example in [examples/serverless-offline/](examples/serverless-offline).
## Prerequisites / Usage Requirements
Requires Node.js latest, LTS, or v10 ([tested](https://github.com/activescott/serverless-aws-static-file-handler/actions)).
Requires Serverless Framework v1.x.
If you are new to the Serverless Framework, check out the [Serverless Framework Getting Started Guide](https://serverless.com/framework/docs/getting-started/).## Install
Install with yarn (`yarn add serverless-aws-static-file-handler`) or npm (`npm install serverless-aws-static-file-handler --save-prod`)
## Features
- Simple to get started
- Works with **text files** such as HTML or **binary** files such as images or fonts## Contributing 🤝
This is a community project. We invite your participation through issues and pull requests! You can peruse the [contributing guidelines](.github/CONTRIBUTING.md).
## Show your support
Give a ⭐️ if this project helped you!
## Release Process (Deploying to NPM)
We use [semantic-release](https://github.com/semantic-release/semantic-release) to consistently release [semver](https://semver.org/)-compatible versions. This project deploys to multiple [npm distribution tags](https://docs.npmjs.com/cli/dist-tag). Each of the below branches correspond to the following npm distribution tags:
| branch | npm distribution tag |
| ------ | -------------------- |
| main | latest |
| beta | beta |To trigger a release use a Conventional Commit following [Angular Commit Message Conventions](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines) on one of the above branches.
## License 📝
Copyright © 2017 [[email protected]](https://github.com/activescott).
This project is [MIT](https://github.com/activescott/serverless-http-invoker/blob/master/LICENSE) licensed.