Skip to content

Commit 24c47a4

Browse files
authored
Merge pull request #23 from adrai/master
example for fastify
2 parents 8f75c1d + 97cf41e commit 24c47a4

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949

5050
* [Deploying a Proxy API](deploy-proxy-api) – an example of how to create an API Gateway that will proxy all requests directly to a Lambda function
5151
* [Running Express Apps in AWS Lambda](express-app-lambda) – an example of how to deploy an existing Express app with minimal changes to Lambda
52+
* [Running fastify Apps in AWS Lambda](fastify-app-lambda) – an example of how to deploy an existing fastify app with minimal changes to Lambda
5253

5354
## Chat-bots
5455

fastify-app-lambda/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Running fastify apps in AWS Lambda
2+
3+
This is a simple example that shows how to deploy an existing [fastify](https://github.com/fastify/fastify) application, with minimal changes, to AWS Lambda.
4+
5+
## Running the example
6+
7+
1. run `npm install` to grab the dependencies
8+
2. run `npm run generate-proxy` to create a simple proxy API for the fastify app
9+
3. run `npm run deploy` to send everything up to AWS Lambda
10+
11+
The third step will print out a URL you can use to access the fastify app.
12+
13+
## Updating the app
14+
15+
1. Change [`app.js`](app.js)
16+
2. (Optionally) use `npm install <PACKAGE NAME> -S` to install additional dependencies (always save them to `package.json` using `-S`)
17+
3. Run `npm run update` to send the new version up to AWS. No need to generate the proxy again
18+
19+
## More information and limitations
20+
21+
See the [Running Express or fastify Apps in AWS Lambda](https://claudiajs.com/tutorials/serverless-express.html) tutorial.

fastify-app-lambda/app.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const fastify = require('fastify')();
2+
3+
fastify.get('/', (request, reply) => reply.send({ hello: 'world' }));
4+
5+
if (require.main === module) {
6+
// called directly i.e. "node app"
7+
fastify.listen(3000, (err) => {
8+
if (err) console.error(err);
9+
console.log(`server listening on ${fastify.server.address().port}`);
10+
});
11+
} else {
12+
// required as a module => executed on aws lambda
13+
module.exports = fastify;
14+
}

fastify-app-lambda/package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "claudia-fastify",
3+
"version": "1.0.0",
4+
"description": "Example application for running a Node fastify app on AWS Lambda using Amazon API Gateway.",
5+
"main": "lambda.js",
6+
"scripts": {
7+
"deploy": "claudia create --handler lambda.handler --deploy-proxy-api --region us-east-1",
8+
"update": "claudia update",
9+
"generate-proxy": "claudia generate-serverless-express-proxy --express-module app"
10+
},
11+
"license": "Apache-2.0",
12+
"dependencies": {
13+
"aws-serverless-express": "^3.0.2",
14+
"fastify": "^0.24.0"
15+
},
16+
"devDependencies": {
17+
"claudia": "^2.14.0"
18+
}
19+
}

0 commit comments

Comments
 (0)