serverless/workshops

Name: workshops

Owner: Serverless

Description: Companion repo for workshops with instructions and code examples

Created: 2017-10-27 18:18:12.0

Updated: 2018-01-24 12:20:36.0

Pushed: 2017-11-17 18:08:25.0

Homepage:

Size: 11

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Serverless Workshops

A companion repository for workshops with instructions and code examples.

Slides

https://drive.google.com/file/d/13D6U2yMwDrg5BJQQPVx_CG2AdF5dA_CV/view?usp=sharing

Pre-requisites

These steps need to be completed before the workshop:

Install NPM and NodeJS

Download appropriate OS package and install it on your machine.

Test to see that you have npm and node installed properly:

m -v
de -v
Install Git

Download appropriate OS package and install it on your machine.

Test to see that you have git installed properly:

t version
Install Curl

Download appropriate OS package and install it on your machine.

Test to see that you have curl installed properly:

rl --version
Install Serverless Framework
m install -g serverless

Test to see that you have Serverless Framework installed properly:

rverless version
AWS Setup

Follow instructions in the tutorial to:

Note: Each workshop participant needs to setup their own AWS account.

Labs Code Examples

As part of the workshop, we will do the following exercises.

Exercise 1: Hello World - creating the hello world app

Create the app from scratch:

 <user_folder>
rverless create --template hello-world --path hello-sls
s deploy
Exercise 2: Hello World - dynamic app

Open the handler.js file in your text editor and update it with the following code:

 strict';

le.exports.helloWorld = (event, context, callback) => {

t dynamicMsg = 'Hello Unknown!';

 check for GET params and use if available
 (event.queryStringParameters && event.queryStringParameters.name) {
  dynamicMsg = `Hello ${event.queryStringParameters.name}!`;


nst response = {
statusCode: 200,
headers: {
  'Access-Control-Allow-Origin': '*', // Required for CORS support to work
},
body: JSON.stringify({
  // message: 'Go Serverless v1.0! Your function executed successfully!',
  message: dynamicMsg,
  input: event,
}),


llback(null, response);

Then, deploy the new code changes:

s deploy
Exercise 3: Users Service - install project

Let's install the users-service project from the Github repo:

d into your working folder
 <user_folder>

nstall the project
s install --url https://github.com/serverless/workshops/tree/master/labs/users-service

d into the users-service folder
 users-service

Then, deploy the new project:

s deploy
Exercise 4: Users Service - calling the API

Note: We need to fetch the urls for the deployed endpoints, and replace the urls in the following code fragments, before we run them.

Fetch the urls for the endpoints
s info
Get User

Go to the browser and type in the url:

https://XXXXXXXXXX.execute-api.us-east-1.amazonaws.com/dev/users/1

Or you can curl it on the command line:

rl -v -X GET https://XXXXXXXXXX.execute-api.us-east-1.amazonaws.com/dev/users/1
Create User
rl -v -X POST \
   https://XXXXXXXXXX.execute-api.us-east-1.amazonaws.com/dev/users/create \
   -d '{"user": {"name":"John Doe", "email":"john.doe@email.com"}}'
Delete User
rl -v -X DELETE https://XXXXXXXXXX.execute-api.us-east-1.amazonaws.com/dev/users/1
Exercise 5: Users Service - other CLI commands
Fetch the project urls
s info
Tailing logs

Let's simulate an error and see it in the logs.

Tail the log for errors:

 <user_folder>/users-service

s logs -f get -t

Go to the browser and type in the url:

https://XXXXXXXXXX.execute-api.us-east-1.amazonaws.com/dev/users/999

Or you can curl it on the command line:

rl -v -X GET https://XXXXXXXXXX.execute-api.us-east-1.amazonaws.com/dev/users/999
Fetch the project metrics
s metrics
Invoke a function locally
s invoke local -f get -p \
   users/test/event.get.json
Invoke a function remotely
s invoke -f get -p \
  users/test/event.get.json --log

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.