getting started with aws lambda and the serverless cloud
TRANSCRIPT
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Vyom Nagrani, Manager Product Management, AWS Lambda
Ben Kehoe, Cloud Robotics Research Scientist at iRobot
AWS Santa Clara Summit, July 13th, 2016
Getting Started with AWS Lambda
and the Serverless Cloud
AWS Compute offerings
VM App Function
Service EC2 ECS Lambda
H/W OS Runtime
Unit of scale
Level of
abstraction
AWS compute offerings
I want to
configure
machines,
storage,
networking,
and my OS
I want to run
servers,
configure
applications,
and control
scaling
Run my
code when
it’s needed
Service EC2 ECS Lambda
How do I
choose?
Agenda
• Why AWS Lambda
• How it works
• Use cases
• Sample architecture
• Customer success story
• Best practices
Why AWS Lambda
ServersHow will the application
handle server hardware failure?
How can I control
access from my servers?
When should I decide to
scale out my servers?
When should I decide to
scale up my servers?
What size servers are
right for my budget?
How much remaining
capacity do my servers have?
(AAHHHHHHHHH!!)
Operations and management Scaling
Provisioning and utilization Availability and fault tolerance
Owning servers means dealing with ...
Serverless compute: AWS Lambda
COMPUTE SERVICE
EVENT-DRIVEN
Run arbitrary
code without
managing
servers
Code only runs
when it needs to
run
AWS Lambda: Run code in response to events
Lambda functions: Stateless, trigger-based code execution
Triggered by events:
• Direct sync and async API calls
• AWS service integrations
• Third-party triggers
• Many more …
Makes it easy to:
• Perform data-driven auditing, analysis, and notification
• Build back-end services that perform at scale
Cost-effective and
efficient
No infrastructure
to manage
Pay only for what you use
Bring your
own code
Productivity-focused compute platform to build powerful, dynamic, modular
applications in the cloud
Run code in standard
languages
Focus on business logic
Benefits of AWS Lambda
1 2 3
How it works
Using AWS Lambda
Bring your own code
• Node.js, Java, Python
• Bring your own libraries
(even native ones)
Simple resource model
• Select power rating from
128 MB to 1.5 GB
• CPU and network
allocated proportionately
Flexible use
• Synchronous or
asynchronous
• Integrated with other
AWS services
Flexible authorization
• Securely grant access to
resources and VPCs
• Fine-grained control for
invoking your functions
Using AWS Lambda
Authoring functions
• WYSIWYG editor or
upload packaged .zip
• Third-party plugins
(Eclipse, Visual Studio)
Monitoring and logging
• Metrics for requests,
errors, and throttles
• Built-in logs to Amazon
CloudWatch Logs
Programming model
• Use processes, threads,
/tmp, sockets normally
• AWS SDK built in
(Python and Node.js)
Stateless
• Persist data using
external storage
• No affinity or access to
underlying infrastructure
Application components for serverless apps
EVENT SOURCE FUNCTION SERVICES (ANYTHING)
Changes in
data state
Requests to
endpoints
Changes in
resource state
Node
Python
Java
… more coming soon
Amazon
S3
Amazon
DynamoDB
Amazon
Kinesis
AWS
CloudFormation
AWS
CloudTrail
Amazon
CloudWatch
Amazon
SNS
Amazon
SES
Amazon
API Gateway
Amazon
Cognito
AWS
IoT
Amazon
Alexa
Cron events
DATA STORES ENDPOINTS
REPOSITORIES EVENT/MESSAGE SERVICES
Event sources that integrate with AWS Lambda
… and the list will continue to grow!
Use cases
Analytics
• Operational management
• Live dashboards
Data workflows
• Content management
• ETL workflows
Multiple application types
Interactive back ends
• Bots
• Webhooks
Autonomous IT
• Policy engines
• Infrastructure management
Everybody knows this 3-tier web app diagram
https://d0.awsstatic.com/whitepapers/AWS_Serverless_Multi-Tier_Architectures.pdf
Here is what that translates to in real life
http://media.amazonwebservices.com/architecturecenter/AWS_ac_ra_web_01.pdf
Updated real-world “serverless” architecture
https://s3.amazonaws.com/awslambda-reference-architectures/web-app/lambda-refarch-webapp.pdf
Example: Real-time file processing
https://github.com/awslabs/lambda-refarch-fileprocessing
Example: Stream processing
https://github.com/awslabs/lambda-refarch-streamprocessing
Customer success story:
Serverless IoT with AWS
Lambda @iRobot
@ben11kehoe
Ben Kehoe
Cloud Robotics Research Scientist
iRobot
Video stored
separately to make
PPTX size
manageable
Serverless
Functions as a service
• No “instances” of any kind
visible in programming
model
• Scales per request
• Never pay for idle
• Fault-tolerant
Serverless → distributed by nature
Component graph becomes
call graph
Distributed systems thinking is
required from the start
Event-based architecture
Internet of Things
Many autonomous devices in
collaboration
→ distributed
Interacting with the real world
→ event-based
AWS
Lambda
Amazon
DynamoDB
Amazon
Redshift
Amazon
Route 53
Amazon VPC
Amazon
CloudWatch
AWS
CloudFormation
AWS
CloudTrail
AWS
Config
AWS IAMAWS KMSAWS WAF
Amazon
Elasticsearch Service
Amazon
Kinesis
Amazon
QuickSight
Amazon
CloudFront
Amazon S3Amazon
Cognito
Amazon
SNS
Amazon API
Gateway
Amazon
SQS
AWS IoT
How iRobot leverages AWS services to support
our features
Breadth of AWS ecosystem
opens up additional integration
and innovation
Scalability and
global footprint
Mature technology
companies need
flexibility and insight
Long-term technical partnership
AWS benefits
API Gateway
App requests
over HTTPSCRUD
operations
IoT
MQTTCRUD
operations
IoT
MQTT
MQTT
Presigned
URL
Staging
bucket
SQS/CloudWatch Events
CloudWatch event
every 5 minutes
Lambda runs
for 5 minutesSQS queue
Breadth of AWS ecosystem
opens up additional integration
and innovation
Scalability and
global footprint
Mature technology
companies need
flexibility and insight
Long-term technical partnership
AWS benefits (recap)
Best practices
AWS Lambda best practices
Limit your function/code size
Node – remember execution is asynchronous
500 MB /tmp directory provided to each function
Don’t assume function will reuse underlying infrastructure
But take advantage of it when it does occur
You own the logs
Include details from service-provided context
Create custom metrics
Operations-centric vs. business-centric
Best practice: Use versions and aliases
Versions = immutable copies of code + properties
Aliases = mutable pointers to versions
Rollbacks
Staged
promotions
“Lock” behavior
for client
The function networking environment
Default - a default network environment within VPC is provided for you
Access to the Internet always permitted to your function
No access to VPC-deployed assets
Customer VPC - Your function executes within the context of your own VPC
Privately communicate with other resources within your VPC
Familiar configuration and behavior with:
Subnets
Elastic network interfaces (ENIs)
EC2 security groups
VPC route tables
NAT gateway
Additional best practices
Externalize authorization to IAM roles whenever possible
Least privilege and separate IAM roles
Externalize configuration
DynamoDB is great for this
Make sure your downstream setup “keeps up” with Lambda scaling
Limit concurrency when talking to relational databases
Be aware of service throttling
Engage AWS Support to increase your limits
Contact AWS Support before known large scaling events
Takeaways
• Many applications can go serverless
• Data processing, back ends, triggers, web hooks
• Lambda functions are opinionated
• State, invocation modes, and deployments
• The ecosystem continues to grow
• Tooling, languages, and application capabilities
Next steps
1. Go to console.aws.amazon.com/lambda and create
your first Lambda function. (The first 1M requests are
on us!)
2. Stay up to date with AWS Lambda on the Compute blog
and check out aws.amazon.com/lambda for scenarios
and customer stories.
3. Send us your questions, comments, and feedback on
the AWS Lambda Forums.
Remember to complete
your evaluations!