GithubHelp home page GithubHelp logo

netlify / functions.netlify.com Goto Github PK

View Code? Open in Web Editor NEW
515.0 30.0 128.0 2.28 MB

Tutorials, examples, workshops and a playground for serverless with Netlify Functions

Home Page: https://functions.netlify.com

JavaScript 27.90% Nunjucks 34.86% SCSS 37.23%
serverless netlify jamstack lambda

functions.netlify.com's Introduction

Everything you ever wanted to know about Netlify Functions ⚡️

Netlify Status

Contents

Suggesting an example or tutorial

Please create an issue in order to submit contributions to be considered for inclusion in this site.

Choose the approprite issue type from the New Issue page.

Installing

  1. Clone the repo using git clone [email protected]:netlify/functions.git
  2. Use npm to install dependencies npm install
  3. Create a .env file with the environment variables listed below
  4. And run the site locally npm run dev

Environment variables

You'll need to generate a GitHub Access Token to retrieve stars and forks. Add the following to your .env file:

URL=http://localhost:8080
GITHUB_TOKEN=
SLACK_WEBHOOK_URL=
GREETING="hi from the Netlify functions site"

Options

  • npm run dev will spin up a development environment and watch for changes
  • npm run build builds a production version of the site to dist
  • npm run debug will run the eleventy debugger

Dependencies

All dependencies are development at the moment

  • @11ty/eleventy
  • dotenv
  • @11ty/eleventy-plugin-rss
  • @11ty/eleventy-plugin-syntaxhighlight
  • @quasibit/eleventy-plugin-sitemap
  • eleventy-plugin-sass
  • eleventy-plugin-seo

Credits

functions.netlify.com's People

Contributors

bencodezen avatar d3ah avatar daviddarnes avatar hexagoncircle avatar philhawksworth avatar pvinis avatar scottmathson avatar soneji avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

functions.netlify.com's Issues

Double opt-in newsletters subscriptions with Netlify + Airtable + Vero

Summary

We built a function example that:

  • Uses Netlify forms to capture new subscribers.
  • Stores those subscribers in and Airtable table.
  • Generates a secure, encrypted "confirmation URL" for double opt-in.
  • Sends that token via Vero Workflows to the subscriber.
  • Uses a function to verify the confirmation from the subscribers.
  • Stores confirmed subscribers in a second Airtable table.
  • The resultant table plays nicely with Vero Newsletters.

This example pulls together several components into a current, workable version that we think others would find useful.

Checklist

Please provide the following with your example:

Function example: CRUD operations to manage testimonials in Fauna data store

Summary

A Jamstack application that manages testimonials(feedback) in the Fauna data store. It uses the Netlify functions to perform all the CRUD operations to create, list, edit, and remove testimonials. The Netlify functions use GraphQL to communicate with the underlying Fauna data store. This app also uses Gatsby to produce prebuilt markups and is hosted on Netlify.

Checklist

Please provide the following with your example:

Recommended way to import methods from local modules in production?

Hey,

I have a Netlify function A located in functions/netlify-a/netlify-a.js. It relies on some method b() located in functions/helpers/b.js. This will work locally when running netlify dev, but won't work in production with the following message.

{
  errorType: "Runtime.ImportModuleError",
  errorMessage: "Error: Cannot find module '../helpers'↵Require stack:↵- /var/task/netlify-a.js↵- /var/runtime/UserFunction.js↵- /var/runtime/index.js",
  trace: ["..."]
}

I understand that helpers are not bundled during the build time. What's the recommended way to fix this issue? I am already running npm install on every function folder to install npm dependencies, how would I go about importing helper methods without publishing them as a separate npm package?

Thanks!

[Proposal] Function example for Go MongoDB CRUD that can be locally tested

I created a easy-to-use Go MongoDB CRUD API with Netlify Functions and it would be great to add this to the examples.

Project repo: https://github.com/bymi15/go-mongo-serverless-crud-boilerplate

This also allows Go serverless functions to be executed and debugged locally (something that isn't currently supported by Netlify Dev).

I believe this will be useful for developers to easily set up and deploy Netlify functions with the Go MongoDB stack.

Environment variable not binded

Hi, I've deployed your example on my Netlify account.

I am invoking the hello_slack function, but I receive this response:

Oops! Something went wrong. TypeError: Only absolute URLs are supported

I see the function reads the value from process.env.SLACK_WEBHOOK_URL environment variable, so I went to Netlify Site settings > Build & deploy > Build environment variables, and there I have added the variable and set the value.

But I'm afraid the value I set there is not being read at run time.

I am starting with Netlify Lambda Functions, so I was wondering if you could point me at the right direction to set up environment variables.

Thank you!

Function tutorial:

Summary

Please provide a brief description of the Netlify Function tutorial or article.

Checklist

Please provide the following with your tutorial or article:

  • title
  • description
  • URL to the article itself
  • date published

[Proposal] New functions example

[Proposal]
I developed a new functions example. You can find it at this repo: https://github.com/jota-ele-ene/wrap-api

I think all the required info to publish it as an example is in the README

I developed to act as a proxy that adds a parameter retrieved from the environmental variables (e.g. the API SECRET KEYS) to the query parameters URL and fetchs the actual server.

[Proposal] Add Probot example to Functions examples

Hello friends 👋🏼

The Add a function example button on https://functions.netlify.com/examples/ brought me here.

I'm one of the @probot maintainers. Probot is a framework to build GitHub Apps. We created example repositories for the different Node app deployment targets out there, and I just created one for Netlify Functions: https://github.com/probot/example-netlify-functions

I thought you might be interested in adding it to the examples gallery?

It was the first time I deployed to Netlify functions, the setup was super smooth! But if there is anything I should mention in the README, or anything else I can do, please let me know

auth

Please read the contributing guidelines and code of conduct before creating an issue.

Please prefix your issue with one of the following: [Bug] [Proposal] [Question].

Please provide as much information as possible, ideally a summary to describe the issue and / or steps to reproduce the issue.

webpack error

I try to execute npm start and I got then this error.

TypeError: Cannot read property 'properties' of undefined
    at module.exports (/Users/satoshi/practice/netlify-functions-example/node_modules/webpack-cli/bin/config-yargs.js:89:48)
    at Object.<anonymous> (/Users/satoshi/practice/netlify-functions-example/node_modules/webpack-dev-server/bin/webpack-dev-server.js:86:25)
    at Module._compile (module.js:641:30)
    at Object.Module._extensions..js (module.js:652:10)
    at Module.load (module.js:560:32)
    at tryModuleLoad (module.js:503:12)
    at Function.Module._load (module.js:495:3)
    at Function.Module.runMain (module.js:682:10)
    at startup (bootstrap_node.js:191:16)
    at bootstrap_node.js:613:3

This error looks Webpack's error.
plotly/dash-component-boilerplate#12

These modules should be updated.

webpack 
webpack-cli 
webpack-dev-server

Netlify Functions only work half of the time

To test my code, I forked your repo and added my own code (Repo, with my additional code). I also deployed the code onto Netlify. The test is located at the bottom of the Netlify page. In short, I added 2 API and test code of the site.

When the code is tested locally both API works 100% of the time. But when the code is deployed the second API only work 50% of the time. When I run the full version it would give me the following error:

{"error":"formats.find is not a function"}

Thanks for the help.

[Typo] Small typo in options section of README.md

Hello Netlify team, I noticed a small typo in the options section. The third list item, should have "run" (or "start") added to it.

  • npm run debug will the eleventy debugger

Should be updated to:

  • npm run debug will run the eleventy debugger

Since it's such a small change I wasn't sure if I should submit a PR or not. I'm happy to fix it, just let me know.

[Bug] Fix wrong code url in ifttt-to-flick-instagram-make-new-github-post.md

The code url is wrong in ifttt-to-flick-instagram-make-new-github-post.md function. Returing a malformed url in the site: https://github.com/https://github.com/rretsiem/renem.net/blob/574b1c5091e993b520e23f993a6c46069e92cdb0/src/functions.

Should be set without domain to prevent that:
rretsiem/renem.net/blob/574b1c5091e993b520e23f993a6c46069e92cdb0/src/functions

Using console.log in Netlify JS functions

Hello,

I am not a JS coder, but I know Nim.

So I am trying to use the Nim JS FFI feature to export Nim code to JS and use those as Netlify functions.

My experiments:

As I don't know JS, I think that the console.log functions should help me better debug the Nim -> JS generated functions. But I cannot make them work (I was hoping that console.log outputs would show up in the Console when added to the Netlify functions too).

Does console.log work? If yes, can you possible show an example of where you would place it in this Nim generated hello.js?

mich

Please read the contributing guidelines and code of conduct before creating an issue.

Please prefix your issue with one of the following: [Bug] [Proposal] [Question].

Please provide as much information as possible, ideally a summary to describe the issue and / or steps to reproduce the issue.

Install error

Mattaio@DESKTOP-1TK6TKC MSYS .../ServerlessFunctions/netlify-functions-example (master)
$ yarn
yarn install v1.21.1
[1/4] Resolving packages...
[2/4] Fetching packages...
error [email protected]: The engine "node" is incompatible with this module. Expected version ">=4 <=9". Got "12.16.2"
error Found incompatible module.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

Title

Please read the contributing guidelines and code of conduct before creating an issue.

Please prefix your issue with one of the following: [Bug] [Proposal] [Question].

Please provide as much information as possible, ideally a summary to describe the issue and / or steps to reproduce the issue.

netlify config

Please read the contributing guidelines and code of conduct before creating an issue.

Please prefix your issue with one of the following: [Bug] [Proposal] [Question].

Please provide as much information as possible, ideally a summary to describe the issue and / or steps to reproduce the issue.

[security] Enforce Branch Protections

This is an issue generated by (for-internal-use-only)github-tools

Description

This repository has exceeded the development grace period, and the repo owner must decide if branch protections should be enforced.
If this repository houses code used in production in any capacity, branch protections must be enforced. Read (for-internal-use-only)here for more details

What do I need to do?

  • You can control whether or not branch protections are enforced by exclusively creating either of the labels:
    'enforce-branch-protections: true' or 'enforce-branch-protections: false'
  • If there is no branch protection control label, this issue will be recreated.
  • Once you have created either label, you can close this issue.
  • If you have issues or questions, please reach out to #internal-security-n-compliance on slack.

questions

Please read the contributing guidelines and code of conduct before creating an issue.

Please prefix your issue with one of the following: [Bug] [Proposal] [Question].

Please provide as much information as possible, ideally a summary to describe the issue and / or steps to reproduce the issue.

fdfdf

Please read the contributing guidelines and code of conduct before creating an issue.

Please prefix your issue with one of the following: [Bug] [Proposal] [Question].

Please provide as much information as possible, ideally a summary to describe the issue and / or steps to reproduce the issue.
united.zip

Golang forgotten?

All the info here is for JS only. What happened to supporting Golang? There is some brief documentation that explains using go for functions, but every example and most of the docs only talk about JS functions. How do we develop Go functions locally, before we push? Currently only way I can test is to push go code in function dir to repo, and hope it works, which it doesnt.

Update legacy explorers.netlify.com link urls found on functions.netlify.com

Summary

We have decided to retire the explorers.netlify.com site and replace it with suitable redirects to their relevant YouTube urls. Updating legacy explorers.netlify.com link urls found on functions.netlify.com will help with SEO and page load speed. Instead of redirecting users to their legacy link's new relevant YouTube url, we want to land the user directly onto the new relevant YouTube url to pass all SEO value straight to the YouTube video and not encounter a redirect which impacts page load time.

Checklist

Update legacy explorers.netlify.com link urls found on functions.netlify.com to their relevant YouTube urls in the backlinks tab in the explorers.netlify.com migration spreadsheet

Request to make your JS examples as much dependency free as possible

Hello,

I am not a JS coder, and so am not used to tooling like yarn, Babel, etc.

I spent an embarrassing amount of time to figure out why import querystring from "querystring"; in https://github.com/netlify/netlify-functions-example/blob/master/src/lambda/hello_name_post.js didn't work "out of box".

Unbeknownst to me, the import keyword is not supported by default unless you use Babel or something (which I believe you are doing in your yarn magic). Thanks to https://stackoverflow.com/questions/39436322/node-js-syntaxerror-unexpected-token-import to help me figure that out.

You could have simply used const querystring = require("querystring"); instead of import querystring from "querystring";.

Here is my attempt at a super-simplified versions of your examples where focus is on the JS code (generated using Nim) than on yarn/Babel/etc: https://nim-lambda-functions.netlify.com/

The example under "Hello, {name} (POST version)" works the same way as in your version.

Please make all the examples easier to adopt as everyone might not be using yarn, Babel, etc.

Adding images to web server site?

If I want to add some images to the website (that runs the functions), they don't get picked up in the build (by Express). How would I enable this?

Great wee starter project, thank you.

TLS Error with Interfax via Netlify Functions in Production Only

Production Error Only

Delivery Error { Error: socket hang up
at TLSSocket.onHangUp (_tls_wrap.js:1137:19)
at Object.onceWrapper (events.js:313:30)
at emitNone (events.js:111:20)
at TLSSocket.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1064:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickDomainCallback (internal/process/next_tick.js:218:9)
code: ‘ECONNRESET’,
path: null,
host: ‘rest.interfax.net’,
port: 443,
localAddress: undefined }

Netlify's Certificate is not working with interfax

I got this message from an interfax employee regarding the issue:

Hello Sean,

Based upon the error, it seems to be related to the TLS and the possibly the cipher’s attempting to be used by your application. For a list of cipher’s our endpoint supports, please reference the image below and/or the following link: https://www.ssllabs.com/ssltest/analyze.html?d=rest.interfax.net&latest

Thank you,

Anthony Cox
Technical Support Engineer, Client Services

[Feature Request]: Websocket support?

Hi everyone.
I tried for using Lambda functions on Netlify Functions, works great. But there no WS/WSS support, if there support for WS/WSS, has any guide how to use (tutorial/video or etc, i didn't find any).

Thanks :)

Netlify Functions Examples

Hi everyone,

I've discovered Netlify couple weeks ago and I just love deploying a NuxtJS app with it 🙌.
As I'm reading a lot of the Netlify documentations, I've seen that the example number 6 (Fetch) is not working.

Steps to reproduce: open this page and go to the 6th example: https://functions-playground.netlify.com

Click on "Tell me a joke!" you get an error from aws FetchError: request to https://08ad1pao69.execute-api.us-east-1.amazonaws.com/dev/random_joke failed, reason: getaddrinfo ENOTFOUND 08ad1pao69.execute-api.us-east-1.amazonaws.com 08ad1pao69.execute-api.us-east-1.amazonaws.com:443

"Unexpected token import" in lambda

I'm trying to write me a lambda that uses node-fetch similar to the hello_fetch example, but I'm gettign an unexpected token error.

image

It works when I deploy a copy of this repository and then change the existing lambdas, but when I try to do it in my own site (with the exact same code) it gives me this error. Help would be appreciated

File in question: name_from_id.js

Function example:

Summary

Please provide a brief description of the Netlify Function example.

Checklist

Please provide the following with your example:

  • title
  • URL to the source code
  • An additional URL for context or to a working demo
  • Suggested tags, e.g. "airtable", "gatsby", "email"

Vhk

Please read the contributing guidelines and code of conduct before creating an issue.

Please prefix your issue with one of the following: [Bug] [Proposal] [Question].

Please provide as much information as possible, ideally a summary to describe the issue and / or steps to reproduce the issue.

[Question] How to integrate Slack's bolt.js?

Hi,

I'm trying to create a Slack bot using Netlify. I wanted to use bolt.js framework because it makes it easier to communicate with Slack API. However, in their code examples, they start the app by listening to a port:

(async () => {
  // Start your app
  await app.start(process.env.PORT || 3000);
  console.log('⚡️ Bolt app is running!');
})();

Meanwhile, in Netlify functions, the exports.handler is the main entry point.

Any idea how to plug their library into Netlify functions? I tried using serverless express but I wasn't able to get it working.

P.S. I did have a look at the existing Slack examples in the functions documentation. I'm aware that if I give Slack the function endpoint, Slack will send a POST with the payload and I should have all the details required in the body and then use Slack's other npm packages to send messages. However, there's a lot of manual work involved in detecting what type of payload is received and processing that information, whereas Bolt js takes care of that.

Thanks!


Please read the contributing guidelines and code of conduct before creating an issue.

Please prefix your issue with one of the following: [Bug] [Proposal] [Question].

Please provide as much information as possible, ideally a summary to describe the issue and / or steps to reproduce the issue.

Unexpected token ...

1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'start' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle [email protected]~prestart: [email protected]
6 info lifecycle [email protected]~start: [email protected]
7 verbose lifecycle [email protected]~start: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]~start: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/Projects/serverless/node_modules/.bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Frameworks/Python.framework/Versions/3.7/bin:~/mongodb-4.0.5/bin:~/mongodb-4.0.5/bin
9 verbose lifecycle [email protected]~start: CWD: /Users/Projects/serverless
10 silly lifecycle [email protected]~start: Args: [ '-c', 'netlify-lambda serve lambda' ]
11 silly lifecycle [email protected]~start: Returned: code: 1  signal: null
12 info lifecycle [email protected]~start: Failed to exec start script
13 verbose stack Error: [email protected] start: `netlify-lambda serve lambda`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)
13 verbose stack     at emitTwo (events.js:125:13)
13 verbose stack     at EventEmitter.emit (events.js:213:7)
13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at emitTwo (events.js:125:13)

Sample project to reproduce: https://github.com/cryptokni8/serverless

If i deploy this directly on netlify, the function without any deps works, but the one with deps fails even when i use common js notations

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.