Skip to content

Commit 549d2e3

Browse files
author
wtao
committed
sls change
1 parent d122ac7 commit 549d2e3

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

backend/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# serverless to AWS lambda
2+
3+
## AWS setup
4+
5+
you will need an aws api gateway and a new aws lambda function to begin with
6+
7+
the index-sls.mjs is your lambda function's entry point
8+
9+
when you create a new route in api gateway, don't know why, the full stage name and the route name of the api gateway need to be baked into the index-sls.mjs's app.all(`route`)
10+
11+
## build and deploy
12+
13+
```bash
14+
sls package
15+
16+
aws s3 cp ./serverless/lambda-mongo-grafana.zip s3://[bucket name]/[path key]
17+
18+
aws lambda update-function-code --function-name [your lambda name] --s3-bucket [bucket name] --s3-key [path key] --region [region of your lambda]
19+
```

backend/index-sls.mjs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@ import { dbConfig, dbQuery } from "./express.mjs";
55
const app = express();
66
app.use(express.json());
77

8+
// don't know why, but once deployed to an aws api gateway
9+
// the full stage+route name, /[aws api gateway stage name]/[aws api gateway route name],
10+
// is required for express.js to route properly
11+
// e.g.
12+
// /default/mongo
13+
const awsApiGatewayRoute = "";
14+
815
// grafana: test datasource connect
9-
app.all("/", dbConfig);
16+
app.all(`${awsApiGatewayRoute}/`, dbConfig);
1017

1118
// grafana: qeury
12-
app.all("/query", dbQuery);
19+
app.all(`${awsApiGatewayRoute}/query`, dbQuery);
1320

1421
//default error handler
1522
app.use((err, req, res, next) => {

0 commit comments

Comments
 (0)