
Security News
PodRocket Podcast: Inside the Recent npm Supply Chain Attacks
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
serverless-aws-static-file-handler
Advanced tools
Easily serve static files with the Serverless Framework on AWS Lambda.
Host the front-end of your web applications on Serverless framework 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.
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: get
To serve binary content make sure that you setup the plugin in your serverless.yml like so:
plugins:
- serverless-aws-static-file-handler/plugins/BinaryMediaTypes
custom:
apiGateway:
binaryMediaTypes:
- "image/png"
- "image/jpeg"
Some additional real-world examples are demonstrated in the examples/basic/ directory as well as a serverless-offline-specific example in examples/serverless-offline/.
Requires Node.js latest, LTS, or v10 (tested).
Requires Serverless Framework v1.x. If you are new to the Serverless Framework, check out the Serverless Framework Getting Started Guide.
Install with yarn (yarn add serverless-aws-static-file-handler
) or npm (npm install serverless-aws-static-file-handler --save-prod
)
This is a community project. We invite your participation through issues and pull requests! You can peruse the contributing guidelines.
Give a ⭐️ if this project helped you!
We use semantic-release to consistently release semver-compatible versions. This project deploys to multiple npm distribution tags. 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 on one of the above branches.
Copyright © 2017 scott@willeke.com.
This project is MIT licensed.
FAQs
Easily serve static files with the Serverless Framework on AWS Lambda.
The npm package serverless-aws-static-file-handler receives a total of 1,125 weekly downloads. As such, serverless-aws-static-file-handler popularity was classified as popular.
We found that serverless-aws-static-file-handler demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.