Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Cloud Functions

Cloud Functions

What are Cloud Functions anyway? What does it mean to have a serverless environment? In this talk, we will answer these questions and we will explore with more detail some applications such as REST APIs and Conversational Bots. The attendee will learn the basics of Functions as a service (FaaS) and a few details of two different applications.

tolkiana

May 27, 2020
Tweet

More Decks by tolkiana

Other Decks in Programming

Transcript

  1. Responds to events Cloud Services Emit events Writes back Invokes

    other services Other APIs Cloud Functions
  2. > REST APIs > React to events and send push

    notifications > Perform intensive tasks
  3. > REST APIs > React to events and send push

    notifications > Perform intensive tasks > Integrate with other cloud services and APIs (Writing bots)
  4. WHAT DO WE NEED? Tool For this talk Other options

    Language Javascript Typescript, Python, Go Cloud Service Firebase Google Cloud CLI Firebase CLI gcloud CLI
  5. WRITING A HELLO WORLD FUNCTION $ npm install -g firebase-tools

    $ mkdir your_functions_directory $ cd your_functions_directory $ firebase login $ firebase init
  6. WRITING A HELLO WORLD FUNCTION $ npm install -g firebase-tools

    $ mkdir your_functions_directory $ cd your_functions_directory $ firebase login $ firebase init
  7. WRITING A HELLO WORLD FUNCTION $ npm install -g firebase-tools

    $ mkdir your_functions_directory $ cd your_functions_directory $ firebase login $ firebase init
  8. WRITING A HELLO WORLD FUNCTION $ npm install -g firebase-tools

    $ mkdir your_functions_directory $ cd your_functions_directory $ firebase login $ firebase init
  9. WRITING A HELLO WORLD FUNCTION $ npm install -g firebase-tools

    $ mkdir your_functions_directory $ cd your_functions_directory $ firebase login $ firebase init
  10. // index.js const functions = require('firebase-functions'); const admin = require('firebase-admin');

    admin.initializeApp(); // This will be my /customers endpoint exports.customers = functions.https.onRequest((request, response) => { const uid = request.query.uid; const dataBase = admin.database(); // some other code to get info from the db here ... return query.once("value").then((snapshot) => { return response.send(snapshot); }).catch((error) => { return response.status(500).end(); }); });
  11. // index.js const functions = require('firebase-functions'); const admin = require('firebase-admin');

    admin.initializeApp(); // This will be my /customers endpoint exports.customers = functions.https.onRequest((request, response) => { const uid = request.query.uid; const dataBase = admin.database(); // some other code to get info from the db here ... return query.once("value").then((snapshot) => { return response.send(snapshot); }).catch((error) => { return response.status(500).end(); }); });
  12. // index.js const functions = require('firebase-functions'); const admin = require('firebase-admin');

    admin.initializeApp(); // This will be my /customers endpoint exports.customers = functions.https.onRequest((request, response) => { const uid = request.query.uid; const dataBase = admin.database(); // some other code to get info from the db here ... return query.once("value").then((snapshot) => { return response.send(snapshot); }).catch((error) => { return response.status(500).end(); }); });
  13. // index.js const functions = require('firebase-functions'); const admin = require('firebase-admin');

    admin.initializeApp(); // This will be my /customers endpoint exports.customers = functions.https.onRequest((request, response) => { const uid = request.query.uid; const dataBase = admin.database(); // some other code to get info from the db here ... return query.once("value").then((snapshot) => { return response.send(snapshot); }).catch((error) => { return response.status(500).end(); }); });
  14. // index.js const functions = require('firebase-functions'); const admin = require('firebase-admin');

    admin.initializeApp(); // This will be my /customers endpoint exports.customers = functions.https.onRequest((request, response) => { const uid = request.query.uid; const dataBase = admin.database(); // some other code to get info from the db here ... return query.once("value").then((snapshot) => { return response.send(snapshot); }).catch((error) => { return response.status(500).end(); }); });
  15. // index.js const functions = require('firebase-functions'); const admin = require('firebase-admin');

    admin.initializeApp(); // This will be my /customers endpoint exports.customers = functions.https.onRequest((request, response) => { const uid = request.query.uid; const dataBase = admin.database(); // some other code to get info from the db here ... return query.once("value").then((snapshot) => { return response.send(snapshot); }).catch((error) => { return response.status(500).end(); }); });
  16. // index.js const functions = require('firebase-functions'); const admin = require('firebase-admin');

    admin.initializeApp(); // This will be my /customers endpoint exports.customers = functions.https.onRequest((request, response) => { const uid = request.query.uid; const dataBase = admin.database(); // some other code to get info from the db here ... return query.once("value").then((snapshot) => { return response.send(snapshot); }).catch((error) => { return response.status(500).end(); }); });
  17. // index.js const functions = require('firebase-functions'); const admin = require('firebase-admin');

    admin.initializeApp(); // This will be my /customers endpoint exports.customers = functions.https.onRequest((request, response) => { const uid = request.query.uid; const dataBase = admin.database(); // some other code to get info from the db here ... return query.once("value").then((snapshot) => { return response.send(snapshot); }).catch((error) => { return response.status(500).end(); }); });
  18. // index.js const functions = require('firebase-functions'); const admin = require('firebase-admin');

    // REST API functions exports.customers = functions.https.onRequest((request, response) => { // ... Implementation for this endpoint }); exports.accounts = functions.https.onRequest((request, response) => { // ... Implementation for this endpoint }); exports.transactions = functions.https.onRequest((request, response) => { // ... Implementation for this endpoint }); // https://cloud-function-url/customers // https://cloud-function-url/accounts // https://cloud-function-url/transactions
  19. // index.js const functions = require('firebase-functions'); const admin = require('firebase-admin');

    // REST API functions exports.customers = functions.https.onRequest((request, response) => { // ... Implementation for this endpoint }); exports.accounts = functions.https.onRequest((request, response) => { // ... Implementation for this endpoint }); exports.transactions = functions.https.onRequest((request, response) => { // ... Implementation for this endpoint }); // https://cloud-function-url/customers // https://cloud-function-url/accounts // https://cloud-function-url/transactions
  20. // index.js const functions = require('firebase-functions'); const admin = require('firebase-admin');

    // REST API functions exports.customers = functions.https.onRequest((request, response) => { // ... Implementation for this endpoint }); exports.accounts = functions.https.onRequest((request, response) => { // ... Implementation for this endpoint }); exports.transactions = functions.https.onRequest((request, response) => { // ... Implementation for this endpoint }); // https://cloud-function-url/customers // https://cloud-function-url/accounts // https://cloud-function-url/transactions
  21. ADVANTAGES > Easy to get started > Easy to deploy

    > Well documented > Not a huge learning curve
  22. ADVANTAGES > Easy to get started > Easy to deploy

    > Well documented > Not a huge learning curve > They have tons of applications and integrations