An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to...

80
An Introduction to Microservices with the Serverless Framework

Transcript of An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to...

Page 1: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

An Introduction to Microservices with the Serverless Framework

Page 2: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

Fernando Medina CoreySolutions ArchitectServerless Inc.

@fmc_sea

Page 3: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

What are we doing?

@fmc_sea An Introduction to Microservices with the Serverless Framework �3

Page 4: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �4

Our Goals

Page 5: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

Let’s get our environment ready

@fmc_sea An Introduction to Microservices with the Serverless Framework �5

Page 6: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

Create an AWS Account

@fmc_sea An Introduction to Microservices with the Serverless Framework �6

https://aws.amazon.com/free

Page 7: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

Install the AWS CLI

@fmc_sea An Introduction to Microservices with the Serverless Framework �7

https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html

(This assumes you have Python3 installed)

Page 8: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

Configure the AWS CLI@fmc_sea An Introduction to Microservices with the Serverless Framework �8

https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html

Page 9: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

Install the Serverless Framework

@fmc_sea An Introduction to Microservices with the Serverless Framework �9

https://serverless.com/framework/docs/getting-started/

Mac/Linux Windows

Page 10: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

Install the Serverless Framework

@fmc_sea An Introduction to Microservices with the Serverless Framework �10

https://serverless.com/framework/docs/getting-started/

(With npm)

Page 11: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

Clone the Project

@fmc_sea An Introduction to Microservices with the Serverless Framework �11

https://github.com/fernando-mc/serverless-devweek2020

Page 12: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

Develop@fmc_sea An Introduction to Microservices with the Serverless Framework �12

Page 13: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

What are we developing?

@fmc_sea An Introduction to Microservices with the Serverless Framework �13

Page 14: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �14

Page 15: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �15

How does it work?

Page 16: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �16

Page 17: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �17

Page 18: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �18

Page 19: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �19

Page 20: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �20

Page 21: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �21

What’s the code look like?

Page 22: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �22

What’s the code look like?

Page 23: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �23

generate_code.py

1. Phone number as input2. (re)generates verification code3. Sends the code to the number

Page 24: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �24

get_votes.py

1. Gets vote counts for all songs2. Returns them to the frontend

Page 25: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �25

vote.py

1. Verified phone number/code 2. Sets the code as used3. Increments a vote counter4. Returns the new vote count

Page 26: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �26

app.js

1. Handles interacting with the API2. Updates vote counts in the UI3. Provides helper text for the user

Page 27: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �27

index.html

1. Snazzy Spotify embeds!2. Pretty Semantic UI buttons!3. Cool vote counters!

Page 28: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �28

serverless.yml

1. Creates Lambda Functions2. Creates API Gateway Endpoints3. Creates our DynamoDB table4. Sets the service’s permissions

Page 29: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �29

What’s in serverless.yml?

Page 30: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �30

Service Configuration

Page 31: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �31

Provider details

Page 32: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �32

Provider details - IAM Roles

Page 33: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �33

Provider details - IAM Roles

Page 34: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �34

Function Definitions

Page 35: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �35

Function Definitions

Page 36: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �36

Function Definitions

Page 37: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �37

Resources

Page 38: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �38

Optional Packaging

Page 39: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �39

How many total lines of code?

(README not included)

Page 40: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �40

Total lines: 436

Page 41: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

Deploy@fmc_sea An Introduction to Microservices with the Serverless Framework �41

Page 42: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

Deployment Options@fmc_sea An Introduction to Microservices with the Serverless Framework �42

Local AWS Keys(2 options)

Using the Serverless Dashboard

Using Serverless CI/CD

Page 43: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

Local AWS Keys@fmc_sea An Introduction to Microservices with the Serverless Framework �43

Page 44: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

AWS Keys &

Serverless Safeguards

@fmc_sea An Introduction to Microservices with the Serverless Framework �44

Page 45: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

AWS Keys &

Serverless Safeguards

@fmc_sea An Introduction to Microservices with the Serverless Framework �45

Page 46: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

AWS Keys &

Serverless Safeguards

@fmc_sea An Introduction to Microservices with the Serverless Framework �46

Page 47: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �47

Deploying with Local Keys

Page 48: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

Deploying via the Serverless

Dashboard

@fmc_sea An Introduction to Microservices with the Serverless Framework �48

Page 49: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

Deploying via the Serverless

Dashboard

@fmc_sea An Introduction to Microservices with the Serverless Framework �49

Page 50: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

Deploying via the Serverless

Dashboard

@fmc_sea An Introduction to Microservices with the Serverless Framework �50

Page 51: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �51

Deploying via the Serverless Dashboard

Page 52: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

Deploying with Serverless CI/CD@fmc_sea An Introduction to Microservices with the Serverless Framework �52

Page 53: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

What are we doing?

@fmc_sea An Introduction to Microservices with the Serverless Framework �53

Page 54: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �54

DEMO TIME!1. Review app/org values2. Create/add an IAM role3. Create Profiles and

Safeguards4. Deploy a `dev` and

`prod` service5. Add API Endpoints to

our frontend

Page 55: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

Just in case…

@fmc_sea An Introduction to Microservices with the Serverless Framework �55

The demo went great Why did I do a live demo?

Page 56: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �56

Page 57: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �57

Page 58: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �58

Page 59: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �59

Page 60: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �60

Page 61: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �61

Page 62: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �62

Page 63: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �63

Page 64: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �64

Page 65: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �65

Page 66: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �66

Page 67: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �67

Debug

Page 68: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �68

Running Our Frontend

Page 69: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �69

DEMO TIME!

1. Run our frontend2. Try to vote3. Try to vote again!

Page 70: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �70

Monitoring

Page 71: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �71

DEMO TIME!1. Explore function logs2. Review specific invocations

Page 72: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

Develop@fmc_sea An Introduction to Microservices with the Serverless Framework �72

Page 73: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

New Requirements:@fmc_sea An Introduction to Microservices with the Serverless Framework �73

Users may vote every five minutes

Page 74: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

Let’s “Build” that@fmc_sea An Introduction to Microservices with the Serverless Framework �74

DEMO TIME!

Page 75: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �75

DEMO TIME!

Deploy to `dev`

Page 76: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �76

How would we get this to prod?

Page 77: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �77

Reality is more complicated…

https://serverless.com/learn/guides/cicd/

Page 78: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �78

Deploying Our Frontend

BONUS DEMO TIME?

Page 79: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �79

We eat our own dog food

Page 80: An Introduction to Microservices with the Serverless Framework · @fmc_sea An Introduction to Microservices with the Serverless Framework 28 serverless.yml 1. Creates Lambda Functions

@fmc_sea An Introduction to Microservices with the Serverless Framework �80

Thank you!Office Hours: 9am tomorrow - Room 212

Unofficial Office Hours: Right nowBy appointment - (DM me)

@fmc_sea