KEMBAR78
Local Lambda Debugging | PPTX
Local Lambda Development and Debugging
Matt Billock
matt@backand.com
Agenda:
● AWS Lambda Overview
● Debugging AWS Lambda
● Building a local test harness
● Deployment with Backand CLI
● Quick overview of Backand
AWS Lambda
● Created in 2014, launched at
re:Invent
● Kicked off "serverless" (caveat)
● Function-as-a-Service
○Deploy code, not applications
Creating A Lambda Function
● Supports Node.JS, Python, C#, and
Java
○ Can call to server functionality (Linux)
● Code deployment options
○ Uploading as a ZIP file
○ Uploading from S3
○ Editing in in-browser editor
Creating A Lambda Function
Demo
Calling AWS Lambda Functions
● Event-based triggers
○ Also On-Demand
● Event Sources
○ AWS Services (S3, DynamoDB, others)
○ API Gateway
○ AWS SDK
Debugging Lambda Functions
● Cloudwatch Integration
○ Provides call record
● console.log()
○ Sends message to Cloudwatch
● … and that's it
Lambda Execution Environment
● Details kept proprietary by Amazon
● Based on Amazon Machine Instance
● Dynamically provisioned (hot vs cold)
● Temporary storage (/tmp, 500 MB)
○ NOT guaranteed to persist
Debugging Lambda Locally
● Need to mimic input format
● Need to mimic output format
○ Transformations in API Gateway
● Need a test harness
Creating a Test Harness
● Function Prototype
● Including Handler
● Mimicking Lambda Invocation
○ Parameters in event object
○ Handlers in the context object
Creating a Test Harness
● Calling a Lambda function, continued:
● Provide handlers in context argument
Test Harness Notes
● Callback mechanism provided by Lambda
○ Only supported by Node.JS actions
● Using callbacks in context parameter
○ Not officially supported
● Not a perfect substitute
○ Calls the function, but not from the same
environment
Improving Iteration Speed
● Per-line output
● Immediate feedback
● Breakpoints and other local
debugging tools
● Unit and Integration tests
Deploying Your Code
● Zip-file from S3, or manual upload
○ NOTE: zip only the source code,
not the parent folder!
● Testing upload
● Publishing
● Complex, non-intuitive
Using Backand's CLI Tool
● Backand On-Demand Node.JS
Lambda actions
● Backand CLI abstracts away
deployment
● npm install -g backand
● Requires registering with Backand
Deploying Lambda Code
● Initializing an action- backand action init
○ Arguments available in docs.backand.com
● Copy your Node.JS code into created
directory
● Deploy - backand action deploy
○ Arguments available in docs.backand.com
Calling Your Lambda
● Authentication
○ can be anonymous
○ api.backand.com/1/token
○ See docs
● cURL
curl -H "<auth header>" "https://api.backand.com/1/objects/action/<object>?name=<name>"
● JavaScript (with Backand SDK)
backand.object.action.get(...)
What is Backand?
● Serverless app platform
● Manages your app's database
● Manages your app's security and
authentication
● Provides custom server-side code execution
● Provides hosting options
● Provides logging, analytics, and more
Backand Features
● Automated REST API
● Bring your own Database
● Custom JavaScript Actions
● Server-Side Code Execution
● Batch and Bulk Processing
● Scheduled Tasks
● Automated messages
● Real-time Communications
● User and Role-based
Security
● Social Media Authentication
● GUI Schema Editor
● Custom Queries
● REST API Playground
● Sample Code Generation
● Hosting
● Detailed Analytics
● Logging
● Multi-Platform SDK
● Single Sign On Support
THANK YOU
https://github.com/backand
https://www.backand.com
matt@backand.com

Local Lambda Debugging

  • 1.
    Local Lambda Developmentand Debugging Matt Billock matt@backand.com
  • 2.
    Agenda: ● AWS LambdaOverview ● Debugging AWS Lambda ● Building a local test harness ● Deployment with Backand CLI ● Quick overview of Backand
  • 3.
    AWS Lambda ● Createdin 2014, launched at re:Invent ● Kicked off "serverless" (caveat) ● Function-as-a-Service ○Deploy code, not applications
  • 4.
    Creating A LambdaFunction ● Supports Node.JS, Python, C#, and Java ○ Can call to server functionality (Linux) ● Code deployment options ○ Uploading as a ZIP file ○ Uploading from S3 ○ Editing in in-browser editor
  • 5.
    Creating A LambdaFunction Demo
  • 6.
    Calling AWS LambdaFunctions ● Event-based triggers ○ Also On-Demand ● Event Sources ○ AWS Services (S3, DynamoDB, others) ○ API Gateway ○ AWS SDK
  • 7.
    Debugging Lambda Functions ●Cloudwatch Integration ○ Provides call record ● console.log() ○ Sends message to Cloudwatch ● … and that's it
  • 8.
    Lambda Execution Environment ●Details kept proprietary by Amazon ● Based on Amazon Machine Instance ● Dynamically provisioned (hot vs cold) ● Temporary storage (/tmp, 500 MB) ○ NOT guaranteed to persist
  • 9.
    Debugging Lambda Locally ●Need to mimic input format ● Need to mimic output format ○ Transformations in API Gateway ● Need a test harness
  • 10.
    Creating a TestHarness ● Function Prototype ● Including Handler ● Mimicking Lambda Invocation ○ Parameters in event object ○ Handlers in the context object
  • 11.
    Creating a TestHarness ● Calling a Lambda function, continued: ● Provide handlers in context argument
  • 12.
    Test Harness Notes ●Callback mechanism provided by Lambda ○ Only supported by Node.JS actions ● Using callbacks in context parameter ○ Not officially supported ● Not a perfect substitute ○ Calls the function, but not from the same environment
  • 13.
    Improving Iteration Speed ●Per-line output ● Immediate feedback ● Breakpoints and other local debugging tools ● Unit and Integration tests
  • 14.
    Deploying Your Code ●Zip-file from S3, or manual upload ○ NOTE: zip only the source code, not the parent folder! ● Testing upload ● Publishing ● Complex, non-intuitive
  • 15.
    Using Backand's CLITool ● Backand On-Demand Node.JS Lambda actions ● Backand CLI abstracts away deployment ● npm install -g backand ● Requires registering with Backand
  • 16.
    Deploying Lambda Code ●Initializing an action- backand action init ○ Arguments available in docs.backand.com ● Copy your Node.JS code into created directory ● Deploy - backand action deploy ○ Arguments available in docs.backand.com
  • 17.
    Calling Your Lambda ●Authentication ○ can be anonymous ○ api.backand.com/1/token ○ See docs ● cURL curl -H "<auth header>" "https://api.backand.com/1/objects/action/<object>?name=<name>" ● JavaScript (with Backand SDK) backand.object.action.get(...)
  • 18.
    What is Backand? ●Serverless app platform ● Manages your app's database ● Manages your app's security and authentication ● Provides custom server-side code execution ● Provides hosting options ● Provides logging, analytics, and more
  • 19.
    Backand Features ● AutomatedREST API ● Bring your own Database ● Custom JavaScript Actions ● Server-Side Code Execution ● Batch and Bulk Processing ● Scheduled Tasks ● Automated messages ● Real-time Communications ● User and Role-based Security ● Social Media Authentication ● GUI Schema Editor ● Custom Queries ● REST API Playground ● Sample Code Generation ● Hosting ● Detailed Analytics ● Logging ● Multi-Platform SDK ● Single Sign On Support
  • 20.