Going Serverless with
AWS
Alex Landa
Services in the Cloud
• Infrastructure (IaaS)
• virtualized basic computing, networking and storage resources.
• EC2, VPC, EBS …
• Platform (PaaS)
• complete development and deployment environment in the cloud
• RDS, ElastiCache, Elastic Beanstalk …
• Software (SaaS) – complete application offered through the
web.
Serverless - don’t think about servers
• A trending execution model in which the server management
and the resource management are completely hidden.
• AWS offers a set of serverless services
• Storage – S3
• DB – DynomoDB
• Queues – SQS, Kinesis
• Notifications – SNS
• Monitoring – CloudWatch
• Compute - Lambda
Used for
• Automation – ”maintenance scripts” for the cloud
• ETL – extraction and transformation layer in front of the
backend services
• External services
• Glue code – connect between several services
• Full blown applications – not the main purpose (yet)
Lambda
• AWS Lambda allows you to define a function that will be
executed when some event happens.
• You do not need to care about the physical execution regarding
resources as AWS Lambda will automatically scale and provide
CPU/Network/IO and Memory for it.
• A major part in a serverless architecture.
Lambda
• The Lambda code you write must be in one of the following
languages:
• Java.
• C#.
• Python.
• Node.js (JavaScript).
• Go
How Does It Work?
• The main component of the Lamda is the handler.
• The point-of-entry.
• When some event happens (more about it in the next slides),
Lamda will create a container ands runs your function there (by
invoking the handler).
• The container may be retain for some time to allow consecutive
executions without paying the bootstrapping price.
• Note that you can’t count on it and a new container may be
created.
Event Sources
• AWS Lambda can connect and be activated by a large variety
of events.
• For example:
• S3 – respond to object_created event.
• SNS – respond to object published on a configured topic.
• API Gateway – wire the Lambda to a REST API.
• CloudWatch Events – respond to object changing state (e.g., EC2
instance state changes).
• You can also invoke the Lambda directly from the CLI or your
application (custom events).
Example HTTP Endpoint
The Container
• Lamda creates a container to run your function.
• When your function exits, the container is frozen for some time
and may be thawed for consecutive execution.
• You are provided with 500MB of /tmp directory which contents
are maintained between invocations.
• Note that you can’t count on it as a new container may be
created for you.
• A good use-case for /tmp is caching.
The Container
• Global objects can be reused and are maintained cross
freeze/thaw.
• For example, static objects in Java.
• In is considered a good practice to try and reuse global
resources (e.g., connection pools).
What about scale?
• Scale in Lambda == “Concurrent Executions”
• Handled by execution pools – 1000 per account, per region
• Can be changed
• If not set function uses “unreserved concurrency pool”
• All specified limits should reach together 900
• 100 reserved for the ”unreserved concurrency”
Throttling
• Behaves differently for synchronous and asynchronous events
• HTTP – synchronous
• S3 trigger – asynchronous
• In case of synchronous - invoking application receives a 429
error
• In case of asynchronous - will automatically retry the invocation
twice, with delays between retries
• If DLQ is configured the failed event will be sent to SNS topic or SQS
Queue
Advanced example
Machine Learning HTTP Endpoint
Logging – CloudWatch
• Lambda integrates with Cloud Watch for logging
• Pushes the logs to /aws/lambda/<function name>
• Common errors:
• permissions denied – modify IAM permission
• timeout exceeded – increase timeout
• memory exceeded - increase memory
• Exception stack trace - go and handle :)
Monitoring – Cloud Watch
• Provides you a full view on the execution metrics
• Number of executions
• Duration
• Failures
• Concurrent executions
• ..
• You should set alarms on those metrics to be notified in case of
unexpected behavior
Serverless != Effortless
• How do we manage all of this?
• Manually – Good for demo and job security, bad for everything else..
• Automatically – using Terraform / CloudFormation + scripts
• Good but requires a lot of knowledge
• Doesn’t solve the debugging
• We want a framework to manage it for us!
Serverless Framework
• Open source CLI for building serverless applications
• Allows you to create, deploy, test , invoke and debug your
serverless services
• Serverless service is composed of :
• Functions – mapped to AWS Lambda
• Resources
• Permissions
Serverless Framework
• Uses serverless.yml to describe the functions of your service
as well as their permissions and dependent resources
• By running serverless deploy it will deploy your changes using
cloud formation
Serverless Framework
Demo
Questions
? ? ? ? ? ? ?
? ? ? ? ? ? ?
? ? ? ? ? ? ?
? ? ? ? ? ? ?

Going serverless with aws

  • 1.
  • 2.
    Services in theCloud • Infrastructure (IaaS) • virtualized basic computing, networking and storage resources. • EC2, VPC, EBS … • Platform (PaaS) • complete development and deployment environment in the cloud • RDS, ElastiCache, Elastic Beanstalk … • Software (SaaS) – complete application offered through the web.
  • 3.
    Serverless - don’tthink about servers • A trending execution model in which the server management and the resource management are completely hidden. • AWS offers a set of serverless services • Storage – S3 • DB – DynomoDB • Queues – SQS, Kinesis • Notifications – SNS • Monitoring – CloudWatch • Compute - Lambda
  • 4.
    Used for • Automation– ”maintenance scripts” for the cloud • ETL – extraction and transformation layer in front of the backend services • External services • Glue code – connect between several services • Full blown applications – not the main purpose (yet)
  • 5.
    Lambda • AWS Lambdaallows you to define a function that will be executed when some event happens. • You do not need to care about the physical execution regarding resources as AWS Lambda will automatically scale and provide CPU/Network/IO and Memory for it. • A major part in a serverless architecture.
  • 6.
    Lambda • The Lambdacode you write must be in one of the following languages: • Java. • C#. • Python. • Node.js (JavaScript). • Go
  • 7.
    How Does ItWork? • The main component of the Lamda is the handler. • The point-of-entry. • When some event happens (more about it in the next slides), Lamda will create a container ands runs your function there (by invoking the handler). • The container may be retain for some time to allow consecutive executions without paying the bootstrapping price. • Note that you can’t count on it and a new container may be created.
  • 8.
    Event Sources • AWSLambda can connect and be activated by a large variety of events. • For example: • S3 – respond to object_created event. • SNS – respond to object published on a configured topic. • API Gateway – wire the Lambda to a REST API. • CloudWatch Events – respond to object changing state (e.g., EC2 instance state changes). • You can also invoke the Lambda directly from the CLI or your application (custom events).
  • 9.
  • 10.
    The Container • Lamdacreates a container to run your function. • When your function exits, the container is frozen for some time and may be thawed for consecutive execution. • You are provided with 500MB of /tmp directory which contents are maintained between invocations. • Note that you can’t count on it as a new container may be created for you. • A good use-case for /tmp is caching.
  • 11.
    The Container • Globalobjects can be reused and are maintained cross freeze/thaw. • For example, static objects in Java. • In is considered a good practice to try and reuse global resources (e.g., connection pools).
  • 12.
    What about scale? •Scale in Lambda == “Concurrent Executions” • Handled by execution pools – 1000 per account, per region • Can be changed • If not set function uses “unreserved concurrency pool” • All specified limits should reach together 900 • 100 reserved for the ”unreserved concurrency”
  • 13.
    Throttling • Behaves differentlyfor synchronous and asynchronous events • HTTP – synchronous • S3 trigger – asynchronous • In case of synchronous - invoking application receives a 429 error • In case of asynchronous - will automatically retry the invocation twice, with delays between retries • If DLQ is configured the failed event will be sent to SNS topic or SQS Queue
  • 14.
  • 15.
    Logging – CloudWatch •Lambda integrates with Cloud Watch for logging • Pushes the logs to /aws/lambda/<function name> • Common errors: • permissions denied – modify IAM permission • timeout exceeded – increase timeout • memory exceeded - increase memory • Exception stack trace - go and handle :)
  • 16.
    Monitoring – CloudWatch • Provides you a full view on the execution metrics • Number of executions • Duration • Failures • Concurrent executions • .. • You should set alarms on those metrics to be notified in case of unexpected behavior
  • 17.
    Serverless != Effortless •How do we manage all of this? • Manually – Good for demo and job security, bad for everything else.. • Automatically – using Terraform / CloudFormation + scripts • Good but requires a lot of knowledge • Doesn’t solve the debugging • We want a framework to manage it for us!
  • 18.
    Serverless Framework • Opensource CLI for building serverless applications • Allows you to create, deploy, test , invoke and debug your serverless services • Serverless service is composed of : • Functions – mapped to AWS Lambda • Resources • Permissions
  • 19.
    Serverless Framework • Usesserverless.yml to describe the functions of your service as well as their permissions and dependent resources • By running serverless deploy it will deploy your changes using cloud formation
  • 20.
  • 21.
    Questions ? ? ?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?