https://github.com/xlanex6/netlify_first_lambda
101 netlify lambda - functions as service - Serverless
https://github.com/xlanex6/netlify_first_lambda
javascript netlify-functions serverless
Last synced: about 1 year ago
JSON representation
101 netlify lambda - functions as service - Serverless
- Host: GitHub
- URL: https://github.com/xlanex6/netlify_first_lambda
- Owner: xlanex6
- Created: 2018-12-23T01:12:34.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-06-29T18:44:18.000Z (almost 3 years ago)
- Last Synced: 2025-02-05T00:38:53.034Z (about 1 year ago)
- Topics: javascript, netlify-functions, serverless
- Language: JavaScript
- Homepage:
- Size: 319 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
## Netlify Lambda
Everythings start with ...
```bash
npm init
```
Install the npm package [netlify-lambda](https://www.npmjs.com/package/netlify-lambda)
```bash
npm install netlify-lambda
```
Add some sripts on `package.json` file, to build and serve the localhost for local development.
```json
...
"scripts": {
"lambda-serve": "netlify-lambda serve functions",
"lambda-build": "netlify-lambda build functions"
},
...
```
- After, create a `netlify.toml` file for the config on root of the project.
```bash
touch netlify.toml
```
and write on it :
```toml
[build]
functions = "lambda"
```
- Create a folder 📁 `functions` on root of the project
```bash
mkdir functions
```
- Add your js file on it, for exemple.
```bash
touch functions/welcome.js
```
exemple:
```js
// welcome.js
exports.handler = (event, context, callback) => {
const { name, age, nat } = JSON.parse(event.body);
callback(null, {
statusCode: 200,
body: JSON.stringify({
data: `hello ${name}, you're ${age} from ${nat}`
})
});
};
```
launch your localhost by running
```bash
npm run lambda-serve
```
Test with Postman on [Insomnia](https://insomnia.rest/)
on `POST` and URI `http://localhost:9000/welcome` like below

Welcome in the new univers of Function As Service (`FASS`).
If you need to push on production, create on your favorite git storage provider but works well with [hub](https://hub.github.com/).
```bash
git add .
git commit -m 'intial commit'
git push origin master
```
Go to your [netlify dashboard](https://app.netlify.com/) and deploy your repo.
You will go a url ( exemple: https://wizardly-wozniak-123c2b.netlify.com )
Your endpoint will be on functions tabs of the project, and set as `PROJECT_URL/.netlify/functions/NAME_OF_YOUR_FUNCTION`
- Enjoy your first lambda on netlify