Slide 1

Slide 1 text

Serverless vs SAM Paolo Ferretti - Road to Coderful

Slide 2

Slide 2 text

Paolo Ferretti Senior Backend Developer @iGeniusAI AWS Certified Solutions Architect - Associate @paoferretti

Slide 3

Slide 3 text

Not Abraham Lincoln “Give me six hours to chop down a tree and I will spend the first four sharpening the axe”

Slide 4

Slide 4 text

Warning: opinions ahead!

Slide 5

Slide 5 text

Agenda Serverless Framework AWS SAM Installation Community Setup Base project structure Deploy Removal Base lambda definition Resurces definition Composition with other stacks Capabilities Tests Documentation Final result

Slide 6

Slide 6 text

Installation curl -o- -L https://slss.io/install | bash choco install serverless Serverless framework AWS SAM MacOS/Linux MacOS/Linux Windows Windows brew tap aws/tap brew install aws-sam-cli Windows Installer (MSI)

Slide 7

Slide 7 text

9 9 Installation score Serverless framework AWS SAM

Slide 8

Slide 8 text

Community Google Trends Serverless Framework AWS SAM

Slide 9

Slide 9 text

Community Stackoverflow | GitHub

Slide 10

Slide 10 text

10 7 Community score Serverless framework AWS SAM

Slide 11

Slide 11 text

Setup Serverless ⟩ serverless Serverless: No project detected. Do you want to create a new one? Yes Serverless: What do you want to make? AWS Node.js ❯ AWS Python Other Serverless: What do you want to call this project? Project successfully created in 'MyServerlessProject' folder. You can monitor, troubleshoot, and test your new service with a free Serverless account. Serverless: Would you like to enable this? (Y/n) You can run the “serverless” command again if you change your mind later.

Slide 12

Slide 12 text

Setup AWS SAM ⟩ sam init Which template source would you like to use? 1 - AWS Quick Start Templates 2 - Custom Template Location Choice: 1 Which runtime would you like to use? 1 - nodejs12.x 2 - python3.8 3 - ruby2.7 4 - go1.x 5 - java11 6 - dotnetcore3.1 7 - nodejs10.x 8 - python3.7 9 - python3.6 10 - python2.7 11 - ruby2.5 12 - java8.al2 13 - java8 14 - dotnetcore2.1 Runtime: 2 Project name [sam-app]: my-sam-app Cloning app templates from https://github.com/awslabs/aws-sam-cli-app-templates.git AWS quick start application templates: 1 - Hello World Example 2 - EventBridge Hello World 3 - EventBridge App from scratch (100+ Event Schemas) 4 - Step Functions Sample App (Stock Trader) 5 - Elastic File System Sample App Template selection: 1 ----------------------- Generating application: ----------------------- Name: my-sam-app Runtime: python3.8 Dependency Manager: pip Application Template: hello-world Output Directory: . Next steps can be found in the README file at ./my-sam-app/README.md

Slide 13

Slide 13 text

8 10 Setup score Serverless framework AWS SAM

Slide 14

Slide 14 text

Base project structure Serverless Framework

Slide 15

Slide 15 text

Base project structure AWS SAM

Slide 16

Slide 16 text

7 10 Base project structure score Serverless framework AWS SAM

Slide 17

Slide 17 text

Deploy Serverless framework

Slide 18

Slide 18 text

Deploy AWS SAM

Slide 19

Slide 19 text

10 10 Deploy score Serverless framework AWS SAM

Slide 20

Slide 20 text

Removal Serverless framework

Slide 21

Slide 21 text

Removal AWS SAM Only using Cloudformation We must empty an S3 bucket

Slide 22

Slide 22 text

10 5 Removal score Serverless framework AWS SAM

Slide 23

Slide 23 text

Base lambda definition Serverless framework AWS SAM Resources: HelloWorldFunction: Type: AWSjkServerlessjkFunction Properties: CodeUri: hello_world/ Handler: app.lambda_handler Runtime: python3.8 Events: HelloWorld: Type: Api Properties: Path: /hello Method: get provider: name: aws runtime: python3.8 functions: hello-world: handler: hello_world.lambda_handler events: - httpApi: method: GET path: /hello_world

Slide 24

Slide 24 text

10 10 Base lambda definition score Serverless framework AWS SAM

Slide 25

Slide 25 text

Both tools use CloudFormation syntax to define resources Resources definition

Slide 26

Slide 26 text

8 10 Resources definition score Serverless framework AWS SAM

Slide 27

Slide 27 text

Composition with other stacks Serverless framework AWS SAM • Parameters support • Possibility to reference resources from external stacks • Parameters support • Possibility to reference resources from external stacks

Slide 28

Slide 28 text

10 10 Composition with other stacks score Serverless framework AWS SAM

Slide 29

Slide 29 text

Capabilities Serverless framework AWS SAM • Plugins ecosystem (https:// www.serverless.com/plugins/) • Multi-cloud support • Can load remote logs • Native integration with step functions • Good integration with AWS services • Can load remote logs

Slide 30

Slide 30 text

8 7 Capabilities score Serverless framework AWS SAM

Slide 31

Slide 31 text

Tests Serverless framework AWS SAM • Lack of default test structure • Run lambda in local environment • Invoke remote lambda • Default test structure • Run lambda in local Docker container • Run a local version of API Gateway • Event payload generator

Slide 32

Slide 32 text

6 10 Tests score Serverless framework AWS SAM

Slide 33

Slide 33 text

Documentation Serverless framework AWS SAM • Comprehensive documentation (https:// www.serverless.com/framework/docs/) • A lot of examples (https:// www.serverless.com/examples/) • Dozens of tutorials (https:// www.serverless.com/blog/category/guides- and-tutorials/) • Official blog (https://www.serverless.com/ blog/) • Comprehensive documentation (https:// docs.aws.amazon.com/serverless- application-model/index.html) • Not many examples • Dedicated tag on AWS Compute blog (https://aws.amazon.com/blogs/compute/ tag/aws-sam-cli/)

Slide 34

Slide 34 text

10 8 Documentation score Serverless framework AWS SAM

Slide 35

Slide 35 text

Final results Serverless Framework AWS SAM Installation 9 9 Community 10 7 Setup 8 10 Base project structure 7 10 Deploy 10 10 Removal 10 5 Base lambda definition 10 10 Resurces definition 8 10 Composition with other stacks 10 10 Capabilities 8 7 Tests 6 10 Documentation 10 8 Final result 106 106

Slide 36

Slide 36 text

No content