A companion repository for workshops with instructions and code examples.
https://drive.google.com/file/d/13D6U2yMwDrg5BJQQPVx_CG2AdF5dA_CV/view?usp=sharing
These steps need to be completed before the workshop:
- Text editor installed
- NPM and NodeJS 6.10 or later installed
- Git 2.0.0 or later installed
- Curl installed
- Serverless Framework installed
- AWS account setup & credentials configured
Download appropriate OS package and install it on your machine.
Test to see that you have npm
and node
installed properly:
$ npm -v
$ node -v
Download appropriate OS package and install it on your machine.
Test to see that you have git
installed properly:
$ git version
Download appropriate OS package and install it on your machine.
Test to see that you have curl
installed properly:
$ curl --version
$ npm install -g serverless
Test to see that you have Serverless Framework installed properly:
$ serverless version
Follow instructions in the tutorial to:
- Setup AWS account
- Configured AWS credentials with the Serverless Framework
Note: Each workshop participant needs to setup their own AWS account.
As part of the workshop, we will do the following exercises.
Create the app from scratch:
$ cd <user_folder>
$ serverless create --template hello-world --path hello-sls
$ sls deploy
Open the handler.js
file in your text editor and update it with the following code:
'use strict';
module.exports.helloWorld = (event, context, callback) => {
let dynamicMsg = 'Hello Unknown!';
// check for GET params and use if available
if (event.queryStringParameters && event.queryStringParameters.name) {
dynamicMsg = `Hello ${event.queryStringParameters.name}!`;
}
const 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,
}),
};
callback(null, response);
};
Then, deploy the new code changes:
$ sls deploy
Let's install the users-service
project from the Github repo:
// cd into your working folder
$ cd <user_folder>
// install the project
$ sls install --url https://github.com/serverless/workshops/tree/master/labs/users-service
// cd into the users-service folder
$ cd users-service
Then, deploy the new project:
$ sls deploy
Note: We need to fetch the urls for the deployed endpoints, and replace the urls in the following code fragments, before we run them.
$ sls info
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:
$ curl -v -X GET https://XXXXXXXXXX.execute-api.us-east-1.amazonaws.com/dev/users/1
$ curl -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"}}'
$ curl -v -X DELETE https://XXXXXXXXXX.execute-api.us-east-1.amazonaws.com/dev/users/1
$ sls info
Let's simulate an error and see it in the logs.
Tail the log for errors:
$ cd <user_folder>/users-service
$ sls 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:
$ curl -v -X GET https://XXXXXXXXXX.execute-api.us-east-1.amazonaws.com/dev/users/999
$ sls metrics
$ sls invoke local -f get -p \
users/test/event.get.json
$ sls invoke -f get -p \
users/test/event.get.json --log