webinar: serverless architectures with aws lambda and mongodb atlas

Download Webinar: Serverless Architectures with AWS Lambda and MongoDB Atlas

Post on 06-Apr-2017

1.135 views

Category:

Software

9 download

Embed Size (px)

TRANSCRIPT

PowerPoint Presentation

Serverless Architectures with AWS Lambda and MongoDB Atlas

Sig NarvezSr. Solutions Architectsig@mongodb.com @SigNarvaez

Hello everyone, thanks for attending today, and thanks Peter for the introduction.

I really hope that you enjoy this webinar, and if you have questions, we will have a Q&A session at the end, and during the webinar, please feel free to enter questions in the chat box. Also here is my contact information, or you can follow me on twitter.

Serverless?LandscapeUse cases

Going ServerlessWhat changes?ConsiderationsMongoDB Atlas

AWS & MongoDB AtlasSimple API for Customer Single ViewLambda & API GatewayMongoDB Atlas & CompassPostman

Agenda

Ok, lets get started. Today well learn about serverless computing, and understand how did we get here, where we think it is applicable, and why MongoDB Atlas, our DBaaS is also part of this trend.

The first 5 mins or so will be an introduction, followed by hands-on demo of building a simple (hypothetical) API powered by services of the AWS cloud and MongoDB Atlas.

Serverless

Big IronCommodity HardwareVirtualizedContainersFunctionsWhere will my code run?

As developers we think about our code, and where will it run, and as we have seen throughout time, the host of our code is getting smaller and smaller every time, and also easier and easier to manage.

Recently, we got on board the container ship. Where we realized, hey, I dont need a full VM to run my code! - and now, we are taking that a step further by thinking about functions, and let something else run the container.

And this is where the 3 major cloud vendors are now focusing on, FaaS: AWS Lambda, Google Cloud Functions, Azure Functions AWS Lambda being the leader, Google Cloud Functions is on Beta / Early Adopter and it was a major focus of the Google Next17 conference just 2 weeks ago.

Serverless Frameworks and Platforms

https://github.com/serverless/serverless

https://www.zappa.io/Chalice (awslabs)https://github.com/awslabs/chalice

Frameworks for CloudprovidersOn-Prem PaaS now offering FaaS

Frameworks are proliferating, with Serverless being the leader and based on AWS Lambda, although I believe they will offer cross-cloud deployments. Zappa is python based and works with Django, Flask and otthersChalice is a Python Microframework from AWS directly.

But FaaS is not only public cloud, the On-Prem PaaS providers like IBM BlueMix, RedHat OpenShift and Azure Stack are also offering FaaS

Cloud services have matured

BaaS SaaS-ification

APIs are the glue

Containers now per function

SysOps DevOps NoOps Less Ops, More Engineering

5 factors fuelling Serverless Computinghttps://www.forbes.com/sites/janakirammsv/2016/02/28/five-factors-that-are-fueling-serverless-computing-part-1

The first three everyone can agree on

Cloud services are now mature and probably offer all the services that developers needWe live in a state of SaaS-ification and Serverless Computing is the next stepSince everything is a service, APIs have become the glue, and they are inseparable from Serverless computing, as functions are headless, and APIs become their Faade.We are still on the Containerization journey, and as a matter of fact, your serverless functions are hosted on containers (1-1), but now managed by the cloud provider - yet just another operational burden turned into a managed service, and being monetizedBut the most important reason of why Serverless computing has now caught the attention of CTOs and CIOs is the promise of yet again reducing operational cost, and increasing developer productivity. Less Ops, More Engineering

Thoughtworks Technology Radar

Last year, serverless architecures moved from Assess to Trial category

Try this on a project that can handle the risk dont forget to understand the capabilities and where it is a good fit

Scheduled JobsSequencing / Orchestration (AWS Steps?)Data QualityTrigger Identify Pass to functionMicro or Nano servicesClicks or TapsEvent and IoT processingDont worry about scaling App ServersLightweight APIsFocus of today!

Good fit for Serverless?

Serverless

How do I think of Serverless? - As the snap chat of computing ?

MicroservicesBefore and after

Container-based Microservice

Payments ServiceProduct Catalog ServiceShopping CartServiceDomains

https://www.mongodb.com/blog/post/serverless-architectures-the-evolution-of-cloud-computing

Serverless Microservice

CommandQueryResponsibilitySegregationThink about:Fine or course grainedShared logicStart-up time!

PackagingDeploymentVersioning

With Serverless things get more granular

I used to have to manage deployments and scale C & Q separately staff to do so and so on no more. With AWS API Gateway I can manage API keys, security, throttling and so on, and now with serverless functions, no need to worry about scale and availability and routing and DNS mappings and so on, I just focus on my application code and logic.With MongoDB Atlas likewise, I dont need to worry about managing servers, patching and so on. I focus on how the database benefits my application and my consumers, and I can upscale or downscale as necessary

Startup Latency: 10ms to 2 mins!! - some languages add more time: Javascript/Python 10-100ms, JVM, > 10 secsMore noticeable if infrequent callsor X calls per Function instance and you have an influx- Hack of pinging - reqires a server!HOW TO SCALE?

CQRS pattern on Serverless Microservices GETAPIPUT PATCH POST DELETE APIAPI KeyAPI Key

Lambda Function(s)Lambda Function(s)CodeCodeLambda Function(s)

VPC Peering

Own deploymentOwn API KeysResources & Methods may map to the same Lambda FunctionLambda Function may map to your same code asset

ShapePersonInsurance PoliciesShape changes per policy typeAddresses

Operations via APIGET Customers with soon-to-expire policies, within a geo radiusGET Customers / by SSN, id, etc.PATCH Update basic contact info (cell, email, )Customer Single View - Insurance Industry (hypothetical)

High-level architecture of a single view platform

Note: Mention that Atlas, Lambda & VPC have to be in the same region

MongoDB Atlas & AWSBuild it!

Required MongoDB Services Atlas!

mgeneratejshttps://github.com/rueckstiess/mgeneratejsnpm install -g mgeneratejsCreate template generate dataUpload to Atlas via mongoimportHint: get connection string from Atlas UI!Browse with Compass

Generate dataset

Template (InsuranceC360_Customers.json)mgeneratejs -n 100 InsuranceC360_Customers.json | mongoimport --host YOUR ATLAS CLUSTER" --numInsertionWorkers 4--db WebinarCustomerSingleView --collection Customers --authenticationDatabase admin --ssl --username YOURUSER --password YOURPASSWORD

Note: Mention that Atlas, Lambda & VPC have to be in the same region

IAMRole with Lambda execute policies

VPCVPCSecurity Groups traffic rulesInternet Gateway outside communicationVPC Peering Connection - Route Table

Required AWS ServicesLambdaVPC, Security Group and IAM roleDevelop inline or upload deployment package (.zip)Use MongoDB Driver connect with MongoDB Atlas

API GatewayAPI definitionAPI Keys & Usage PlansResources and HTTP MethodsMap Routes to Lambda functions

VPC

MongoDB AtlasProvision a Cluster M10+ need an assigned AWS region for VPC peerSame AWS region (I will use us-west-2)Initiate VPC peer with AWS

AWS VPCAccept incoming Peering ConnectionUpdate Route Table

EC2Install MongoDBTest connection from the MongoDB Shell to ensure VPC Peer is workingOptional but highly recommended ensure VPC Peering is working before proceeding to Lambda

MongoDB Atlas peered with your AWS VPC

Note: Mention that Atlas, Lambda & VPC have to be in the same region

VPC Peering

AtlasAWS

Verify VPC Peer works

Security Group

Peering Connections

Lambda

Role with lambda permissions (IAM)

Code packagingfrom__future__importprint_function

importjsonimportpymongo

print('Loadingfunction')print(=== CONNECTING TO MONGODB ATLAS ===')connstr=ENTER YOUR MONGODB ATLAS CONNECTION HERE"MONGOCLIENT=pymongo.MongoClient(connstr, readPreference=secondaryPreferred)

defGET_lambda_handler(event,context):

implement GET logic

defPOST_lambda_handler(event,context):

implement POST logic

http://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html

Lambda functions

Upload & configure functionThe handler functionThe role with lambda permissionsThe VPC (peered with Atlas)The security group that allows trafficAt least 2 subnets

API Gateway

Read API GET /api/v1/customers

CUD API - PATCH /api/v1/customers

Deploying the API

Access and throttling via API Keys

Test!

Test with Postman

Load test too!

Mention why US-EAST-1

AWS CloudWatch

Connections and containers .. http://docs.aws.amazon.com/lambda/latest/dg/lambda-introduction.html AWS Lambda maintains the container for some time in anticipation of another Lambda function invocation. the service freezes the container after a function completes, and thaws the container for reuse. If AWS Lambda chooses to reuse the container, this has the following implications:

- Any declarations in your Lambda function code (outside the handler code, see Programming Model) remains initialized, providing additional optimization when the function is invoke

Recommended

View more >