SlideShare une entreprise Scribd logo
1  sur  53
Télécharger pour lire hors ligne
#MDBW17
Overview, best practices
BUILDING SERVERLESS APPS
WITH MONGODB ATLAS, AWS
LAMBDA AND STEP FUNCTIONS
#MDBW17
RAPHAEL LONDNER
Developer Advocate,
MongoDB
PAUL SEARS
Solutions Architect,
AWS
paulsear@amazon.com
@rlondner
#MDBW17
AGENDA
• Lambda overview and common use cases
• Lambda code deep dive
• Lambda demo with MongoDB Atlas
• Lambda best practices
• Step Functions
• Step Functions demo
AWS LAMBDA
OVERVIEW
#MDBW17
SERVERLESS COMPUTING - AWS LAMBDA
Run code without provisioning or managing servers – pay only for the
compute time you consume.
#MDBW17
Continuous ScalingNo Servers to
Manage
Subsecond
Metering
BENEFITS OF AWS LAMBDA
AWS Lambda handles:
• Operations and
management
• Provisioning and utilization
• Scaling
• Availability and fault
tolerance
Automatically scales your
application, running code in
response to each trigger
Your code runs in parallel and
processes each trigger
individually, scaling precisely
with the size of the workload
Pricing
• CPU and Network
scaled based on
RAM (128 MB to
1500 MB)
• $0.20 per
1M requests
• Price per 100ms
#MDBW17
AWS LAMBDA USE CASES
• Web applications
• Data processing (real-time streaming analytics)
• Scalable back ends (mobile apps, IoT devices)
• Amazon Alexa
• Chatbots
#MDBW17
Web
Applications
• Static
websites
• Complex web
apps
• Packages for
Flask and
Express
Data
Processing
• Real time
• MapReduce
• Batch
Chatbots
• Powering
chatbot logic
Backends
• Apps &
services
• Mobile
• IoT
</></>
Amazon
Alexa
• Powering
voice-enabled
apps
• Alexa Skills Kit
Autonomous
IT
• Policy engines
• Extending
AWS services
• Infrastructure
management
Data processing: Lambda + S3
COMMON USE CASES
#MDBW17
Data
Processing
• Real time
• MapReduce
• Batch
Data processing: Lambda + Kinesis
COMMON USE CASES
#MDBW17
Web
Applications
• Static
websites
• Complex web
apps
• Packages for
Flask and
Express
Data
Processing
• Real time
• MapReduce
• Batch
Chatbots
• Powering
chatbot logic
Backends
• Apps &
services
• Mobile
• IoT
</></>
Amazon
Alexa
• Powering
voice-enabled
apps
• Alexa Skills Kit
Autonomous
IT
• Policy engines
• Extending
AWS services
• Infrastructure
management
COMMON USE CASES
#MDBW17
Web
Applications
• Static
websites
• Complex web
apps
• Packages for
Flask and
Express
Data
Processing
• Real time
• MapReduce
• Batch
Chatbots
• Powering
chatbot logic
Backends
• Apps &
services
• Mobile
• IoT
</></>
Amazon
Alexa
• Powering
voice-enabled
apps
• Alexa Skills Kit
Autonomous
IT
• Policy engines
• Extending
AWS services
• Infrastructure
management
COMMON USE CASES
CODE DEEP DIVE
#MDBW17
COMPONENTS OF A SERVERLESS APP
EVENT SOURCE
Requests to
endpoints
Changes in
resource state
FUNCTION SERVICES
#MDBW17
ANATOMY OF A LAMBDA FUNCTION
• Handler function (or method)
• An input parameter
‒ Integer, double, string, JSON…
• A context parameter
‒ Provides information such as
o Remaining time until timeout, log group and stream, request ID, etc…
‒ Exposes public properties
• A return value (optional)
#MDBW17
ANATOMY OF A LAMBDA FUNCTION (NODE.JS)
• Handler function in index.js
exports.myHandler = function(event, context, callback)
=> {…}
• Handler format in AWS Lambda: [moduleName].[functionName]
index.myHandler
#MDBW17
ANATOMY OF A LAMBDA FUNCTION (JAVA)
• Handler function in example.Hello class
package example;
public class Hello {
public String myHandler(type inputVal, Context context) {...}
• Handler format in Lambda: [package].[className]::[functionName]
#MDBW17
ANATOMY OF A LAMBDA FUNCTION (PYTHON)
• Handler function in hello_python.py file
def my_handler(event, context):
…
return some_value
• Handler format in Lambda: [fileName].[functionName]
#MDBW17
ANATOMY OF A LAMBDA FUNCTION (C#)
• Handler function in Example.Hello
namespace Example;
public class Hello {
public Stream MyHandler(type inputVal, ILambdaContext context) {...}
• Handler forma in Lambda:
[assemblyName]::[namespace].[className]::[methodName]
#MDBW17
HOW TO DEVELOP FOR LAMBDA & ATLAS
IN NODE.JS
Sign up for
Atlas
Create
a
cluster
Copy cluster
URI to a safe
location
Create
a DB
user
Init a
Node
project
Write code!
Import
MongoDB
Node driver
#MDBW17
HOW TO TEST AND DEPLOY YOUR LAMBDA
Upload your
package to
AWS Lambda
Use lambda-
local to test
locally
Zip your
Node.js
code
Create
your
Lambda
function
Set env.
variables,
memory,
security…
Test in AWS
(Console,
API
Gateway)
LAMBDA DEMO
BIT.LY/LAMBDATUTORIAL
AWS BEST PRACTICES
#MDBW17
BEST PRACTICES: LAMBDA FUNCTION
ü Use the right “timeout”
ü Utilize the functions local storage which is 500MB in size in the /tmp
ü Lower costs and improve performance by minimizing the use of startup code
not directly related to processing the current event
ü Use the built-in CloudWatch monitoring of your Lambda functions to view and
optimize request latencies
#MDBW17
THINGS TO REMEMBER: LAMBDA FUNCTION
ü Memory = “Power level”
q Higher levels offer more memory and more CPU power
ü Functions don’t have a notion of state
q Use MongoDB Atlas, S3, or Elasticache, or AWS Step Functions
q Wrap your config in a function and call it from your published code
ü Use the right access control for downstream services
q IAM roles and permissions for AWS services
q VPC for private endpoints
q KMS for storing credentials for downstream endpoints
#MDBW17
THINGS TO REMEMBER: LAMBDA
APPLICATION
ü Lambda scales by events/requests
q Plan for concurrent request rate on downstream services
ü Shared scaling responsibility for VPC enabled functions
q Sufficient IPs to match your expected concurrency
q at least one subnet in each availability zone
ü Retries are built in for asynchronous and Stream invokes
q Plan for retries for synchronous applications
#MDBW17
WHERE NOT TO CONSIDER LAMBDA (TODAY)
• Large software dependencies: Custom software applications with
licensing agreements such as MS-Office document processing, EDA
tools, Oracle databases, etc.
• OS dependencies: Software packages or applications which rely on
calling underlying Windows RPCs
• Custom hardware: GPU acceleration, hardware affinity
ATLAS WITH AWS
BEST PRACTICES
#MDBW17
AWS LAMBDA WITH MONGODB ATLAS
• Store database connection string in an environment variable
‒ Use –E parameter with lambda-local
‒ Reference it with process.env['MONGODB_ATLAS_URI']
• Encrypt database connection string in AWS Lambda
‒ Use AWS.KMS() to decrypt() the connection string
#MDBW17
PERFORMANCE BEST PRACTICES WITH NODE.JS
• Declare the db object outside the handler method
• Do NOT close the db object!
• Set context.callbackWaitsForEmptyEventLoop to
‘false’
• Try to re-use the db object if
db.serverConfig.isConnected() returns true
LAMBDA
BEST PRACTICES
DEMO
AWS STEP
FUNCTIONS
#MDBW17
λλ
λ
DBMS
λ
λ
λ
λ
λ
λ λ
λ
λ
Queue
MODERN
APP
#MDBW17
MODERN
APP
#MDBW17
“I WANT TO SEQUENCE FUNCTIONS”
“I want to select functions based on data”
“I want to retry functions”
“I want try/catch/finally”
Turning functions into apps
“I have code that runs for hours”
“I want to run functions in parallel”
#MDBW17
BENEFITS OF AWS STEP FUNCTIONS
Diagnose and debug
problems faster
Adapt to change
Easy to connect and
coordinate
distributed components and
microservices to quickly
create apps
Manages the operations
and infrastructure of
service coordination to
ensure availability at
scale, and
under failure
Productivity Agility Resilience
#MDBW17
RUN EACH STEP IN SEQUENCE
Vendor A
Vendor B
Vendor C
#MDBW17
…AND UNWIND IF MY PLANS FAIL AT ANY POINT
Vendor A
Vendor B
Vendor C
#MDBW17
COORDINATION MUST-HAVES
• Scales out
• Doesn’t lose state
• Deals with errors/timeouts
• Easy to build & operate
• Auditable
#MDBW17
APPLICATION LIFECYCLE IN AWS STEP FUNCTIONS
Visualize in the
Console
Define in JSON Monitor
Executions
DEFINE IN JSON AND THEN VISUALIZE IN THE
CONSOLE• {
• ”Comment”: “Hello World Example",
• "StartAt” : "HelloWorld”,
• "States” : {
• "HelloWorld” : {
• "Type” : "Task",
• "Resource” :
"arn:aws:lambda:REGION:ACCOUNT_ID:function:FUNCTI
ON_NAME”,
• "End” : true
• }
• }
#MDBW17
EXECUTE ONE OR ONE MILLION
Start
End
HelloWorld
Start
End
HelloWorld
Start
End
HelloWorld
Start
End
HelloWorld
Start
End
HelloWorld
Start
End
HelloWorld
Start
End
HelloWorld
Start
End
HelloWorld
#MDBW17
MONITOR EXECUTIONS FROM THE CONSOLE
#MDBW17
SEVEN STATE TYPES
Task A single unit of work
Choice Adds branching logic
Parallel Fork and join the data across tasks
Wait Delay for a specified time
Fail
Stops an execution and marks it as a
failure
Succeed Stops an execution successfully
Pass Passes its input to its output
#MDBW17
BUILD VISUAL WORKFLOWS FROM STATE TYPES
Task
Choice
Fail
Parallel
#MDBW17
STEP FUNCTIONS: CUSTOMER USE-CASES
• Workflow/Order management
• Batch processing
• Shell-script replacement
• Enterprise application workflows
• Data gathering and processing
#MDBW17
INTEGRATE WITH OTHER AWS SERVICES
• Create state machines and Activities with AWS CloudFormation
• Call Step Functions with Amazon API Gateway
• Start state machines in response to events or on a schedule with
CloudWatch Events
• Monitor state machine executions with CloudWatch
• Log API calls with CloudTrail
STEP FUNCTIONS
DEMO
BIT.LY/SFTUTORIAL
#MDBW17
#MDBW17
FOLLOW-ON SESSION
• What: MongoDB Atlas and Serverless Architectures
• When: Wednesday, June 21 at 4.30PM
• Where: Crystal A
• Who: Tosin Ajayi, Sr. Solutions Architect
#MDBW17
REFERENCE LINKS
• Serverless development with Node.js, Lambda and MongoDB Atlas
• Optimizing AWS Lambda performance with MongoDB Atlas and
Node.js
• Step Functions with MongoDB Atlas Part 1
• Step Functions with MongoDB Atlas Part 2
• Lambda with MongoDB GitHub repository
• Step Functions with MongoDB GitHub repository
BUILDING Serverless apps with MongoDB AtLAS, AWS Lambda and Step Functions

Contenu connexe

Tendances

ServerlessPresentation
ServerlessPresentationServerlessPresentation
ServerlessPresentation
Rohit Kumar
 
Building CICD Pipelines for Serverless Applications - DevDay Austin 2017
Building CICD Pipelines for Serverless Applications - DevDay Austin 2017Building CICD Pipelines for Serverless Applications - DevDay Austin 2017
Building CICD Pipelines for Serverless Applications - DevDay Austin 2017
Amazon Web Services
 
Building Serverless Web Applications - DevDay Austin 2017
Building Serverless Web Applications - DevDay Austin 2017Building Serverless Web Applications - DevDay Austin 2017
Building Serverless Web Applications - DevDay Austin 2017
Amazon Web Services
 
Exploring Reactive Integrations With Akka Streams, Alpakka And Apache Kafka
Exploring Reactive Integrations With Akka Streams, Alpakka And Apache KafkaExploring Reactive Integrations With Akka Streams, Alpakka And Apache Kafka
Exploring Reactive Integrations With Akka Streams, Alpakka And Apache Kafka
Lightbend
 

Tendances (20)

把您的 Amazon Lex Chatbot 與訊息服務集成
把您的 Amazon Lex Chatbot 與訊息服務集成把您的 Amazon Lex Chatbot 與訊息服務集成
把您的 Amazon Lex Chatbot 與訊息服務集成
 
aws lambda & api gateway
aws lambda & api gatewayaws lambda & api gateway
aws lambda & api gateway
 
ServerlessPresentation
ServerlessPresentationServerlessPresentation
ServerlessPresentation
 
What is AWS lambda?
What is AWS lambda?What is AWS lambda?
What is AWS lambda?
 
Bridging the Gap: Connecting AWS and Kafka
Bridging the Gap: Connecting AWS and KafkaBridging the Gap: Connecting AWS and Kafka
Bridging the Gap: Connecting AWS and Kafka
 
AWS Lambda@Edge Lightning Demos
AWS Lambda@Edge Lightning Demos AWS Lambda@Edge Lightning Demos
AWS Lambda@Edge Lightning Demos
 
Building CICD Pipelines for Serverless Applications - DevDay Austin 2017
Building CICD Pipelines for Serverless Applications - DevDay Austin 2017Building CICD Pipelines for Serverless Applications - DevDay Austin 2017
Building CICD Pipelines for Serverless Applications - DevDay Austin 2017
 
Building Serverless Web Applications - DevDay Austin 2017
Building Serverless Web Applications - DevDay Austin 2017Building Serverless Web Applications - DevDay Austin 2017
Building Serverless Web Applications - DevDay Austin 2017
 
Building resilient serverless systems with non serverless components
Building resilient serverless systems with non serverless componentsBuilding resilient serverless systems with non serverless components
Building resilient serverless systems with non serverless components
 
Building Serverless Web Applications - May 2017 AWS Online Tech Talks
Building Serverless Web Applications  - May 2017 AWS Online Tech TalksBuilding Serverless Web Applications  - May 2017 AWS Online Tech Talks
Building Serverless Web Applications - May 2017 AWS Online Tech Talks
 
How to fail with serverless
How to fail with serverlessHow to fail with serverless
How to fail with serverless
 
Exploring Reactive Integrations With Akka Streams, Alpakka And Apache Kafka
Exploring Reactive Integrations With Akka Streams, Alpakka And Apache KafkaExploring Reactive Integrations With Akka Streams, Alpakka And Apache Kafka
Exploring Reactive Integrations With Akka Streams, Alpakka And Apache Kafka
 
Infinite Scaling using Lambda and Aws - Atlogys Tech Talk
Infinite Scaling using Lambda and Aws - Atlogys Tech TalkInfinite Scaling using Lambda and Aws - Atlogys Tech Talk
Infinite Scaling using Lambda and Aws - Atlogys Tech Talk
 
Serverless Architecture Patterns - Manoj Ganapathi
Serverless Architecture Patterns - Manoj GanapathiServerless Architecture Patterns - Manoj Ganapathi
Serverless Architecture Patterns - Manoj Ganapathi
 
AWS Jungle - Lambda
AWS Jungle - LambdaAWS Jungle - Lambda
AWS Jungle - Lambda
 
How to Build a Big Data Application: Serverless Edition
How to Build a Big Data Application: Serverless EditionHow to Build a Big Data Application: Serverless Edition
How to Build a Big Data Application: Serverless Edition
 
Building Serverless Web Applications
Building Serverless Web Applications Building Serverless Web Applications
Building Serverless Web Applications
 
AWS Lambda
AWS LambdaAWS Lambda
AWS Lambda
 
How to Build a Big Data Application: Serverless Edition
How to Build a Big Data Application: Serverless EditionHow to Build a Big Data Application: Serverless Edition
How to Build a Big Data Application: Serverless Edition
 
Serverless AI - London Loft
Serverless AI - London LoftServerless AI - London Loft
Serverless AI - London Loft
 

Similaire à BUILDING Serverless apps with MongoDB AtLAS, AWS Lambda and Step Functions

Similaire à BUILDING Serverless apps with MongoDB AtLAS, AWS Lambda and Step Functions (20)

AWS Lambda, Step Functions & MongoDB Atlas Tutorial
AWS Lambda, Step Functions & MongoDB Atlas TutorialAWS Lambda, Step Functions & MongoDB Atlas Tutorial
AWS Lambda, Step Functions & MongoDB Atlas Tutorial
 
Serverless Architecture Patterns
Serverless Architecture PatternsServerless Architecture Patterns
Serverless Architecture Patterns
 
serverless_architecture_patterns_london_loft.pdf
serverless_architecture_patterns_london_loft.pdfserverless_architecture_patterns_london_loft.pdf
serverless_architecture_patterns_london_loft.pdf
 
Getting Started with AWS Lambda and the Serverless Cloud
Getting Started with AWS Lambda and the Serverless CloudGetting Started with AWS Lambda and the Serverless Cloud
Getting Started with AWS Lambda and the Serverless Cloud
 
Webinar: Serverless Architectures with AWS Lambda and MongoDB Atlas
Webinar: Serverless Architectures with AWS Lambda and MongoDB AtlasWebinar: Serverless Architectures with AWS Lambda and MongoDB Atlas
Webinar: Serverless Architectures with AWS Lambda and MongoDB Atlas
 
Contruyendo tu primera aplicación con AWS
Contruyendo tu primera aplicación con AWSContruyendo tu primera aplicación con AWS
Contruyendo tu primera aplicación con AWS
 
Getting Started with AWS Lambda & Serverless Cloud
Getting Started with AWS Lambda & Serverless CloudGetting Started with AWS Lambda & Serverless Cloud
Getting Started with AWS Lambda & Serverless Cloud
 
AWS Lambda Functions A Comprehensive Guide
AWS Lambda Functions A Comprehensive GuideAWS Lambda Functions A Comprehensive Guide
AWS Lambda Functions A Comprehensive Guide
 
What's New with AWS Lambda
What's New with AWS LambdaWhat's New with AWS Lambda
What's New with AWS Lambda
 
What's New with AWS Lambda
What's New with AWS LambdaWhat's New with AWS Lambda
What's New with AWS Lambda
 
AWS October Webinar Series - AWS Lambda Best Practices: Python, Scheduled Job...
AWS October Webinar Series - AWS Lambda Best Practices: Python, Scheduled Job...AWS October Webinar Series - AWS Lambda Best Practices: Python, Scheduled Job...
AWS October Webinar Series - AWS Lambda Best Practices: Python, Scheduled Job...
 
Introduction to AWS lambda & Serverless Application1.pptx
Introduction to AWS lambda & Serverless Application1.pptxIntroduction to AWS lambda & Serverless Application1.pptx
Introduction to AWS lambda & Serverless Application1.pptx
 
What’s new in serverless - re:Invent 2020
What’s new in serverless - re:Invent 2020What’s new in serverless - re:Invent 2020
What’s new in serverless - re:Invent 2020
 
How to build and deploy serverless apps - AWS Summit Cape Town 2018
How to build and deploy serverless apps - AWS Summit Cape Town 2018How to build and deploy serverless apps - AWS Summit Cape Town 2018
How to build and deploy serverless apps - AWS Summit Cape Town 2018
 
Getting Started with AWS Lambda and the Serverless Cloud
Getting Started with AWS Lambda and the Serverless CloudGetting Started with AWS Lambda and the Serverless Cloud
Getting Started with AWS Lambda and the Serverless Cloud
 
Getting Started with AWS Lambda and the Serverless Cloud
Getting Started with AWS Lambda and the Serverless CloudGetting Started with AWS Lambda and the Serverless Cloud
Getting Started with AWS Lambda and the Serverless Cloud
 
Serverless Architecture Patterns
Serverless Architecture PatternsServerless Architecture Patterns
Serverless Architecture Patterns
 
Production Ready Serverless Java Applications in 3 Weeks AWS UG Cologne Febru...
Production Ready Serverless Java Applications in 3 Weeks AWS UG Cologne Febru...Production Ready Serverless Java Applications in 3 Weeks AWS UG Cologne Febru...
Production Ready Serverless Java Applications in 3 Weeks AWS UG Cologne Febru...
 
Aws lambda and accesing AWS RDS - Clouddictive
Aws lambda and accesing AWS RDS - ClouddictiveAws lambda and accesing AWS RDS - Clouddictive
Aws lambda and accesing AWS RDS - Clouddictive
 
Migrating your .NET Applications to the AWS Serverless Platform
Migrating your .NET Applications to the AWS Serverless PlatformMigrating your .NET Applications to the AWS Serverless Platform
Migrating your .NET Applications to the AWS Serverless Platform
 

Dernier

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
anilsa9823
 

Dernier (20)

Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 

BUILDING Serverless apps with MongoDB AtLAS, AWS Lambda and Step Functions

  • 1. #MDBW17 Overview, best practices BUILDING SERVERLESS APPS WITH MONGODB ATLAS, AWS LAMBDA AND STEP FUNCTIONS
  • 2. #MDBW17 RAPHAEL LONDNER Developer Advocate, MongoDB PAUL SEARS Solutions Architect, AWS paulsear@amazon.com @rlondner
  • 3. #MDBW17 AGENDA • Lambda overview and common use cases • Lambda code deep dive • Lambda demo with MongoDB Atlas • Lambda best practices • Step Functions • Step Functions demo
  • 5. #MDBW17 SERVERLESS COMPUTING - AWS LAMBDA Run code without provisioning or managing servers – pay only for the compute time you consume.
  • 6. #MDBW17 Continuous ScalingNo Servers to Manage Subsecond Metering BENEFITS OF AWS LAMBDA AWS Lambda handles: • Operations and management • Provisioning and utilization • Scaling • Availability and fault tolerance Automatically scales your application, running code in response to each trigger Your code runs in parallel and processes each trigger individually, scaling precisely with the size of the workload Pricing • CPU and Network scaled based on RAM (128 MB to 1500 MB) • $0.20 per 1M requests • Price per 100ms
  • 7. #MDBW17 AWS LAMBDA USE CASES • Web applications • Data processing (real-time streaming analytics) • Scalable back ends (mobile apps, IoT devices) • Amazon Alexa • Chatbots
  • 8. #MDBW17 Web Applications • Static websites • Complex web apps • Packages for Flask and Express Data Processing • Real time • MapReduce • Batch Chatbots • Powering chatbot logic Backends • Apps & services • Mobile • IoT </></> Amazon Alexa • Powering voice-enabled apps • Alexa Skills Kit Autonomous IT • Policy engines • Extending AWS services • Infrastructure management Data processing: Lambda + S3 COMMON USE CASES
  • 9. #MDBW17 Data Processing • Real time • MapReduce • Batch Data processing: Lambda + Kinesis COMMON USE CASES
  • 10. #MDBW17 Web Applications • Static websites • Complex web apps • Packages for Flask and Express Data Processing • Real time • MapReduce • Batch Chatbots • Powering chatbot logic Backends • Apps & services • Mobile • IoT </></> Amazon Alexa • Powering voice-enabled apps • Alexa Skills Kit Autonomous IT • Policy engines • Extending AWS services • Infrastructure management COMMON USE CASES
  • 11. #MDBW17 Web Applications • Static websites • Complex web apps • Packages for Flask and Express Data Processing • Real time • MapReduce • Batch Chatbots • Powering chatbot logic Backends • Apps & services • Mobile • IoT </></> Amazon Alexa • Powering voice-enabled apps • Alexa Skills Kit Autonomous IT • Policy engines • Extending AWS services • Infrastructure management COMMON USE CASES
  • 13. #MDBW17 COMPONENTS OF A SERVERLESS APP EVENT SOURCE Requests to endpoints Changes in resource state FUNCTION SERVICES
  • 14. #MDBW17 ANATOMY OF A LAMBDA FUNCTION • Handler function (or method) • An input parameter ‒ Integer, double, string, JSON… • A context parameter ‒ Provides information such as o Remaining time until timeout, log group and stream, request ID, etc… ‒ Exposes public properties • A return value (optional)
  • 15. #MDBW17 ANATOMY OF A LAMBDA FUNCTION (NODE.JS) • Handler function in index.js exports.myHandler = function(event, context, callback) => {…} • Handler format in AWS Lambda: [moduleName].[functionName] index.myHandler
  • 16. #MDBW17 ANATOMY OF A LAMBDA FUNCTION (JAVA) • Handler function in example.Hello class package example; public class Hello { public String myHandler(type inputVal, Context context) {...} • Handler format in Lambda: [package].[className]::[functionName]
  • 17. #MDBW17 ANATOMY OF A LAMBDA FUNCTION (PYTHON) • Handler function in hello_python.py file def my_handler(event, context): … return some_value • Handler format in Lambda: [fileName].[functionName]
  • 18. #MDBW17 ANATOMY OF A LAMBDA FUNCTION (C#) • Handler function in Example.Hello namespace Example; public class Hello { public Stream MyHandler(type inputVal, ILambdaContext context) {...} • Handler forma in Lambda: [assemblyName]::[namespace].[className]::[methodName]
  • 19. #MDBW17 HOW TO DEVELOP FOR LAMBDA & ATLAS IN NODE.JS Sign up for Atlas Create a cluster Copy cluster URI to a safe location Create a DB user Init a Node project Write code! Import MongoDB Node driver
  • 20. #MDBW17 HOW TO TEST AND DEPLOY YOUR LAMBDA Upload your package to AWS Lambda Use lambda- local to test locally Zip your Node.js code Create your Lambda function Set env. variables, memory, security… Test in AWS (Console, API Gateway)
  • 24. #MDBW17 BEST PRACTICES: LAMBDA FUNCTION ü Use the right “timeout” ü Utilize the functions local storage which is 500MB in size in the /tmp ü Lower costs and improve performance by minimizing the use of startup code not directly related to processing the current event ü Use the built-in CloudWatch monitoring of your Lambda functions to view and optimize request latencies
  • 25. #MDBW17 THINGS TO REMEMBER: LAMBDA FUNCTION ü Memory = “Power level” q Higher levels offer more memory and more CPU power ü Functions don’t have a notion of state q Use MongoDB Atlas, S3, or Elasticache, or AWS Step Functions q Wrap your config in a function and call it from your published code ü Use the right access control for downstream services q IAM roles and permissions for AWS services q VPC for private endpoints q KMS for storing credentials for downstream endpoints
  • 26. #MDBW17 THINGS TO REMEMBER: LAMBDA APPLICATION ü Lambda scales by events/requests q Plan for concurrent request rate on downstream services ü Shared scaling responsibility for VPC enabled functions q Sufficient IPs to match your expected concurrency q at least one subnet in each availability zone ü Retries are built in for asynchronous and Stream invokes q Plan for retries for synchronous applications
  • 27. #MDBW17 WHERE NOT TO CONSIDER LAMBDA (TODAY) • Large software dependencies: Custom software applications with licensing agreements such as MS-Office document processing, EDA tools, Oracle databases, etc. • OS dependencies: Software packages or applications which rely on calling underlying Windows RPCs • Custom hardware: GPU acceleration, hardware affinity
  • 28. ATLAS WITH AWS BEST PRACTICES
  • 29. #MDBW17 AWS LAMBDA WITH MONGODB ATLAS • Store database connection string in an environment variable ‒ Use –E parameter with lambda-local ‒ Reference it with process.env['MONGODB_ATLAS_URI'] • Encrypt database connection string in AWS Lambda ‒ Use AWS.KMS() to decrypt() the connection string
  • 30. #MDBW17 PERFORMANCE BEST PRACTICES WITH NODE.JS • Declare the db object outside the handler method • Do NOT close the db object! • Set context.callbackWaitsForEmptyEventLoop to ‘false’ • Try to re-use the db object if db.serverConfig.isConnected() returns true
  • 35. #MDBW17 “I WANT TO SEQUENCE FUNCTIONS” “I want to select functions based on data” “I want to retry functions” “I want try/catch/finally” Turning functions into apps “I have code that runs for hours” “I want to run functions in parallel”
  • 36. #MDBW17 BENEFITS OF AWS STEP FUNCTIONS Diagnose and debug problems faster Adapt to change Easy to connect and coordinate distributed components and microservices to quickly create apps Manages the operations and infrastructure of service coordination to ensure availability at scale, and under failure Productivity Agility Resilience
  • 37. #MDBW17 RUN EACH STEP IN SEQUENCE Vendor A Vendor B Vendor C
  • 38. #MDBW17 …AND UNWIND IF MY PLANS FAIL AT ANY POINT Vendor A Vendor B Vendor C
  • 39. #MDBW17 COORDINATION MUST-HAVES • Scales out • Doesn’t lose state • Deals with errors/timeouts • Easy to build & operate • Auditable
  • 40. #MDBW17 APPLICATION LIFECYCLE IN AWS STEP FUNCTIONS Visualize in the Console Define in JSON Monitor Executions
  • 41. DEFINE IN JSON AND THEN VISUALIZE IN THE CONSOLE• { • ”Comment”: “Hello World Example", • "StartAt” : "HelloWorld”, • "States” : { • "HelloWorld” : { • "Type” : "Task", • "Resource” : "arn:aws:lambda:REGION:ACCOUNT_ID:function:FUNCTI ON_NAME”, • "End” : true • } • }
  • 42. #MDBW17 EXECUTE ONE OR ONE MILLION Start End HelloWorld Start End HelloWorld Start End HelloWorld Start End HelloWorld Start End HelloWorld Start End HelloWorld Start End HelloWorld Start End HelloWorld
  • 44. #MDBW17 SEVEN STATE TYPES Task A single unit of work Choice Adds branching logic Parallel Fork and join the data across tasks Wait Delay for a specified time Fail Stops an execution and marks it as a failure Succeed Stops an execution successfully Pass Passes its input to its output
  • 45. #MDBW17 BUILD VISUAL WORKFLOWS FROM STATE TYPES Task Choice Fail Parallel
  • 46. #MDBW17 STEP FUNCTIONS: CUSTOMER USE-CASES • Workflow/Order management • Batch processing • Shell-script replacement • Enterprise application workflows • Data gathering and processing
  • 47. #MDBW17 INTEGRATE WITH OTHER AWS SERVICES • Create state machines and Activities with AWS CloudFormation • Call Step Functions with Amazon API Gateway • Start state machines in response to events or on a schedule with CloudWatch Events • Monitor state machine executions with CloudWatch • Log API calls with CloudTrail
  • 51. #MDBW17 FOLLOW-ON SESSION • What: MongoDB Atlas and Serverless Architectures • When: Wednesday, June 21 at 4.30PM • Where: Crystal A • Who: Tosin Ajayi, Sr. Solutions Architect
  • 52. #MDBW17 REFERENCE LINKS • Serverless development with Node.js, Lambda and MongoDB Atlas • Optimizing AWS Lambda performance with MongoDB Atlas and Node.js • Step Functions with MongoDB Atlas Part 1 • Step Functions with MongoDB Atlas Part 2 • Lambda with MongoDB GitHub repository • Step Functions with MongoDB GitHub repository