Skip to content

Commit

Permalink
Added Serverless Lambda Functions initial setup
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrwitek committed May 1, 2019
1 parent 12d5d64 commit 81a6b29
Show file tree
Hide file tree
Showing 14 changed files with 6,432 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# dependencies
/node_modules
/server/node_modules
/.pnp
.pnp.js

Expand All @@ -10,6 +11,7 @@

# production
/build
/server/build

# misc
.DS_Store
Expand Down
10 changes: 10 additions & 0 deletions lambdas/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// lambda build config
{
"presets": ["@babel/preset-typescript", "@babel/preset-env"],
"plugins": [
"@babel/transform-runtime",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-transform-object-assign",
"@babel/plugin-proposal-object-rest-spread"
]
}
1 change: 1 addition & 0 deletions lambdas/build/hello.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions lambdas/src/hello.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { ALBHandler } from 'aws-lambda';
import querystring from 'querystring';

export const handler: ALBHandler = async (event, context) => {
switch (event.httpMethod) {
case 'GET': {
return {
statusCode: 200,
body: `Hello, World!`,
};
}

case 'POST': {
const params = querystring.parse(event.body!);
const name = params.name || 'World!';

return {
statusCode: 200,
body: `Hello, ${name}`,
};
}

default:
return { statusCode: 405, body: 'Method Not Allowed' };
}
};
2 changes: 2 additions & 0 deletions netlify.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
functions = "lambdas/build" # netlify-lambda reads this for local dev server
Loading

0 comments on commit 81a6b29

Please sign in to comment.