Primeros pasos en desarrollo
serverless
Javier Ramírez
Developer Advocate - Amazon Web Services
@supercoco9 ramirez
We are witnessing a paradigm shift
Experiment,
innovate
more often
Release
features
faster
Build better
products
Focus on
business
logic
Decouple
software
systems
Win
customers
Win
customers
75% of organizations use or plan to use serverless
technologies within the next two years.1
* 451 Research, The Journey to Serverless-First: Enterprise Stories
https://aws.amazon.com/resources/analyst-reports/451-serverless-first-enterprises-on-aws/
Sumo Logic’s analysis of its AWS customers’ activities found a modest increase in
those running Lambdas, going from 36% in 2019 to 39% in 2020. In early 2020,
Datadog reported that more than 40% of its AWS customers had adopted Lambda,
with that figure almost doubling among AWS customers that also used containers.
https://thenewstack.io/adoption-of-aws-lambda-serverless-stalls/
https://www.sumologic.com/brief/continuous-intelligence-report/
Development transformation at Amazon (and everywhere else)
1994-2001 2002+
Monolithic architecture +
hierarchical organization
Decoupled services +
Two-pizza teams
Amazon S3 at launch:
Amazon S3 @ re:Invent 2018:
In 2020 S3 stored over 100 trillion (1014,
or 100,000,000,000,000) objects, and
regularly peaks at tens of millions of
requests per second.
Deployment at scale
1000s of
teams
Micro-
services
CI/CD Serverless
>60 million deployments a year*
Computing evolution – A paradigm shift
LEVEL
OF
ABSTRACTION
FOCUS ON BUSINESS LOGIC
PHYSICAL MACHINES
Requires “guess” planning
Lives for years on-premises
Heavy investments (capex)
Low innovation factor
Deploy in months
Computing evolution – A paradigm shift
LEVEL
OF
ABSTRACTION
FOCUS ON BUSINESS LOGIC
VIRTUAL MACHINES
Hardware independence
Faster provisioning speed (minutes/hours)
Trade capex for opex
More scale
Elastic resources
Faster speed and agility
Reduced maintenance
Computing evolution – A paradigm shift
LEVEL
OF
ABSTRACTION
FOCUS ON BUSINESS LOGIC
CONTAINERIZATION
Platform independence
Consistent runtime environment
Higher resource utilization
Easier and faster deployments
Isolation and sandboxing
Start speed (deploy in seconds)
No server is easier to manage than
"no server.”
Werner Vogels—Amazon CTO
Computing evolution – A paradigm shift
AWS Lambda
AWS Fargate
LEVEL
OF
ABSTRACTION
FOCUS ON BUSINESS LOGIC
Continuous scaling
Fault tolerance built-in
Pay for value
Zero maintenance
SERVERLESS
AWS operational responsibility models
On-Premises Cloud
Less More
Compute Virtual Machine
EC2 Elastic Beanstalk AWS Lambda
Fargate
Databases MySQL MySQL on EC2
RDS MySQL RDS Aurora Aurora Serverless DynamoDB
Storage Storage
S3
Messaging ESBs
Amazon MQ Kinesis SQS / SNS
Analytics
Hadoop Hadoop on EC2 EMR Elasticsearch Service Athena
Serverless means …
No servers to provision
or manage
Scales with usage
Never pay for idle Availability and fault
tolerance built in
AWS approach to reliability
Serverless means:
Greater agility
Less overhead
Better focus
Increased scale
More flexibility
Faster time to market
AWS Serverless Portfolio (some missing services)
APPLICATION PRIMITIVES – COMPUTE AND DATASTORES
AWS
Lambda
AWS
Fargate
Amazon
API Gateway
Amazon
SNS
Amazon
MQ
Amazon
SQS
AWS
Step Functions
APPLICATION INTEGRATION
DEVELOPER TOOLS
SECURITY AND ADMINISTRATION
Amazon Aurora
Serverless
Amazon
S3
Amazon
DynamoDB
AWS
AppSync
AWS
IAM
Amazon
Cognito
Amazon
Inspector
Amazon
VPC
Amazon
GuardDuty
AWS
CloudFormation
AWS
Cloud9
AWS
CloudTrail
Amazon
CloudWatch
AWS
X-Ray
AWS
CodePipeline
AWS
Config
AWS
SSO
AWS
Shield
AWS
WAF
Amazon
Kinesis
AWS Serverless
Application
Repository
Amazon
EventBridge
ANALYTICS
Amazon
Athena
AWS
Glue
AWS Glue
Elastic Views
AWS Glue
DataBrew
Amazon
Kinesis
Amazon
Quicksight
Amazon
Timestream
Introduction to AWS Lambda
• Function-as-a-Service
• Run code without provisioning or managing servers
• Pay only for the compute time you consume
• Automatically runs your code with high availability
• Scale with usage
Lambda handles
• Load balancing
• Auto scaling
• Handling failures
• Security isolation
• OS management
• Managing utilization
(and many other things) for you
Comparison of operational responsibility
AWS Lambda
Serverless functions
AWS Fargate
Serverless containers
ECS/EKS
Container-management as a service
EC2
Infrastructure-as-a-Service
More opinionated
Less opinionated
AWS manages Customer manages
• Data source integrations
• Physical hardware, software, networking,
and facilities
• Provisioning
• Application code
• Container orchestration, provisioning
• Cluster scaling
• Physical hardware, host OS/kernel,
networking, and facilities
• Application code
• Data source integrations
• Security config and updates, network config,
management tasks
• Container orchestration control plane
• Physical hardware software, networking,
and facilities
• Application code
• Data source integrations
• Work clusters
• Security config and updates, network config,
firewall, management tasks
• Physical hardware software,
networking, and facilities
• Application code
• Data source integrations
• Scaling
• Security config and updates, network config,
management tasks
• Provisioning,managing scaling and
patching of servers
Customer uses cases: Lambda at scale
processes 4,000 requests
per second
processes half a trillion
validations of stock trades daily
triggers 1.2 billion Lambda
requests each month
Scaled up to 20,000
concurrent Lambda executions
in testing
Anatomy of a Lambda Function
Serverless applications
AWS
Lambda
Serverless applications
Function
Node.js
Python
Java
C#
Go
Ruby
PowerShell
Runtime API
Serverless Applications
Event source Function
Node.js
Python
Java
C#
Go
Ruby
PowerShell
Runtime API
Changes in
data state
Requests to
endpoints
Changes in
Resource state
AWS Lambda integrations
https://docs.aws.amazon.com/lambda/lates
t/dg/lambda-services.html#intro-core-
components-event-sources
Serverless Applications
Event source Services
Changes in
data state
Requests to
endpoints
Changes in
Resource state
Function
Node.js
Python
Java
C#
Go
Ruby
PowerShell
Runtime API
Lambda Execution Models
Synchronous
(push)
Asynchronous
(event)
Stream
(Poll-based)
Amazon
DynamoDB
Amazon
SNS
/order
Amazon
S3
reqs
Amazon
Kinesis
changes
AWS Lambda
service
Amazon API
Gateway
Lambda
function
Lambda
function
function
Dead-Letter Queue
• Asynchronous Lambda invocations are retried two more
times (3 times total)
• Lambda can forward payloads that were not processed
to a dead-letter queue (IF configured!)
• A mechanism to handle exceptions and failures
gracefully
Monitoring and debugging Lambda functions
• AWS Lambda console includes a dashboard for functions
• Lists all Lambda functions
• Easy editing of resources, event sources and other settings
• At-a-glance metrics
• Metrics automatically reported to Amazon CloudWatch for each Lambda
function
• Requests
• Errors
• Latency
• Throttles
AWS X-Ray
Profile and troubleshoot
serverless applications:
• Lambda instruments
incoming requests for all
supported languages and can
capture calls made in code
• API Gateway inserts a tracing
header into HTTP calls as
well as reports data back to
X-Ray itself
var AWSXRay = require(‘aws-xray-sdk-core‘);
var AWS = AWSXRay.captureAWS(require(‘aws-sdk’));
S3Client = AWS.S3();
Anatomy of a Lambda Function
Handler() function
Function to be executed upon
invocation
Event object
Data sent during Lambda
function Invocation
Context object
Methods available to interact
with runtime information
(request ID, log group, more)
import json
def lambda_handler(event, context):
# TODO implement
return {
'statusCode': 200,
'body': json.dumps('Hello World!')
}
Lambda Layers
Lets functions easily share code: Upload layer
once, reference within any function
Promote separation of responsibilities, lets
developers iterate faster on writing business logic
Built in support for secure sharing by ecosystem
Lambda Layers: Uses cases
• Custom code, that is used by more than one function
• Libraries, modules, frameworks to simplify the
implementation of your business logic
• Security/monitoring service
• Shared code that does not change frequently
• Bring your own Runtime
• C++
• Rust
• PHP
Fine-grained Pricing
Buy compute time in 1ms
increments
Low request charge
No hourly, daily, or monthly
minimums
No per-device fees
Never pay for idle
Free Tier
1M requests and 400,000 GBs of compute.
Every month, every customer.
Let’s see this in action
AWS Compute Offerings
Service
I want to
configure
servers, storage,
networking, and
my OS
I want to run
servers,
configure
applications, and
control scaling
Run my code
when it’s
needed
How do I
choose?
Amazon EC2 Amazon ECS AWS Lambda
AWS Fargate
I want to run my
containers
Serverless compute engine
for containers
Long-running
Bring existing code
Fully-managed orchestration
AWS Fargate
The two Serverless compute options
Serverless event-driven
code execution
Short-lived
All language runtimes
Data source integrations
AWS Lambda
Picking a Compute Platform: Containers vs. Lambda
10 GB
But distributed systems can be harder
to coordinate and debug
Orchestration for serverless apps
“I want to sequence functions”
“I want to select functions based on data”
“I want to run functions in parallel”
“I want to retry functions”
“I want to try/catch/finally”
“I want to run code for hours”
AWS Step Functions
AWS Step Functions
Visualize in the
Console
Define in JSON Monitor
Executions
Easily coordinate multiple Lambda functions using visual workflows
Processing a new bank account application
requires some service coordination
Data
checking
Verify identity documents
Check address
Human review
List flagged applications
Handle human decisions
Account applications
Accept new application
Consolidate data checks
Human review?
Approve or reject
Example workflow:
opening an account
Wait for a callback
Parallel steps
Branching choice
Tasks
There are still a lot of things to think about
• Deployment and Infrastructure as code
• Secrets/configuration management
• Simplifying code management
• Debugging/troubleshooting
• Performance controls
• Security
X-Ray trace example
Para saber más
• https://aws.amazon.com/serverless
• https://bit.ly/ServerlessWorkshopIL
• https://step-functions-workshop.go-aws.com/
Gracias
Javier Ramírez
Developer Advocate - Amazon Web Services
@supercoco9 ramirez

Primeros pasos en desarrollo serverless

  • 1.
    Primeros pasos endesarrollo serverless Javier Ramírez Developer Advocate - Amazon Web Services @supercoco9 ramirez
  • 2.
    We are witnessinga paradigm shift Experiment, innovate more often Release features faster Build better products Focus on business logic Decouple software systems Win customers Win customers 75% of organizations use or plan to use serverless technologies within the next two years.1 * 451 Research, The Journey to Serverless-First: Enterprise Stories https://aws.amazon.com/resources/analyst-reports/451-serverless-first-enterprises-on-aws/
  • 3.
    Sumo Logic’s analysisof its AWS customers’ activities found a modest increase in those running Lambdas, going from 36% in 2019 to 39% in 2020. In early 2020, Datadog reported that more than 40% of its AWS customers had adopted Lambda, with that figure almost doubling among AWS customers that also used containers. https://thenewstack.io/adoption-of-aws-lambda-serverless-stalls/ https://www.sumologic.com/brief/continuous-intelligence-report/
  • 4.
    Development transformation atAmazon (and everywhere else) 1994-2001 2002+ Monolithic architecture + hierarchical organization Decoupled services + Two-pizza teams
  • 5.
    Amazon S3 atlaunch:
  • 6.
    Amazon S3 @re:Invent 2018: In 2020 S3 stored over 100 trillion (1014, or 100,000,000,000,000) objects, and regularly peaks at tens of millions of requests per second.
  • 7.
    Deployment at scale 1000sof teams Micro- services CI/CD Serverless >60 million deployments a year*
  • 8.
    Computing evolution –A paradigm shift LEVEL OF ABSTRACTION FOCUS ON BUSINESS LOGIC PHYSICAL MACHINES Requires “guess” planning Lives for years on-premises Heavy investments (capex) Low innovation factor Deploy in months
  • 9.
    Computing evolution –A paradigm shift LEVEL OF ABSTRACTION FOCUS ON BUSINESS LOGIC VIRTUAL MACHINES Hardware independence Faster provisioning speed (minutes/hours) Trade capex for opex More scale Elastic resources Faster speed and agility Reduced maintenance
  • 10.
    Computing evolution –A paradigm shift LEVEL OF ABSTRACTION FOCUS ON BUSINESS LOGIC CONTAINERIZATION Platform independence Consistent runtime environment Higher resource utilization Easier and faster deployments Isolation and sandboxing Start speed (deploy in seconds)
  • 11.
    No server iseasier to manage than "no server.” Werner Vogels—Amazon CTO
  • 12.
    Computing evolution –A paradigm shift AWS Lambda AWS Fargate LEVEL OF ABSTRACTION FOCUS ON BUSINESS LOGIC Continuous scaling Fault tolerance built-in Pay for value Zero maintenance SERVERLESS
  • 13.
    AWS operational responsibilitymodels On-Premises Cloud Less More Compute Virtual Machine EC2 Elastic Beanstalk AWS Lambda Fargate Databases MySQL MySQL on EC2 RDS MySQL RDS Aurora Aurora Serverless DynamoDB Storage Storage S3 Messaging ESBs Amazon MQ Kinesis SQS / SNS Analytics Hadoop Hadoop on EC2 EMR Elasticsearch Service Athena
  • 14.
    Serverless means … Noservers to provision or manage Scales with usage Never pay for idle Availability and fault tolerance built in
  • 15.
    AWS approach toreliability
  • 16.
    Serverless means: Greater agility Lessoverhead Better focus Increased scale More flexibility Faster time to market
  • 17.
    AWS Serverless Portfolio(some missing services) APPLICATION PRIMITIVES – COMPUTE AND DATASTORES AWS Lambda AWS Fargate Amazon API Gateway Amazon SNS Amazon MQ Amazon SQS AWS Step Functions APPLICATION INTEGRATION DEVELOPER TOOLS SECURITY AND ADMINISTRATION Amazon Aurora Serverless Amazon S3 Amazon DynamoDB AWS AppSync AWS IAM Amazon Cognito Amazon Inspector Amazon VPC Amazon GuardDuty AWS CloudFormation AWS Cloud9 AWS CloudTrail Amazon CloudWatch AWS X-Ray AWS CodePipeline AWS Config AWS SSO AWS Shield AWS WAF Amazon Kinesis AWS Serverless Application Repository Amazon EventBridge ANALYTICS Amazon Athena AWS Glue AWS Glue Elastic Views AWS Glue DataBrew Amazon Kinesis Amazon Quicksight Amazon Timestream
  • 18.
    Introduction to AWSLambda • Function-as-a-Service • Run code without provisioning or managing servers • Pay only for the compute time you consume • Automatically runs your code with high availability • Scale with usage
  • 19.
    Lambda handles • Loadbalancing • Auto scaling • Handling failures • Security isolation • OS management • Managing utilization (and many other things) for you
  • 20.
    Comparison of operationalresponsibility AWS Lambda Serverless functions AWS Fargate Serverless containers ECS/EKS Container-management as a service EC2 Infrastructure-as-a-Service More opinionated Less opinionated AWS manages Customer manages • Data source integrations • Physical hardware, software, networking, and facilities • Provisioning • Application code • Container orchestration, provisioning • Cluster scaling • Physical hardware, host OS/kernel, networking, and facilities • Application code • Data source integrations • Security config and updates, network config, management tasks • Container orchestration control plane • Physical hardware software, networking, and facilities • Application code • Data source integrations • Work clusters • Security config and updates, network config, firewall, management tasks • Physical hardware software, networking, and facilities • Application code • Data source integrations • Scaling • Security config and updates, network config, management tasks • Provisioning,managing scaling and patching of servers
  • 21.
    Customer uses cases:Lambda at scale processes 4,000 requests per second processes half a trillion validations of stock trades daily triggers 1.2 billion Lambda requests each month Scaled up to 20,000 concurrent Lambda executions in testing
  • 22.
    Anatomy of aLambda Function
  • 23.
  • 24.
  • 25.
    Serverless Applications Event sourceFunction Node.js Python Java C# Go Ruby PowerShell Runtime API Changes in data state Requests to endpoints Changes in Resource state
  • 26.
  • 27.
    Serverless Applications Event sourceServices Changes in data state Requests to endpoints Changes in Resource state Function Node.js Python Java C# Go Ruby PowerShell Runtime API
  • 28.
  • 29.
    Dead-Letter Queue • AsynchronousLambda invocations are retried two more times (3 times total) • Lambda can forward payloads that were not processed to a dead-letter queue (IF configured!) • A mechanism to handle exceptions and failures gracefully
  • 30.
    Monitoring and debuggingLambda functions • AWS Lambda console includes a dashboard for functions • Lists all Lambda functions • Easy editing of resources, event sources and other settings • At-a-glance metrics • Metrics automatically reported to Amazon CloudWatch for each Lambda function • Requests • Errors • Latency • Throttles
  • 31.
    AWS X-Ray Profile andtroubleshoot serverless applications: • Lambda instruments incoming requests for all supported languages and can capture calls made in code • API Gateway inserts a tracing header into HTTP calls as well as reports data back to X-Ray itself var AWSXRay = require(‘aws-xray-sdk-core‘); var AWS = AWSXRay.captureAWS(require(‘aws-sdk’)); S3Client = AWS.S3();
  • 32.
    Anatomy of aLambda Function Handler() function Function to be executed upon invocation Event object Data sent during Lambda function Invocation Context object Methods available to interact with runtime information (request ID, log group, more) import json def lambda_handler(event, context): # TODO implement return { 'statusCode': 200, 'body': json.dumps('Hello World!') }
  • 33.
    Lambda Layers Lets functionseasily share code: Upload layer once, reference within any function Promote separation of responsibilities, lets developers iterate faster on writing business logic Built in support for secure sharing by ecosystem
  • 34.
    Lambda Layers: Usescases • Custom code, that is used by more than one function • Libraries, modules, frameworks to simplify the implementation of your business logic • Security/monitoring service • Shared code that does not change frequently • Bring your own Runtime • C++ • Rust • PHP
  • 35.
    Fine-grained Pricing Buy computetime in 1ms increments Low request charge No hourly, daily, or monthly minimums No per-device fees Never pay for idle Free Tier 1M requests and 400,000 GBs of compute. Every month, every customer.
  • 36.
  • 37.
    AWS Compute Offerings Service Iwant to configure servers, storage, networking, and my OS I want to run servers, configure applications, and control scaling Run my code when it’s needed How do I choose? Amazon EC2 Amazon ECS AWS Lambda AWS Fargate I want to run my containers
  • 38.
    Serverless compute engine forcontainers Long-running Bring existing code Fully-managed orchestration AWS Fargate The two Serverless compute options Serverless event-driven code execution Short-lived All language runtimes Data source integrations AWS Lambda
  • 39.
    Picking a ComputePlatform: Containers vs. Lambda 10 GB
  • 40.
    But distributed systemscan be harder to coordinate and debug
  • 41.
    Orchestration for serverlessapps “I want to sequence functions” “I want to select functions based on data” “I want to run functions in parallel” “I want to retry functions” “I want to try/catch/finally” “I want to run code for hours” AWS Step Functions
  • 42.
    AWS Step Functions Visualizein the Console Define in JSON Monitor Executions Easily coordinate multiple Lambda functions using visual workflows
  • 43.
    Processing a newbank account application requires some service coordination Data checking Verify identity documents Check address Human review List flagged applications Handle human decisions Account applications Accept new application Consolidate data checks Human review? Approve or reject
  • 44.
    Example workflow: opening anaccount Wait for a callback Parallel steps Branching choice Tasks
  • 45.
    There are stilla lot of things to think about • Deployment and Infrastructure as code • Secrets/configuration management • Simplifying code management • Debugging/troubleshooting • Performance controls • Security
  • 46.
  • 47.
    Para saber más •https://aws.amazon.com/serverless • https://bit.ly/ServerlessWorkshopIL • https://step-functions-workshop.go-aws.com/
  • 49.
    Gracias Javier Ramírez Developer Advocate- Amazon Web Services @supercoco9 ramirez