Wilson Mar bio photo

Wilson Mar

Hello!

Calendar YouTube Github

LinkedIn

Invisible ubiquitious server clouds across the land

US (English)   Norsk (Norwegian)   Español (Spanish)   Français (French)   Deutsch (German)   Italiano   Português   Estonian   اَلْعَرَبِيَّةُ (Egypt Arabic)   Napali   中文 (简体) Chinese (Simplified)   日本語 Japanese   한국어 Korean

Overview

This describes the ecosystem around the “Serverless” computing concept to build applications as a collection of microservices that run in response to events, auto-scaled in a cloud.

This article is a pre-requisite to my tutorial on creating a new Amazon Lambda serverless app running in the Amazon cloud.

A sentiment about physical servers is reflected in the wi-fi password used by attendees of #ServelessConf:
serverless hateservers-452x183-70kb

Serverless = FaaS

“Serverless” refer to an architectural style called FaaS (Function as a Service) where software program code are independently deployed and run on a cloud system for “zero system administration” by the developer.

This is also called an “event-driven system”.

For those who want to run a lean shop, it’s a fast, easy, low-cost route to get apps in production without worry about scalability. Unlike renting a machine (as in EC2) which accrue charges even when idle, charges for Serverless functions accrue only when individual requests are invoked.

The developer simply uploads the source code, then leave it to the cloud provider to take care of security, monitoring, disk space management, log management, scaling, redundancy, backup, crash reporting, etc..

Mike Roberts at http://martinfowler.com/articles/serverless.html wrote “Depending on the circumstances, such systems can significantly reduce operational cost and complexity at a cost of vendor dependencies and (at the moment) immaturity of supporting services.”

PROTIP: It’s still up to developers to do testing and performance measuring and tuning. Use of multi-tenancy makes for response-time variation. So do sythentic transactions outside the cloud vendor to monitor user experience, and to keep your app in cache to avoid process start-up after sleeping.

“Serverless is on the relentless historical trend toward industrialization” – @simonwardley

FaaS Providers - Pricing

Free tiers bring down costs, as shown by Peter Sbarski’s Serverless Calculator at serverlesscalc.com
serverless-costcomp-648x490-13259

Google App Engine in 2008 was arguably the first.

Concerns (the Downsides)

Database idle costs money!

“You never pay for idle” Austen says in an interview with CloudAcademy Introduction to the Serverless Paradigm [23:50]

WRONG! While Lambda does not incur charges while idle, DynamoDB,, which Amazon touts as the default database, do incur charges for data stored (even though no data is read or written to it).

PROTIP: On AWS use SimpleDB instead of DynamoDB for true no-cost idle.

Control

PROTIP: The other side of freedom from server hassles is that developers also give away control.

Having one’s data in another company’s cloud requires trust in that company’s ability to keep data secure, redundant, and pricing fair.

PROTIP: Going with a particular vendor’s API means that you need to keep up with changes in APIs that can occur frequently, even though they may not apply to your own operation.

There is the danger of vendor lock-in.

But frameworks have emerged to allieviate that:

Serverless usage in the wild

When a $9 million monolithic app built for the Australian Census failed, two students over two-weeks created a scalable system using $500 of compute time (including load testing).

Compelling Science Fiction.com uses Simple Email to read emails and sends it to S3. Lambda emails notifications. Stories are saved in DynamoDB. Python pulls data.

Eric Jonas does hyperperameter sweeps, Monte Carlo simulations. Spark requires dedicated servers and is not very elastic. map of map reduce.

His Simultaneous “Big Lambda” talk

http://www.emitconference.com Emit Conference for “event-driven architectures” August 17th, 2017 in San Francisco has people who’ve done it:

  • Rob Gruhl Senior Manager of Serverless Platform Team at Nordstrom
  • Bobby Calderwood Technology Fellow at Capital One
  • Madhuri Yechuri Founder of Elotl
  • Dave Copeland Director of Engineering at Stitch Fix
  • Shawn Burke Staff Software Engineer at Uber

  • Ajay Nair Head of Product (AWS Lambda) at Amazon Web Services
  • Jason Polites Product Manager for Google Cloud Functions
  • Chris Anderson Senior Program Manager for Azure Functions
  • Cornelia Davis Senior Director of Technology at Pivotal Software

  • Anne Thomas VP & Distinguished Analyst at Gartner, Inc.
  • Matthew Lancaster Global Lead, Lightweight Architectures at Accenture

An audio Q&A with The CTO of New York Times, Nick Rockwell, who migrated the paper to using React and GraphQL Apollo that reads off of a Kafka pipeline on Google Cloud and Big Query.

Services

FunctionalityTypeAWS service3rd-party
ComputeFunctionsAWS LambdaIron.io
SecurityAuthenticationIAM, Cognito federationAuth0, AuthRocket, Okta
Logging, Monitoring, Anomaly AnalyticsCloudWatch, CloudTrail, X-Ray tracingHoneycomb, Datadog
AnalyticsVisualizationQuickSight-
StreamingstreamsKinesis-
MessagesSQS, SNSTwilio
PersistenceFilesS3-
Time SeriesTimestreamInfluxDB, etc.
NoSQLDynamoDBRedis
SQLAuroraMySQL, PostgeSQL
Data warehouseRedshift columnar Spectrum from S3Hadoop, Spark
SearchCloudSearchElasticSearch
BlockchainQuantumLedger-
Query/TransformETL, SQLGlue, Athena, EMR-
Machine Learning-SageMakerTensorflow
Image recognition-RekognitionAlgorithmia, Quandl
Payment--Stripe, Paypal
Geocoding--HERE, Loqate

Best Practices

Functions need to be Stateless (not long-running tasks)

Functions that access resources (such as PaaS databases) should be in a private cloud, which AWS calls VPC (Virtual Private Cloud).

Functions that access resources over the public internet should run the function in a subnet with a NAT’d route to the internet.

NodeJs start up faster than Java.

There are 3 execution models:

  1. Synchronous (push event-driven pipelines) via API Gateway
  2. Asynchronous (event requests) via SNS, S3
  3. Stream-based changes via DynamoDB (NoSQL) to Kinesis

CloudWatch warming triggers every 5 minutes to keep code in memory to reduce warm-up time. This is to avoid Freeze/thaw errors.

  • Limit data transformations to one per Lambda function.
  • Upgrade to latest NodeJs regularly

  • Console
  • Function Code
  • Execution Roles
  • Test Events
  • Execution Results
  • Monitoring analytics


AWS Lambda

Internally, AWS Lambda functions are run using AWS Firecracker open-source software managing lightweight VMs, to reduce startup time and memory overhead.

AWS Lex bot Lambda Blueprint provides a pre-configured patterns for building conversational interfaces : OrderFlowers, ScheduleAppointment (in Python), BookTrip (in NodeJs).

Reusable Layers in libraries (like Docker) reduce dependency size.

serverless-layers-965x569.jpg

Step functions build visual workflows using State Types in state stores.

Search/browse generic pre-defined apps from the AWS Serverless Application Repository (SAR). Configure one and deploy it.

SAM

Although people say Terraform templates are more flexible …

The AWS Serverless Application Model (SAM) at https://github.com/awslabs/serverless-application-model was announced Nov 2016 to define the building blocks of Cloud Formation templates that access Amazon API Gateway APIs, AWS Lambda functions, and Amazon DynamoDB tables needed by serverless applications.

Templates

Two AWS evangelists created pre-built templates with manual instructions, which they walked though in 30 minutes on Twitch.tv:

  1. Get an AWS IAM User with AWSCodeStarFullAccess.

    CAUTION: Installation steps in Peter Sbarski’s book suggests providing “Administrator access to all services and resources.

  2. Login the AWS Console to select region N. Virginia.
  3. In AWS CodeStar. Start a project. Node.js. create role.
  4. Choose a project template:
    • Under Application Category select Web Application.
    • Under Programming Languages select Node.js.
    • Pick “Node.JS Web Application AWS Lambda (running serverless)”.

More examples are at https://github.com/serverless/examples

serverless-aws-flow-648x416-52875.jpg

  • Route 53 : a highly available & scalable DNS service which also manages traffic flow based on different routeing types e.g., Latency Based Routing, Geo DNS, and Weighted Round Robin as well as DNS failover.

  • CloudFront CDN: Content Distribution Network.

  • S3 : a static file storage which can store petabytes of storage if you want, with 99.999999% durability.

  • API Gateway : a REST-based service which allows you to create, publish, monitor and quickly scale & secure API services.

  • Lambda : to hold and process server side code, with no charges for server time between client requests.

  • MongoDB instead of DyanmoDB : a scalable database which guarantees the same consistent speed of read and write requests.

  • SES (Simple Email Service) : Mass emailing service, like MailChimp.

PROTIP: The future of FaaS vendors isn’t the front-end but the back-end services that include API Gateways and Artificial Intelligence features such as image recognition, text sentiment analysis, natural language process (NLP), and Machine Learning.

PROTIP: The payoff for housing the back-end in a public cloud is for machine learning and AI services to be added. For example: https://github.com/aws-samples/aws-serverless-ember

serverless-aws-ember-648x379-36238

Azure Functions

Marketing information is at https://azure.microsoft.com/services/functions

  1. Create an Azure Storage account.
  2. Search for “Function App” in the Azure Marketplace.
  3. Click Create.
  4. Provide an app name that’s globally unique among all others public.

    .azurewebsites.net

  5. Create or use a Resource Group to manage your similar functions as a group.
  6. Select a Location closest to you.

    PROTIP: Include the location as a suffix in your app name.

  7. Selection of Memory Allocation can be adjusted once you figure out how much after running a few times.
  8. Create.
  9. Click Refresh or the “bell” icon to see messages related.

  10. After deployment, click the Resource Group, then the app name.
  11. Click “Webhood + API” and JavaScript language (or C#).
  12. Copy the Function URL and paste it in a browser.
  13. Click Logs to see the history tracking.
  14. Add a Parameter.

IBM Bluemix OpenWhisk

https://developer.ibm.com/openwhisk

The advantage of IBM’s hybrid-cloud approach is that one can use IBM’s proprietary Bluemix UI and then use command-line with OpenWhisk (which is open sourced).

ibm-openwhisk-arch-720x168

Google Cloud Functions

https://cloud.google.com/functions

@googlecloud

Google Firebase

Iron.io and other on-premises

Iron.io has their Gesalt Framework

Local Runs for testing

For a “test-first” approach to achieve code maturity, doing test runs locally before committing to a team branch is important.

Let’s examine the choices to emulate AWS Lambda locally:

  1. Install the “Command line tool for locally running and remotely deploying your node.js applications to Amazon Lambda.” from github.com/motdotla/node-lambda

    npm install -g node-lambda

  2. Describe tests in a JSON file.

Serverless Coding Frameworks

  • Shep (bustle.com)
  • ClaudiaJs
  • Apex provides a shim to support Go and languages not yet supported by Lambda,
  • Sparta for AWS Lambda, as a Golang app, is baked into deliverable binary (unlike Node).

    • https://gospart.io
    • https://github.com/mweagle/Sparta
  • Gordon is written in Python

  • Zappa is written in Python for Flask apps running only on AWS Lambda
  • Google Cloud Functions for Firebase
  • The Serverless Framework

Apex

http://apex.run/

Open sourced on GitHub/apex/apex

See https://github.com/apex/apex/blob/master/docs/infra.md

Currently the following variables are exposed to Terraform:

  • aws_region the AWS region name such as “us-west-2”
  • apex_environment the environment name such as “prod” or “stage”
  • apex_function_role the Lambda role ARN
  • apex_function_arns A map of all lambda functions
  • apex_function_names A map of all the names of the lambda functions

ClaudiaJs

https://www.manning.com/books/serverless-applications-with-nodejs Serverless Applications with Node.js
Using AWS Lambda and Claudia.js by Slobodan Stojanović and Aleksandar Simović

Serverless the company

The name “serverless” has been co-opted by enprepreneur Austen Collins @austencollins who built the Serverless company around its open-source Serverless Framework on GitHub, a combination of command-line utilities and conventions.

His initial Serverless presentation at AWS:Invent 2015

Hacker News announced it in 2015 when the product was first called JAWS.

The company’s social media:

Install Serverless Framework

PROSTIP: The Serverless Framework is a command-line tool, providing scaffolding, workflow automation and best practices for developing and deploying your serverless architecture.

Below is an annotated, expanded verson of this:

  1. Install Node.js as a pre-requisite since the framework is written in Node.js.

  2. Install the serverless-framework

    
    npm install -g serverless
    
  3. Verify version:

    serverless -v
    sls -v
    

    1.42.3 NOTE: Serverless was in Beta version 0.5.6 as of June 2016, with v1.0 announced 24 June 2016.

    Update Serverless

    PROTIP: I subscribed to get notifications of changes, and I can see a lot of refactoring is happening very quickly, so I suggest that you update frequently.

    
    npm update -g serverless
    

    Nothing returns if you’re up-to-date.

    The command notes whether you should npm install -g npm

    Look around

  4. Get summary of commands using the abbreviated command:

    sls

    The response (version 1.28.0) you’ll have to extend the terminal screen to avoid line wrapping:

    Commands
           * You can run commands with "serverless" or the shortcut "sls"
           * Pass "--verbose" to this command to get in-depth plugin info
           * Pass "--no-color" to disable CLI colors
           * Pass "--help" after any <command> for contextual help
     
    Framework
           * Documentation: https://serverless.com/framework/docs/
     
    config ........................ Configure Serverless
    config credentials ............ Configures a new provider profile for the Serverless Framework
    create ........................ Create new Serverless service
    install ....................... Install a Serverless service from GitHub or a plugin from the Serverless registry
    package ....................... Packages a Serverless service
    deploy ........................ Deploy a Serverless service
    deploy function ............... Deploy a single function from the service
    deploy list ................... List deployed version of your Serverless Service
    deploy list functions ......... List all the deployed functions and their versions
    invoke ........................ Invoke a deployed function
    invoke local .................. Invoke function locally
    info .......................... Display information about the service
    logs .......................... Output the logs of a deployed function
    metrics ....................... Show metrics for a specific function
    print ......................... Print your compiled and resolved config file
    remove ........................ Remove Serverless service and all resources
    rollback ...................... Rollback the Serverless service to a specific deployment
    rollback function ............. Rollback the function to the previous version
    slstats ....................... Enable or disable stats
    plugin ........................ Plugin management for Serverless
    plugin install ................ Install and add a plugin to your service
    plugin uninstall .............. Uninstall and remove a plugin from your service
    plugin list ................... Lists all available plugins
    plugin search ................. Search for plugins
     
    Plugins
    AwsConfigCredentials, Config, Create, Deploy, Emit, Info, Install, Invoke, Login, Logout, Logs, Metrics, Package, Plugin, PluginInstall, PluginList, PluginSearch, PluginUninstall, Print, Remove, Rollback, Run, SlStats
    
  5. Verify where the executable is located:

    command -v serverless
    

    The response (with your account rather than “wilsonmar”):

    /Users/wilsonmar/.nvm/versions/node/v9.11.1/bin/serverless
    
  6. Get the location of files

    find / -name serverless 2>/dev/null
    

    The response (with your account rather than “wilsonmar”):

    /usr/local/bin/serverless
    

    In the serverless framework folder

  7. Navigate to framework folders and files:

    
    cd /usr/local/lib/node_modules/serverless
    ls -al
    

    The response (with your account rather than “wilsonmar”):

    CHANGELOG.md      README.md         lib               package-lock.json scripts
    LICENSE.txt       bin               node_modules      package.json
    
  8. View the README.md file using a Markdown reader:

    
    atom README.md
    

    Instead of the Atom text editor (from GitHub), alt-click on the file to select Markdown Preview.

    The file contains a list of projects, plugins, and consultants who provide services.

    https://serverless.com/framework

    Serverless is open-sourced under the MIT license and actively maintained by a full-time, venture-backed team.

    Files of Serverless Framework

README.md, CONTRIBUTING.md, LICENSE.txt are standard GitHub files.

.eslintrc.js contains rules for how lint programs identify issues with code formatting.

.jsbeautifyrc contains settings for JavaScript code beautify program.

.jscsrc

.npmignore defines files and folders for NPM to ignore.

.travis.yml is used by the Travis task runner.

Dockerfile defines how to load the server in Docker.

docker-compose.yml

Folders

.idea contains settings for use by the IDEA IDE.

.github

bin

coverage

lib contains library files

node_modules are populated

scripts

tests

_meta Plugins

The heart of Serverless are its Plugins, which makes it extensible.

Plugins can be written in python, node.js, java, scala or C#.

Plugins need to be installed for each project that uses each.

  1. List plugins come installed with the Framework :

    ls _meta/

  2. Navigate your active directory to the root of your project.
  3. Plugins are downloaded from GitHub by npm, so to install a plug-in, for example:

    npm install --save-dev serverless-webpack-plugin webpack
    

    See asprouse/serverless-webpack-plugin - Use Webpack to optimize your Serverless Node.js Functions.

    In serverless.yml, this section:

    plugins:
      - custom-serverless-plugin
    custom:
      custom-config-category:
        configBucket: configBucketName
    

PROTIP: Functions of the same component can use the lib folder to share common code.

Get Permissions

aws-lambda-node-js-programming

  • http://stackoverflow.com/questions/37779324/how-to-troubleshoot-serverless-iam-permissions

Serverless Command-line

Lambda functions can be defined from a command-line using the Serverless framework.

AWS May 2016 Webinar Series - Deep Dive on Serverless Web Applications

http://abalone0204.github.io/2016/05/22/serverless-simple-crud/

Keeping Secrets

BLAH: AWS Lambda doesn’t allow setting and reference to operating system environment variables.

Lambda functions have a deploy.env file in combination with the --configFile flag to set values which will be prepended to your compiled Lambda function as process.env environment variables before it gets uploaded to S3.

Secrets such as DB connection string or encryption key are secure values that should not be checked into version control (specified in a .gitignore file).

Sample Hello Project

  1. Create a folder to hold serverless projects. For example, you may choose another:

    
    mkdir ~/gits/sls
    cd ~/gits/sls
    

    Serverless Platform Online

  2. Open the cloud dashboard:

    serverless login
    

    This opens a browser to:

    https://dashboard.serverless.com/?cli=true

  3. Log in using your GitHub or Google credentials.

    • App visualization - View the services you’ve deployed with the Serverless Framework. inspect config, monitor deployment activity and more.

    • Collaborate - Share your Serverless Framework projects with teammates.

    • Hosted event gateway - Your account includes a free Event Gateway. Create event-driven APIs, workflows and integrations with any systems you’d like to integrate with serverless functions-as-a-service.

  4. Click on the + App button An app name is suggested by concatenating your account and app plus the “slsgateway.com”, such as:

    myname-myapp-dev.slsgateway.com

  5. Edit the name and click SAVE.
  6. Return to the Terminal to see:

    Serverless: You are now logged in

    New local

  7. Create a serverless.yml file using a template for a nodejs app running on the aws cloud provider:

    sls create -t aws-nodejs --path aws-nodejs-hello
    

    -t is a contraction of command parameter --templatef

    Serverless: Generating boilerplate...
     _______                             __
    |   _   .-----.----.--.--.-----.----|  .-----.-----.-----.
    |   |___|  -__|   _|  |  |  -__|   _|  |  -__|__ --|__ --|
    |____   |_____|__|  \___/|_____|__| |__|_____|_____|_____|
    |   |   |             The Serverless Application Framework
    |       |                           serverless.com, v1.28.0
     -------'
     
    Serverless: Successfully generated boilerplate for template: "aws-nodejs"
    Serverless: NOTE: Please update the "service" property in serverless.yml with your service name
    
  8. The previous command (like Git clone) creates a folder, so

    cd aws-nodejs-hello

    Two files are created in the folder:

    • handler.js which is the coding for the Lambda function.
    • serverless.yml defines the configuration.

  9. Edit file serverless.yml to add permissions to use Amazon’s SES (Simple Email Service):

    service: aws-nodejs-hello
    app: myapp-dev
    tenant: wilsonmar
     
    provider:
      name: aws
      runtime: nodejs6.10
      stage: prod
      memorySize: 256
      environment:
     ACCESS_KEY_VALUE: 123-access-key-value-456-abc
      iamRoleStatements:
             - Effect: "Allow"
     Action:
       - "ses:*"
     Resource:
       - "*"
     
    functions:
    hello:
       handler: handler.hello
       events:
          - http:
              path: hello
              mention: get
    

    Functions

    The name of the function is defined (“hello”).

    Handlers

    PROTIP: Handlers can compress or transform objects while being uploaded to Amazon S3.

    Path

    When using the AWS API Gateway,

    path: hello/{id}

    Events

    Another http example:

    method: post
    cors: true
    
  10. The other lines beginning with # are comments that can be deleted.

    Deploy function

  11. Deploy the app (-verbosely):

    sls deploy -v

    PROTIP: Be mindful of this message: Serverless: WARNING: Missing “tenant” and “app” properties in serverless.yml. Without these properties, you can not publish the service to the Serverless Platform.

    The response is a lot of lines, including something like this:

    Service Information
    service: aws-nodejs-hello
    stage: dev
    region: us-east-1
    stack: aws-nodejs-hello-dev
    api keys:
      None
    endpoints:
      None
    functions:
      hello: aws-nodejs-hello-dev-hello
     
    *Stack Outputs*
    HelloLambdaFunctionQualifiedArn: arn:aws:lambda:us-east-1:903265058630:function:aws-nodejs-hello-dev-hello:1
    ServerlessDeploymentBucketName: aws-nodejs-hello-dev-serverlessdeploymentbucket-wafuwil8ilvx
    

    You’ll get a “congrats on your first deploy” email if it is:

    Congrats on your very first deployment on the Serverless Framework! Here's to many more. 🎉 
     
    Use these resources from our community to help you build apps faster:
    <a target="_blank" href="https://github.com/serverless/examples"Serverless examples repository</a> for a list of ready-to-go, deployable serverless services
    Serverless plug-ins to extend base functionality
    David
    your friendly neighborhood developer
    @ Serverless
    

    Functions deployed

  12. List services:

    sls deploy list

    An example response:

    Serverless: Listing deployments:
    Serverless: -------------
    Serverless: Timestamp: 1531622582547
    Serverless: Datetime: 2018-07-15T02:43:02.547Z
    Serverless: Files:
    Serverless: - aws-nodejs-hello.zip
    Serverless: - compiled-cloudformation-template.json
    

    Show Function Logs

  13. Open up a separate tab in your console and fetch (stream) all logs for your Function:

    sls logs -f hello -t

    Sample response:

    START RequestId: 9cb599bd-87d9-11e8-a1ac-77e94c02a7c3 Version: $LATEST
    END RequestId: 9cb599bd-87d9-11e8-a1ac-77e94c02a7c3
    REPORT RequestId: 9cb599bd-87d9-11e8-a1ac-77e94c02a7c3  Duration: 0.55 ms Billed Duration: 100 ms   Memory Size: 1024 MB  Max Memory Used: 21 MB  
    

    Invoke function

  14. Invoke:

    sls invoke -f hello --log

    Response:

    {
     "statusCode": 200,
     "body": "{\"message\":\"Go Serverless v1.0! Your function executed successfully!\",\"input\":{}}"
    }
    --------------------------------------------------------------------
    START RequestId: 5df3ecdc-87d9-11e8-8ed7-c3ee16fc727b Version: $LATEST
    END RequestId: 5df3ecdc-87d9-11e8-8ed7-c3ee16fc727b
    REPORT RequestId: 5df3ecdc-87d9-11e8-8ed7-c3ee16fc727b  Duration: 2.16 ms Billed Duration: 100 ms   Memory Size: 1024 MB  Max Memory Used: 20 MB  
    

    PROTIP: Pay attention to “Max Memory Used:”.

    Remove all functions

  15. Remove all Functions, Events and Resources of the service, so charges are no longer accrued:

    sls remove

    Example response:

    Serverless: Getting all objects in S3 bucket...
    Serverless: Removing objects in S3 bucket...
    Serverless: Removing Stack...
    Serverless: Checking Stack removal progress...
    .......
    Serverless: Stack removal finished...
    Serverless: Successfully archived your service on the Serverless Platform
    

Implement a sample project

Richard Moot (@wootmoot), Developer Evangelist @Square, wrote Super Simple Serverless eCommerce. Richard stores files in Gists, which will work as long as the files don’t ever change.

  1. In the Amazon console, use your AWS admin account within IAM, create an account with permissions to read and write S3.
  2. In S3, create a bucket to get a UNIQUE_ID.
  3. Create a product image and put in within your S3 bucket.
  4. Edit the sample product.html file

    • Replace UNIQUE_ID with the ID of the app in AWS.
    • Replace “/0.jpeg” with the URI to the product image at: &LT;img class=’productImage’ src=”/0.jpeg” />
    • Replace “Square 1 Sticker” with your own product’s name.

    My changes are stored in GitHub.

  5. Edit the sample index.htm
  6. Save a favicon.ico graphic file in the root.
  7. Save the main.css and normalize.css, plugin.js, main.js
  8. Save sample handler.js
  9. enable “Static website hosting” in Properties to have a publicly accessible site.
  10. Edit the sample serverless.yml

  11. Replace YOUR_LOCATION_ID in serverless.yml

Richard also created Serverless Instant Checkout Links with Square

Alternately, choose another pre-defined app from this list:

  • https://zanon.io/posts/building-serverless-websites-on-aws-tutorial using the Serverless Framework 1.1, dated JAN 31, 2016 by Fred Eady.

  • serverless/serverless-graphql - Official Serverless boilerplate to kick start your project

  • serverless/serverless-starter - A simple boilerplate for new projects with a few architectural options

  • serverless/serverless-graphql-blog - A blog boilerplate that leverages GraphQL in front of DynamoDB to offer a minimal REST API featuring only 1 endpoint

  • laardee/serverless-authentication-boilerplate - A generic authentication boilerplate for Serverless framework

  • sc5/sc5-serverless-boilerplate - A boilerplate for test driven development of REST endpoints

  • [microapps/MoonMail] (https://github.com/microapps/MoonMail) - Build your own email marketing infrastructure using Lambda + SES from http://microapps.com/

  1. Create a folder.

  2. Load a sample project from the list above:

    sls project install serverless-graphql

    The response:

    _______                             __
    |   _   .-----.----.--.--.-----.----|  .-----.-----.-----.
    |   |___|  -__|   _|  |  |  -__|   _|  |  -__|__ --|__ --|
    |____   |_____|__|  \___/|_____|__| |__|_____|_____|_____|
    |   |   |             The Serverless Application Framework
    |       |                           serverless.com, v0.5.6
    `-------'
     
    Serverless: Installing Serverless Project "serverless-graphql"...  
    Serverless: Downloading project and installing dependencies...  
    Serverless: Initializing Serverless Project...  
    Serverless: Enter a new stage name for this project:  (dev)
    
  3. Press Enter to accept the default

  4. Keyboard up and down to select:

    Serverless: For the "dev" stage, do you want to use an existing Amazon Web Services profile or create a new one?
      > Existing Profile
     Create A New Profile
    Serverless: Select a profile for your project:
     default
      > GitHubPublisher1
     me_dev
     serverless-graphql_dev
    Serverless: Creating stage "dev"...  
    Serverless: Select a new region for your stage:
     us-east-1
      > us-west-2
     eu-west-1
     eu-central-1
     ap-northeast-1
    Serverless: Creating region "us-west-2" in stage "dev"...  
    Serverless: Deploying resources to stage "dev" in region "us-west-2" via Cloudformation (~3 minutes)...
    

Structure of Folders and Files

PROTIP: The serverless framework save developers’ time by standardizing the structure of folders and files.

s-project.json       // Project file (JSON or YAML)
s-resources-cf.json  // CloudFormation template
s-templates.json     // Config templates and variables
admin.env            // AWS Profiles (gitignored)
_meta                // Metadata (gitignored)
function1            // A custom function
  |__event.json
  |__handler.js
  |__s-function.json
   

This set of project file is what developers work with.

The serverless framework programming which read and process project files is written in Node JavaScript.

The s-project.json lists plugins:

{
  "name": "notes",
  "custom": {},
  "plugins": [
    "serverless-client-s3"
  ]
}
   

A key differentiator with the Serverless Framework is that infrastructure specs are defined as code in one project. s-resources-cf.json is a AWS CloudFormation template specifying security (IAM) roles, SNS email topics, DynamoDB tables, Queues, ARNs.

Components are deployed per stage (dev, prod, etc.), allowing developers to easily deploy separate prod, test and dev environments.

Within the folder for each function is a s-function.json file containing metadata such as plugins installed with the project.

When the framework is created for a project, a .gitignore file is created with other files to specify private and temporary work files that should not be publicly uploaded to GitHub.

Project metadata in file _meta outputs and user variables used in function configurations. But due to the sensitive nature of these variables, the file needs to be gitignore’d by default. A workaround is to use the Serverless Meta Sync plugin which stores project metadata in S3.

admin.env

Production limits & prep

BLAH: The 64-character name limit.

By default, AWS Lambda limits the total concurrent executions across all functions within a given region to 100. This is a safety limit to protect users from costs due to potential runaway or recursive functions during initial development and testing. To increase this limit above the default, request a limit increase for concurrent executions here.

BLAH: Can’t search for logs across regions.

Troubleshooting

lumigo.io offers their lumigo-cli to troubleshoot Serverless apps.

Libraries

React Serverless app running in Azure?

https://github.com/99xt/serverless-dependency-install Serverless plugin to manage dependencies

with architectural best practices using NPM, Angular, Gulp.

https://github.com/99xt/serverless-dynamodb-local

Rock Stars

Yan Cui (@@theburningmonktheburningmonk.com from London) goes deeper than anyone else on Serverless.

Adnan Rahić (@adnanrahic, bookvar.co founder) $50 Packt Serverless JavaScript by Example [Video] December, 2017

Phillip Muens (@pmmuens, github.com/pmuens) from Germany

Matthew Fuller

Jake Knowles

  • AWS Lambda: Serverless Microservices Guide with Simple Instructions

John McKim @johncmckim blogs on Medium:

CNCF

Andru Estes

Building Serverless Web Applications with React & AWS Amplify video course by Nader Dabit.

Develop a Serverless Backend using Node.js on AWS Lambda by Nik Graf

Pluralsight video tutorials

Azure:

Instead of giving you an emulator for local development, Azure give you the runtime. The whole box. The Azure Functions Core Tools is the same runtime that Azure uses in the cloud. Because you get the whole runtime, you can build any kind of function locally. Blob and Azure Message Queue Triggers as well. Not just HTTP triggers.

Open an Azure Functions project in VS Code, and you are prompted to setup an extension to run and debug functions, put a breakpoint in the gutter and hit the green button in the debug panel.

Google:

Random Resources

Serverless Instant Checkout Links with Square – Square Corner Blog

A crash course on Serverless APIs with Express and MongoDB

how-to-write-your-first-aws-lambda-function

Taking Serverless and AI to the Next Level February 27, 2018 by Yaron Haviv, Tomer Rosenthal

Building Serverless Application Pipelines March 6, 2018 https://www.cncf.io/wp-content/uploads/2018/03/cncf-serverless-webinar.pdf by Sebastien Goasguen

Lists:

https://github.com/anaibol/awesome-serverless

https://techbeacon.com/50-best-starter-kits-resources-building-serverless-apps

Salesforce integration

https://apex.run

AWS IDE

Zip fileslocally and upload to Lambda

More on Clouds

This is one of a series on Cloud computing