SlideShare una empresa de Scribd logo
1 de 53
Descargar para leer sin conexión
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
George Mao
Specialist Solutions Architect, Serverless
Amazon Web Services
Building Enterprise-Grade
Serverless Apps
SRV315
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Customers innovating with AWS Lambda
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Why are customers choosing Lambda & Serverless?
iRobot does >1,000 Lambda deployments a day
for its serverless IoT backend that runs internet
connected-vacuums, with 2M connected robots by
2018 (FY17 projected).
Fannie Maeis replacing on-premises data
centers with a Lambda-based solution that can run
a Monte Carlo simulation on 20M mortgage
calculations in 1.5 hours.
Nextdoor replaced its Apache Flume platform
with a serverless data ingestion pipeline that
handles 3B events daily.
HomeAwayuses Lambda to process and prepare 6M user-
uploaded photos a month for its vacation rental marketplace.
Agero’saccident detection and driver behavior analysis
platform handles over 1B Lambda requests each month and
scales to handle 20x at peak load.
Revvelreduced video transcoding time by >95% at a fraction
of the cost of transcoding videos on server-based solutions.
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Stack Overflow Developer Survey 2018
*https://insights.stackoverflow.com/survey/2018/
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Key Industry Trends
Don’t code it yourself!
The Rise of Managed Services
Stream processing and
“embarrassingly parallel” computing
Snowballing adoption of
microservices
Serverless, event-driven
architectures
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Lambda Means…
No Server Management Flexible Scaling
No Idle Capacity
$
High Availability
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Agenda: 6 ways to improve your serverless mojo
1. Think in patterns: the serverless architecture playbook
2. Use APIs effectively
3. SecOps like you mean it: permissions & privileges
4. Software lifecycle: from coding to deployment
5. Think in apps
6. When things go wrong: Error-handling and diagnostics
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
1. Serverless Patterns:
Managed services + Lambda functions
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Managed services as building blocks
Amazon SNS
Amazon SQS
Amazon S3
Messaging
Monitoring and Debugging
Storage
AWS X-Ray
AWS Lambda
Amazon API Gateway
Orchestration
API Proxy
Compute
AWS Step Functions
Amazon DynamoDB
Amazon Kinesis
Analytics
Database
Edge Compute
AWS Greengrass
Lambda@Edge
Amazon Athena
Amazon Aurora
Serverless (coming soon)
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AWS Lambda
Compute
Example: Serverless analytics
Amazon Kinesis
Analytics
Amazon Athena
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Amazon API Gateway
API Proxy
AWS Lambda
Compute
Amazon S3
Storage
Example: Serverless web app
Amazon DynamoDB
Database
Amazon Aurora
Serverless (coming soon)
Static Content Dynamic Content
API Serving
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Patterns for the Cloud Era
• Media transform on upload: Amazon S3 event +
Lambda
• NoSQL data cleansing: Amazon DynamoDB change
streams + Lambda
• Serverless website: Amazon S3 + Amazon DynamoDB
+ Amazon API Gateway + Lambda
• Click-stream analytics: Amazon Kinesis Data Firehose
+ Lambda
• Ordered event processing: Kinesis + Lambda
• Multi-function fanout: Amazon SNS (or Lambda) +
Lambda
• Workflows: AWS Step Functions + Lambda
• Event distribution: Amazon CloudWatch Events +
Lambda
• Serverless cron jobs: CloudWatch timer events +
Lambda
• GraphQL actions: AWS AppSync + Lambda
• On-the-fly image resizing: AWS Lambda@Edge +
Amazon CloudFront
• Email rules: Amazon SES + Lambda
• Configuration policy enforcement: AWS Config +
Lambda
• Stored procedures: Amazon Aurora + Lambda
• Custom authorizers for APIs: API Gateway auth +
Lambda
• DevOps choreography: CloudWatch alarms + Lambda
• Alexa skills: Amazon Alexa + Lambda
• Chatbots: Slack + Amazon Lex + Lambda
• IoT automation: AWS IoT + Lambda
• Smart devices: AWS Greengrass + Lambda
• On-premises file encrypt for transit: AWS Snowball
Edge + Lambda
• …
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Meta-patterns
1. Service pushes async event to Lambda (Amazon S3, Amazon SNS)
2. Lambda grabs event from service (Amazon DynamoDB, Amazon Kinesis)
3. Synchronous exchange (Amazon Alexa, Amazon Lex)
4. Batch transform (Amazon Kinesis Data Firehose)
5. Microservice (API + Lambda + your choice of DB)
6. Customization via functions (AWS Config, Amazon SES rules)
7. Data-driven fanout (S3-Lambda, Lambda-Lambda)
8. Choreography (AWS Step Functions + Lambda)
9. Lambda functions in devices (AWS Greengrass, AWS Snowball Edge)
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
ICYMI:
Amazon SQS as a built-in Lambda event
source
is live!
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Patterns: Best practices
• Don’t reinvent the wheel – use managed services when possible
• …and stay current ☺
• Keep events inside AWS services for as long as possible:
• Example:
• Amazon S3 → client → Lambda
• Amazon S3 → Lambda
• Verify limits end-to-end
• Prefer idempotent, stateless functions, and when you can’t…
• Use AWS Step Functions if you need stateful control (retries, long-running)
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
2. Use APIs Effectively
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
GetFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.get
Runtime: nodejs6.10
CodeUri: s3://bucket/api_backend.zip
Policies: AmazonDynamoDBReadOnlyAccess
Environment:
Variables:
TABLE_NAME: !Ref Table
Events:
GetResource:
Type: Api
Properties:
Path: /resource/{resourceId}
Method: get
Start Simple!
Meet AWS SAM!
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Extend with Swagger
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
Api:
Type: AWS::Serverless::Api
Properties:
StageName: prod
DefinitionUri: swagger.yml
---
swagger: "2.0"
info:
version: "2018-06-06T01:36:07Z"
title: "PetStore"
host: "0ftv5igkjd.execute-api.us-east-
1.amazonaws.com"
basePath: "/test"
schemes:
- "https"
paths:
/:
get:
consumes:
- "application/json"
produces:
- "text/html"
responses:
200:
description: "200 response"
headers:
Content-Type:
type: "string"
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Choose the right API Endpoints
• Edge optimized: Designed for geographically diverse clients, uses
integrated CloudFront to enable clients to connect to the closest
PoP
• Regional: Designed for EC2 clients, within the same region as the
API
• Private: Designed for VPC only access, with no internet access
needed. (Uses AWS PrivateLink VPC endpoint)
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Manage throttling and rate-limiting
• Protect backends with method
level rate-limiting
• Protect clients from aggressive
use using Usage plans
• Limit on RPS
• Limit on requests per
day/week/month
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
ICYMI – Summary of recent API Gateway launches
• Fine-grained (method-level) throttling
• Overrides on request/response parameters and
response status
• Higher limits on APIs and resource change rates
• 600 APIs (regional or private endpoint)
• 120 APIs (edge-optimized)
• Available in AWS China Ningxia region
• Resource policies and cross-account access enabled
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
3. Security and AuthZ
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Serverless apps can be the most secure apps, if…
…you use the tools provided correctly:
• Secure
- Resource policies (Lambda & API GW)
- Custom authorizers (API GW)
- Execution roles (Lambda)
• Audit
- AWS Config policies
- AWS CloudTrail traces
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Full circle of protection
Limit
Access
Limit rights
Secure
credentials
Audit
access
Enforce
policies
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Limit access: Resource policies and custom authorizers
Analogy: Who would I invite into my
house?
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Limit access: Resource policies and custom authorizers
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Limit access: Resource policies and custom authorizers
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Limits rights: Execution and invocation roles
Analogy: What do I let my kids play
with?
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Limit rights: Execution and invocation roles
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Limit rights: Execution and invocation roles
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Keeping track: Auditing and Config Policies
• Use AWS CloudTrail to track API and function management
(creation, deletion, retrieval, etc.)
• Can also audit function invocation for Lambda
• Run queries against CloudTrail data using Amazon Athena
• Or build a simple analysis engine using Lambda functions
• Use AWS Config to continuously monitor and enforce policies
• For example: Enforcing Lambda function policies do not have public
access
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AWS Config: Detect Public Access and react!
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Calling Third Party Services Securely
AWS Secrets Manager
• Securely store, retrieve, and manage database credentials,
API keys, and other secrets for AWS or third-party systems
• Rotate, audit, and version secrets
• Built-in support for MySQL, PostgreSQL, and Amazon
Aurora on Amazon RDS
• Supports both default and custom KMS keys
• Avoid cleartext secrets in Lambda env vars or code!
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
4. Building, Testing, and Deploying
Serverless Apps
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AWS CodePipeline
AWS Code Suite
AWS
CodeCommit
or GitHub
AWS
CodeBuild
(build)
AWS
CodeBuild
(test)
AWS
CloudFormation
(deploy)
AWS
CodeDeploy
(rollout)
AWS Cloud9
Editor
AWS
CodeStar
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Best Practices for Serverless Development
• CI/CD pipeline for apps (including repo publishing!)
• Test and debug locally
• AWS CloudFormation can deploy to multiple regions
• Useful for multi-region APIs
• Deploy incrementally for safety
• Weighted aliases in Lambda
• Canary stages in API Gateway
• AWS CodeDeploy can automate AWS SAM app deploys (including
rollback)
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Local test, build, & debug with AWS SAM CLI
• AWS SAM = AWS Serverless Application
Model
• Copy of the Lambda execution environment
• Powers local test/debug
• Models serverless applications
• Works in IDEs, command line, etc.
• Use “sam init” to create a new project
• Open source!
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
5. It’s All about [Serverless] Apps
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AWS Serverless Application Repository
Customize and create directly from the Lambda console, command
line, or SDK
• Publish and share apps three ways…
• Within your AWS account
• Across accounts
• With everyone (public access)
• Based on AWS SAM – simple model of your serverless application
• Deploys using CloudFormation (use anywhere AWS CloudFormation works!)
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Growing Set of App Producers
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
6. When Things Go Wrong:
Error-Handling and Diagnostics
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
CloudWatch metrics
• API Calls Count,
• Latency,
• 4XXs, 5XXs,
• Integration Latency,
• Cache Hit Count,
• Cache Miss Count
API Gateway
• Invocation Count,
• Invocation duration,
• Invocation errors,
• Throttled Invocation,
• Iterator Age,
• DLQ Errors,
• Concurrency
Lambda
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
API Gateway CloudWatch Logs
API Gateway Execution Logging
Two levels of logging, error and info
Optionally log method request/body content
Set globally in stage, or override per method
API Gateway Access Logging
Details about *who* accessed your API
IP, HttpMethod, User, Protocol, Time
Customizable format for machine parsable logs
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
API Gateway Custom Access Logging
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
The Lambda function request Lifecycle
1. Download your code (as a SquashFS filesystem)
2. Start the language runtime
3. Load your code (e.g., class loading in Java)
4. Run “init” code (e.g., static initializers in Java)
5. Process the request warm
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Same View in AWS X-Ray
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Things You Can Track in X-Ray for Lambda
• Cold vs warm starts
• Async dwell time (time event spends in queue)
• Duration of calls to other AWS services (and with a little work to
add trace points, third-party services)
• Errors and throttles from AWS service calls
Lots of great third-party offerings can also help!
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Making Cold Starts More Efficient
• Control the dependencies in your function's deployment package
• Tree shake your Java code! (Hint: Spring is expensive )
• Can combine ‘cold’ and ‘hot’ functions
• Optimize for your language, where applicable…
• Node – Browserfy, Minify
• AWS Java v2 SDK (preview)
• Only use VPC if you need access to a resource there!
• Delay loading where possible
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Summary: 6 ways to improve your serverless mojo
1. Think in patterns: the serverless architecture playbook
2. Use APIs effectively
3. SecOps like you mean it: permissions & privileges
4. Software lifecycle: from coding to deployment
5. Think in apps
6. When things go wrong: Error-handling and diagnostics
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Speaker Info / Social Media Channels
George Mao
Serverless Specialist Solutions Architect
georgemao@
http://aws.amazon.com/serverless/
https://github.com/aws-samples/
https://github.com/awslabs
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Submit session feedback
1. Tap the Schedule icon.
2. Select the session you attended.
3. Tap Session Evaluation to submit your
feedback.
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Thank you!

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

AWS Systems Manage: Bridging Operational Models
AWS Systems Manage: Bridging Operational Models AWS Systems Manage: Bridging Operational Models
AWS Systems Manage: Bridging Operational Models
 
Serverless Architectural Patterns and Best Practices
Serverless Architectural Patterns and Best PracticesServerless Architectural Patterns and Best Practices
Serverless Architectural Patterns and Best Practices
 
Lessons Learned from Building an AWS Service on AWS Lambda (SRV327-R1) - AWS ...
Lessons Learned from Building an AWS Service on AWS Lambda (SRV327-R1) - AWS ...Lessons Learned from Building an AWS Service on AWS Lambda (SRV327-R1) - AWS ...
Lessons Learned from Building an AWS Service on AWS Lambda (SRV327-R1) - AWS ...
 
Modern Applications Web Day | Impress Your Friends with Your First Serverless...
Modern Applications Web Day | Impress Your Friends with Your First Serverless...Modern Applications Web Day | Impress Your Friends with Your First Serverless...
Modern Applications Web Day | Impress Your Friends with Your First Serverless...
 
How AQR Capital Uses AWS to Research New Investment Signals
How AQR Capital Uses AWS to Research New Investment Signals How AQR Capital Uses AWS to Research New Investment Signals
How AQR Capital Uses AWS to Research New Investment Signals
 
Learn Step by Step How iDevices Uses AWS IoT Analytics - AWS Online Tech Talks
Learn Step by Step How iDevices Uses AWS IoT Analytics - AWS Online Tech TalksLearn Step by Step How iDevices Uses AWS IoT Analytics - AWS Online Tech Talks
Learn Step by Step How iDevices Uses AWS IoT Analytics - AWS Online Tech Talks
 
CI/CD for Serverless and Containerized Applications (DEV309-R1) - AWS re:Inve...
CI/CD for Serverless and Containerized Applications (DEV309-R1) - AWS re:Inve...CI/CD for Serverless and Containerized Applications (DEV309-R1) - AWS re:Inve...
CI/CD for Serverless and Containerized Applications (DEV309-R1) - AWS re:Inve...
 
Containers State of the Union I AWS Dev Day 2018
Containers State of the Union I AWS Dev Day 2018Containers State of the Union I AWS Dev Day 2018
Containers State of the Union I AWS Dev Day 2018
 
Build Intelligent Apps with Amazon ML
Build Intelligent Apps with Amazon ML Build Intelligent Apps with Amazon ML
Build Intelligent Apps with Amazon ML
 
Getting Started with AWS Lambda and Serverless Computing
Getting Started with AWS Lambda and Serverless ComputingGetting Started with AWS Lambda and Serverless Computing
Getting Started with AWS Lambda and Serverless Computing
 
Building Real-time Serverless Backends
Building Real-time Serverless BackendsBuilding Real-time Serverless Backends
Building Real-time Serverless Backends
 
Use Alexa Skills to Buy Digital Content: A Workshop for In-Skill Purchasing (...
Use Alexa Skills to Buy Digital Content: A Workshop for In-Skill Purchasing (...Use Alexa Skills to Buy Digital Content: A Workshop for In-Skill Purchasing (...
Use Alexa Skills to Buy Digital Content: A Workshop for In-Skill Purchasing (...
 
Serverless: State of The Union I AWS Dev Day 2018
Serverless: State of The Union I AWS Dev Day 2018Serverless: State of The Union I AWS Dev Day 2018
Serverless: State of The Union I AWS Dev Day 2018
 
Secure your AWS Account and your Organization's Accounts
Secure your AWS Account and your Organization's Accounts Secure your AWS Account and your Organization's Accounts
Secure your AWS Account and your Organization's Accounts
 
Leadership Session: Learn about 10 Years' of Windows and .NET Innovation on A...
Leadership Session: Learn about 10 Years' of Windows and .NET Innovation on A...Leadership Session: Learn about 10 Years' of Windows and .NET Innovation on A...
Leadership Session: Learn about 10 Years' of Windows and .NET Innovation on A...
 
IAM for Enterprises: How Vanguard Matured IAM Controls to Support Micro Accou...
IAM for Enterprises: How Vanguard Matured IAM Controls to Support Micro Accou...IAM for Enterprises: How Vanguard Matured IAM Controls to Support Micro Accou...
IAM for Enterprises: How Vanguard Matured IAM Controls to Support Micro Accou...
 
Serverless - State of the Union
Serverless - State of the UnionServerless - State of the Union
Serverless - State of the Union
 
SRV315 Building Enterprise-Grade Serverless Apps
 SRV315 Building Enterprise-Grade Serverless Apps SRV315 Building Enterprise-Grade Serverless Apps
SRV315 Building Enterprise-Grade Serverless Apps
 
BDA309 Build Your First Big Data Application on AWS
BDA309 Build Your First Big Data Application on AWSBDA309 Build Your First Big Data Application on AWS
BDA309 Build Your First Big Data Application on AWS
 
Unleash the Power of Temporary AWS Credentials (a.k.a. IAM roles) (SEC390-R1)...
Unleash the Power of Temporary AWS Credentials (a.k.a. IAM roles) (SEC390-R1)...Unleash the Power of Temporary AWS Credentials (a.k.a. IAM roles) (SEC390-R1)...
Unleash the Power of Temporary AWS Credentials (a.k.a. IAM roles) (SEC390-R1)...
 

Similar a Build Enterprise-Grade Serverless Apps - SRV315 - Chicago AWS Summit

Serverless Architecture - Design Patterns and Best Practices
Serverless Architecture - Design Patterns and Best PracticesServerless Architecture - Design Patterns and Best Practices
Serverless Architecture - Design Patterns and Best Practices
Amazon Web Services
 

Similar a Build Enterprise-Grade Serverless Apps - SRV315 - Chicago AWS Summit (20)

Building serverless enterprise applications - SRV315 - Toronto AWS Summit
Building serverless enterprise applications - SRV315 - Toronto AWS SummitBuilding serverless enterprise applications - SRV315 - Toronto AWS Summit
Building serverless enterprise applications - SRV315 - Toronto AWS Summit
 
Building Serverless Enterprise Applications - SRV315 - Anaheim AWS Summit
Building Serverless Enterprise Applications - SRV315 - Anaheim AWS SummitBuilding Serverless Enterprise Applications - SRV315 - Anaheim AWS Summit
Building Serverless Enterprise Applications - SRV315 - Anaheim AWS Summit
 
Serverless Architectural Patterns and Best Practices (ARC305-R2) - AWS re:Inv...
Serverless Architectural Patterns and Best Practices (ARC305-R2) - AWS re:Inv...Serverless Architectural Patterns and Best Practices (ARC305-R2) - AWS re:Inv...
Serverless Architectural Patterns and Best Practices (ARC305-R2) - AWS re:Inv...
 
The Future of Enterprise Applications is Serverless (ENT314-R1) - AWS re:Inve...
The Future of Enterprise Applications is Serverless (ENT314-R1) - AWS re:Inve...The Future of Enterprise Applications is Serverless (ENT314-R1) - AWS re:Inve...
The Future of Enterprise Applications is Serverless (ENT314-R1) - AWS re:Inve...
 
Serverless Architectural Patterns - ServerlessDays TLV
Serverless Architectural Patterns - ServerlessDays TLVServerless Architectural Patterns - ServerlessDays TLV
Serverless Architectural Patterns - ServerlessDays TLV
 
Build and Deploy Serverless Applications with AWS SAM
Build and Deploy Serverless Applications with AWS SAM Build and Deploy Serverless Applications with AWS SAM
Build and Deploy Serverless Applications with AWS SAM
 
Serverless Architectural Patterns
Serverless Architectural PatternsServerless Architectural Patterns
Serverless Architectural Patterns
 
Developing and Implementing APIs at Scale, the Servless Way - Ed Lima - AWS T...
Developing and Implementing APIs at Scale, the Servless Way - Ed Lima - AWS T...Developing and Implementing APIs at Scale, the Servless Way - Ed Lima - AWS T...
Developing and Implementing APIs at Scale, the Servless Way - Ed Lima - AWS T...
 
Serverless computing - Build and run applications without thinking about servers
Serverless computing - Build and run applications without thinking about serversServerless computing - Build and run applications without thinking about servers
Serverless computing - Build and run applications without thinking about servers
 
Getting Started with AWS Lambda Serverless Computing
Getting Started with AWS Lambda Serverless ComputingGetting Started with AWS Lambda Serverless Computing
Getting Started with AWS Lambda Serverless Computing
 
Serverless Architecture - Design Patterns and Best Practices
Serverless Architecture - Design Patterns and Best PracticesServerless Architecture - Design Patterns and Best Practices
Serverless Architecture - Design Patterns and Best Practices
 
Building Serverless Applications with Amazon DynamoDB & AWS Lambda - Workshop...
Building Serverless Applications with Amazon DynamoDB & AWS Lambda - Workshop...Building Serverless Applications with Amazon DynamoDB & AWS Lambda - Workshop...
Building Serverless Applications with Amazon DynamoDB & AWS Lambda - Workshop...
 
Serverless Development Deep Dive
Serverless Development Deep DiveServerless Development Deep Dive
Serverless Development Deep Dive
 
Serverless Architectural Patterns - GOTO Amsterdam
Serverless Architectural Patterns - GOTO AmsterdamServerless Architectural Patterns - GOTO Amsterdam
Serverless Architectural Patterns - GOTO Amsterdam
 
Unlocking Agility with the AWS Serverless Application Model (SAM) - AWS Summi...
Unlocking Agility with the AWS Serverless Application Model (SAM) - AWS Summi...Unlocking Agility with the AWS Serverless Application Model (SAM) - AWS Summi...
Unlocking Agility with the AWS Serverless Application Model (SAM) - AWS Summi...
 
Developing Serverless Application on AWS
Developing Serverless Application on AWSDeveloping Serverless Application on AWS
Developing Serverless Application on AWS
 
Serverless use cases with AWS Lambda - More Serverless Event
Serverless use cases with AWS Lambda - More Serverless EventServerless use cases with AWS Lambda - More Serverless Event
Serverless use cases with AWS Lambda - More Serverless Event
 
Building API-Driven Microservices with Amazon API Gateway - AWS Online Tech T...
Building API-Driven Microservices with Amazon API Gateway - AWS Online Tech T...Building API-Driven Microservices with Amazon API Gateway - AWS Online Tech T...
Building API-Driven Microservices with Amazon API Gateway - AWS Online Tech T...
 
Introduction to AWS Lambda and Serverless Applications
Introduction to AWS Lambda and Serverless ApplicationsIntroduction to AWS Lambda and Serverless Applications
Introduction to AWS Lambda and Serverless Applications
 
Intro to AWS Lambda and Serverless Applications: re:Invent 2018 Recap at the ...
Intro to AWS Lambda and Serverless Applications: re:Invent 2018 Recap at the ...Intro to AWS Lambda and Serverless Applications: re:Invent 2018 Recap at the ...
Intro to AWS Lambda and Serverless Applications: re:Invent 2018 Recap at the ...
 

Más de Amazon Web Services

Tools for building your MVP on AWS
Tools for building your MVP on AWSTools for building your MVP on AWS
Tools for building your MVP on AWS
Amazon Web Services
 
How to Build a Winning Pitch Deck
How to Build a Winning Pitch DeckHow to Build a Winning Pitch Deck
How to Build a Winning Pitch Deck
Amazon Web Services
 
Building a web application without servers
Building a web application without serversBuilding a web application without servers
Building a web application without servers
Amazon Web Services
 
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
Amazon Web Services
 

Más de Amazon Web Services (20)

Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
 
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
 
Esegui pod serverless con Amazon EKS e AWS Fargate
Esegui pod serverless con Amazon EKS e AWS FargateEsegui pod serverless con Amazon EKS e AWS Fargate
Esegui pod serverless con Amazon EKS e AWS Fargate
 
Costruire Applicazioni Moderne con AWS
Costruire Applicazioni Moderne con AWSCostruire Applicazioni Moderne con AWS
Costruire Applicazioni Moderne con AWS
 
Come spendere fino al 90% in meno con i container e le istanze spot
Come spendere fino al 90% in meno con i container e le istanze spot Come spendere fino al 90% in meno con i container e le istanze spot
Come spendere fino al 90% in meno con i container e le istanze spot
 
Open banking as a service
Open banking as a serviceOpen banking as a service
Open banking as a service
 
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
 
OpsWorks Configuration Management: automatizza la gestione e i deployment del...
OpsWorks Configuration Management: automatizza la gestione e i deployment del...OpsWorks Configuration Management: automatizza la gestione e i deployment del...
OpsWorks Configuration Management: automatizza la gestione e i deployment del...
 
Microsoft Active Directory su AWS per supportare i tuoi Windows Workloads
Microsoft Active Directory su AWS per supportare i tuoi Windows WorkloadsMicrosoft Active Directory su AWS per supportare i tuoi Windows Workloads
Microsoft Active Directory su AWS per supportare i tuoi Windows Workloads
 
Computer Vision con AWS
Computer Vision con AWSComputer Vision con AWS
Computer Vision con AWS
 
Database Oracle e VMware Cloud on AWS i miti da sfatare
Database Oracle e VMware Cloud on AWS i miti da sfatareDatabase Oracle e VMware Cloud on AWS i miti da sfatare
Database Oracle e VMware Cloud on AWS i miti da sfatare
 
Crea la tua prima serverless ledger-based app con QLDB e NodeJS
Crea la tua prima serverless ledger-based app con QLDB e NodeJSCrea la tua prima serverless ledger-based app con QLDB e NodeJS
Crea la tua prima serverless ledger-based app con QLDB e NodeJS
 
API moderne real-time per applicazioni mobili e web
API moderne real-time per applicazioni mobili e webAPI moderne real-time per applicazioni mobili e web
API moderne real-time per applicazioni mobili e web
 
Database Oracle e VMware Cloud™ on AWS: i miti da sfatare
Database Oracle e VMware Cloud™ on AWS: i miti da sfatareDatabase Oracle e VMware Cloud™ on AWS: i miti da sfatare
Database Oracle e VMware Cloud™ on AWS: i miti da sfatare
 
Tools for building your MVP on AWS
Tools for building your MVP on AWSTools for building your MVP on AWS
Tools for building your MVP on AWS
 
How to Build a Winning Pitch Deck
How to Build a Winning Pitch DeckHow to Build a Winning Pitch Deck
How to Build a Winning Pitch Deck
 
Building a web application without servers
Building a web application without serversBuilding a web application without servers
Building a web application without servers
 
Fundraising Essentials
Fundraising EssentialsFundraising Essentials
Fundraising Essentials
 
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
 
Introduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container ServiceIntroduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container Service
 

Build Enterprise-Grade Serverless Apps - SRV315 - Chicago AWS Summit

  • 1. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. George Mao Specialist Solutions Architect, Serverless Amazon Web Services Building Enterprise-Grade Serverless Apps SRV315
  • 2. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Customers innovating with AWS Lambda
  • 3. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Why are customers choosing Lambda & Serverless? iRobot does >1,000 Lambda deployments a day for its serverless IoT backend that runs internet connected-vacuums, with 2M connected robots by 2018 (FY17 projected). Fannie Maeis replacing on-premises data centers with a Lambda-based solution that can run a Monte Carlo simulation on 20M mortgage calculations in 1.5 hours. Nextdoor replaced its Apache Flume platform with a serverless data ingestion pipeline that handles 3B events daily. HomeAwayuses Lambda to process and prepare 6M user- uploaded photos a month for its vacation rental marketplace. Agero’saccident detection and driver behavior analysis platform handles over 1B Lambda requests each month and scales to handle 20x at peak load. Revvelreduced video transcoding time by >95% at a fraction of the cost of transcoding videos on server-based solutions.
  • 4. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Stack Overflow Developer Survey 2018 *https://insights.stackoverflow.com/survey/2018/
  • 5. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Key Industry Trends Don’t code it yourself! The Rise of Managed Services Stream processing and “embarrassingly parallel” computing Snowballing adoption of microservices Serverless, event-driven architectures
  • 6. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Lambda Means… No Server Management Flexible Scaling No Idle Capacity $ High Availability
  • 7. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Agenda: 6 ways to improve your serverless mojo 1. Think in patterns: the serverless architecture playbook 2. Use APIs effectively 3. SecOps like you mean it: permissions & privileges 4. Software lifecycle: from coding to deployment 5. Think in apps 6. When things go wrong: Error-handling and diagnostics
  • 8. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. 1. Serverless Patterns: Managed services + Lambda functions
  • 9. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Managed services as building blocks Amazon SNS Amazon SQS Amazon S3 Messaging Monitoring and Debugging Storage AWS X-Ray AWS Lambda Amazon API Gateway Orchestration API Proxy Compute AWS Step Functions Amazon DynamoDB Amazon Kinesis Analytics Database Edge Compute AWS Greengrass Lambda@Edge Amazon Athena Amazon Aurora Serverless (coming soon)
  • 10. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS Lambda Compute Example: Serverless analytics Amazon Kinesis Analytics Amazon Athena
  • 11. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Amazon API Gateway API Proxy AWS Lambda Compute Amazon S3 Storage Example: Serverless web app Amazon DynamoDB Database Amazon Aurora Serverless (coming soon) Static Content Dynamic Content API Serving
  • 12. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Patterns for the Cloud Era • Media transform on upload: Amazon S3 event + Lambda • NoSQL data cleansing: Amazon DynamoDB change streams + Lambda • Serverless website: Amazon S3 + Amazon DynamoDB + Amazon API Gateway + Lambda • Click-stream analytics: Amazon Kinesis Data Firehose + Lambda • Ordered event processing: Kinesis + Lambda • Multi-function fanout: Amazon SNS (or Lambda) + Lambda • Workflows: AWS Step Functions + Lambda • Event distribution: Amazon CloudWatch Events + Lambda • Serverless cron jobs: CloudWatch timer events + Lambda • GraphQL actions: AWS AppSync + Lambda • On-the-fly image resizing: AWS Lambda@Edge + Amazon CloudFront • Email rules: Amazon SES + Lambda • Configuration policy enforcement: AWS Config + Lambda • Stored procedures: Amazon Aurora + Lambda • Custom authorizers for APIs: API Gateway auth + Lambda • DevOps choreography: CloudWatch alarms + Lambda • Alexa skills: Amazon Alexa + Lambda • Chatbots: Slack + Amazon Lex + Lambda • IoT automation: AWS IoT + Lambda • Smart devices: AWS Greengrass + Lambda • On-premises file encrypt for transit: AWS Snowball Edge + Lambda • …
  • 13. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Meta-patterns 1. Service pushes async event to Lambda (Amazon S3, Amazon SNS) 2. Lambda grabs event from service (Amazon DynamoDB, Amazon Kinesis) 3. Synchronous exchange (Amazon Alexa, Amazon Lex) 4. Batch transform (Amazon Kinesis Data Firehose) 5. Microservice (API + Lambda + your choice of DB) 6. Customization via functions (AWS Config, Amazon SES rules) 7. Data-driven fanout (S3-Lambda, Lambda-Lambda) 8. Choreography (AWS Step Functions + Lambda) 9. Lambda functions in devices (AWS Greengrass, AWS Snowball Edge)
  • 14. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. ICYMI: Amazon SQS as a built-in Lambda event source is live!
  • 15. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Patterns: Best practices • Don’t reinvent the wheel – use managed services when possible • …and stay current ☺ • Keep events inside AWS services for as long as possible: • Example: • Amazon S3 → client → Lambda • Amazon S3 → Lambda • Verify limits end-to-end • Prefer idempotent, stateless functions, and when you can’t… • Use AWS Step Functions if you need stateful control (retries, long-running)
  • 16. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. 2. Use APIs Effectively
  • 17. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Resources: GetFunction: Type: AWS::Serverless::Function Properties: Handler: index.get Runtime: nodejs6.10 CodeUri: s3://bucket/api_backend.zip Policies: AmazonDynamoDBReadOnlyAccess Environment: Variables: TABLE_NAME: !Ref Table Events: GetResource: Type: Api Properties: Path: /resource/{resourceId} Method: get Start Simple! Meet AWS SAM!
  • 18. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Extend with Swagger AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Resources: Api: Type: AWS::Serverless::Api Properties: StageName: prod DefinitionUri: swagger.yml --- swagger: "2.0" info: version: "2018-06-06T01:36:07Z" title: "PetStore" host: "0ftv5igkjd.execute-api.us-east- 1.amazonaws.com" basePath: "/test" schemes: - "https" paths: /: get: consumes: - "application/json" produces: - "text/html" responses: 200: description: "200 response" headers: Content-Type: type: "string"
  • 19. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Choose the right API Endpoints • Edge optimized: Designed for geographically diverse clients, uses integrated CloudFront to enable clients to connect to the closest PoP • Regional: Designed for EC2 clients, within the same region as the API • Private: Designed for VPC only access, with no internet access needed. (Uses AWS PrivateLink VPC endpoint)
  • 20. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Manage throttling and rate-limiting • Protect backends with method level rate-limiting • Protect clients from aggressive use using Usage plans • Limit on RPS • Limit on requests per day/week/month
  • 21. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. ICYMI – Summary of recent API Gateway launches • Fine-grained (method-level) throttling • Overrides on request/response parameters and response status • Higher limits on APIs and resource change rates • 600 APIs (regional or private endpoint) • 120 APIs (edge-optimized) • Available in AWS China Ningxia region • Resource policies and cross-account access enabled
  • 22. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. 3. Security and AuthZ
  • 23. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Serverless apps can be the most secure apps, if… …you use the tools provided correctly: • Secure - Resource policies (Lambda & API GW) - Custom authorizers (API GW) - Execution roles (Lambda) • Audit - AWS Config policies - AWS CloudTrail traces
  • 24. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Full circle of protection Limit Access Limit rights Secure credentials Audit access Enforce policies
  • 25. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Limit access: Resource policies and custom authorizers Analogy: Who would I invite into my house?
  • 26. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Limit access: Resource policies and custom authorizers
  • 27. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Limit access: Resource policies and custom authorizers
  • 28. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Limits rights: Execution and invocation roles Analogy: What do I let my kids play with?
  • 29. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Limit rights: Execution and invocation roles
  • 30. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Limit rights: Execution and invocation roles
  • 31. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Keeping track: Auditing and Config Policies • Use AWS CloudTrail to track API and function management (creation, deletion, retrieval, etc.) • Can also audit function invocation for Lambda • Run queries against CloudTrail data using Amazon Athena • Or build a simple analysis engine using Lambda functions • Use AWS Config to continuously monitor and enforce policies • For example: Enforcing Lambda function policies do not have public access
  • 32. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS Config: Detect Public Access and react!
  • 33. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Calling Third Party Services Securely AWS Secrets Manager • Securely store, retrieve, and manage database credentials, API keys, and other secrets for AWS or third-party systems • Rotate, audit, and version secrets • Built-in support for MySQL, PostgreSQL, and Amazon Aurora on Amazon RDS • Supports both default and custom KMS keys • Avoid cleartext secrets in Lambda env vars or code!
  • 34. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. 4. Building, Testing, and Deploying Serverless Apps
  • 35. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS CodePipeline AWS Code Suite AWS CodeCommit or GitHub AWS CodeBuild (build) AWS CodeBuild (test) AWS CloudFormation (deploy) AWS CodeDeploy (rollout) AWS Cloud9 Editor AWS CodeStar
  • 36. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Best Practices for Serverless Development • CI/CD pipeline for apps (including repo publishing!) • Test and debug locally • AWS CloudFormation can deploy to multiple regions • Useful for multi-region APIs • Deploy incrementally for safety • Weighted aliases in Lambda • Canary stages in API Gateway • AWS CodeDeploy can automate AWS SAM app deploys (including rollback)
  • 37. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Local test, build, & debug with AWS SAM CLI • AWS SAM = AWS Serverless Application Model • Copy of the Lambda execution environment • Powers local test/debug • Models serverless applications • Works in IDEs, command line, etc. • Use “sam init” to create a new project • Open source!
  • 38. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. 5. It’s All about [Serverless] Apps
  • 39. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS Serverless Application Repository Customize and create directly from the Lambda console, command line, or SDK • Publish and share apps three ways… • Within your AWS account • Across accounts • With everyone (public access) • Based on AWS SAM – simple model of your serverless application • Deploys using CloudFormation (use anywhere AWS CloudFormation works!)
  • 40. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Growing Set of App Producers
  • 41. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. 6. When Things Go Wrong: Error-Handling and Diagnostics
  • 42. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. CloudWatch metrics • API Calls Count, • Latency, • 4XXs, 5XXs, • Integration Latency, • Cache Hit Count, • Cache Miss Count API Gateway • Invocation Count, • Invocation duration, • Invocation errors, • Throttled Invocation, • Iterator Age, • DLQ Errors, • Concurrency Lambda
  • 43. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  • 44. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. API Gateway CloudWatch Logs API Gateway Execution Logging Two levels of logging, error and info Optionally log method request/body content Set globally in stage, or override per method API Gateway Access Logging Details about *who* accessed your API IP, HttpMethod, User, Protocol, Time Customizable format for machine parsable logs
  • 45. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. API Gateway Custom Access Logging
  • 46. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. The Lambda function request Lifecycle 1. Download your code (as a SquashFS filesystem) 2. Start the language runtime 3. Load your code (e.g., class loading in Java) 4. Run “init” code (e.g., static initializers in Java) 5. Process the request warm
  • 47. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Same View in AWS X-Ray
  • 48. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Things You Can Track in X-Ray for Lambda • Cold vs warm starts • Async dwell time (time event spends in queue) • Duration of calls to other AWS services (and with a little work to add trace points, third-party services) • Errors and throttles from AWS service calls Lots of great third-party offerings can also help!
  • 49. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Making Cold Starts More Efficient • Control the dependencies in your function's deployment package • Tree shake your Java code! (Hint: Spring is expensive ) • Can combine ‘cold’ and ‘hot’ functions • Optimize for your language, where applicable… • Node – Browserfy, Minify • AWS Java v2 SDK (preview) • Only use VPC if you need access to a resource there! • Delay loading where possible
  • 50. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Summary: 6 ways to improve your serverless mojo 1. Think in patterns: the serverless architecture playbook 2. Use APIs effectively 3. SecOps like you mean it: permissions & privileges 4. Software lifecycle: from coding to deployment 5. Think in apps 6. When things go wrong: Error-handling and diagnostics
  • 51. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Speaker Info / Social Media Channels George Mao Serverless Specialist Solutions Architect georgemao@ http://aws.amazon.com/serverless/ https://github.com/aws-samples/ https://github.com/awslabs
  • 52. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Submit session feedback 1. Tap the Schedule icon. 2. Select the session you attended. 3. Tap Session Evaluation to submit your feedback.
  • 53. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Thank you!