Code Monkey home page Code Monkey logo

netlify_first_lambda's Introduction

Netlify Lambda

Everythings start with ...

 npm init

Install the npm package netlify-lambda

npm install netlify-lambda

Add some sripts on package.json file, to build and serve the localhost for local development.

...
  "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.
 touch netlify.toml

and write on it :

[build]
    functions = "lambda"
  • Create a folder ๐Ÿ“ functions on root of the project
mkdir functions
  • Add your js file on it, for exemple.
touch  functions/welcome.js

exemple:

// 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

npm run lambda-serve

Test with Postman on Insomnia

on POST and URI http://localhost:9000/welcome like below

alternate text

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.

git add .
git commit -m 'intial commit'
git push origin master

Go to your netlify dashboard 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

netlify_first_lambda's People

Contributors

xlanex6 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.