$30 off During Our Annual Pro Sale. View Details »

Serverless VS SAM

Serverless VS SAM

Paolo Ferretti

September 30, 2020
Tweet

More Decks by Paolo Ferretti

Other Decks in Programming

Transcript

  1. Not Abraham Lincoln “Give me six hours to chop down

    a tree and I will spend the first four sharpening the axe”
  2. 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
  3. 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)
  4. 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.
  5. 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
  6. 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
  7. 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
  8. 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
  9. 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
  10. 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/)
  11. 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