Skip to content

Karibash/aws-serverless-express-edge

 
 

Repository files navigation

Run serverless applications on the edge in Amazon CloudFront by leveraging Lambda@Edge. This is especially useful for deporting the intensive task of server rendering SPAs to AWS Lambda, which will let you scale to 100 reqs/s painlessly all the while leveraging CloudFront's edge cache.

Limits on Lambda@Edge.

Getting Started

npm install aws-serverless-express-edge
// lambda.js
'use strict'
const awsServerlessExpress = require('aws-serverless-express-edge')
const app = require('./app')
const server = awsServerlessExpress.createServer(app)

exports.handler = (event, context) => awsServerlessExpress.proxy(server, event, context)

Package and create your Lambda function, deploy the function in us-east-1, then link it to a CloudFront distribution as an Origin Request.

⚠️ It is strongly recommended to serve assets from another distribution.

Quick Start/Example

TODO

Getting the Edge event object

This package includes middleware to easily get the event object Lambda receives from API Gateway

const awsServerlessExpressMiddleware = require('aws-serverless-express-edge/middleware')
app.use(awsServerlessExpressMiddleware.eventContext())
app.get('/', (req, res) => {
  res.json(req.edge.event)
})

About

Run serverless applications on the edge in Amazon CloudFront by leveraging Lambda@Edge.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 86.5%
  • HTML 13.5%