Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
in production
an experience reportan experience report
what you should know before you go to production
ServerlessServerle...
Yan Cui
http://theburningmonk.com
@theburningmonk
Domas Lasauskas
apr, 2016
hey guys, vote on this post
and I’ll announce a winner at
10PM tonight
10PM
traffic
10PM
traffic
70-100x
low utilisation to leave room for spikes
EC2 scaling is slow, so scale earlier
lots of $$$ for unused resources
up to 30 mins for deployment
deployment required downtime
- Dan North
“lead time to someone saying
thank you is the only reputation
metric that matters.”
“what would good
look like for us?”
be small
be fast
have zero downtime
have no lock-step
DEPLOYMENTS SHOULD...
FEATURES SHOULD...
be deployable independently
be loosely-coupled
WE WANT TO...
minimise cost for unused resources
minimise ops effort
reduce tech mess
deliver visible improvements faster
nov, 2016
170 Lambda functions in prod
1.2 GB deployment packages in prod
95% cost saving vs EC2
15x no. of prod releases per month
time
is a good fit
1st function in prod!
time
is a good fit
?
time
is a good fit
1st function in prod!
ALERTING
CI / CD
TESTING
LOGGING
MONITORING
Practices ToolsPrinciples
what is good? how to make it good? with what?
Principles outlast Tools
170 functions
? ?
time
is a good fit
1st function in prod!
SECURITY
DISTRIBUTED TRACING
CONFIG MANAGEMENT
evolving the PLATFORM
rebuilt search
Legacy Monolith Amazon Kinesis Amazon Lambda
Amazon CloudSearch
Legacy Monolith Amazon Kinesis Amazon Lambda
Amazon CloudSearchAmazon API Gateway Amazon Lambda
new analytics pipeline
Legacy Monolith Amazon Kinesis Amazon Lambda
Google BigQuery
Legacy Monolith Amazon Kinesis Amazon Lambda
Google BigQuery
1 developer, 2 days
design production
(his 1st serverless pro...
Legacy Monolith Amazon Kinesis Amazon Lambda
Google BigQuery
“nothing ever got done
this fast at Skype!”
- Chris Twamley
- Dan North
“lead time to someone saying
thank you is the only reputation
metric that matters.”
Rebuilt
with Lambda
Rebuilt
with Lambda
BigQuery
BigQuery
grapheneDB
BigQuery
grapheneDB
BigQuery
grapheneDB
BigQuery
nov, 2016
getting PRODUCTION READY
choose a tried-and-tested
deployment framework,
don’t invent your own
http://serverless.com
https://github.com/awslabs/serverless-application-model
http://apex.run
https://apex.github.io/up
https://github.com/claudiajs/claudia
https://github.com/Miserlou/Zappa
http://gosparta.io/
TESTING
amzn.to/29Lxuzu
Level of Testing
1.Unit
do our objects do the right thing?
are they easy to work with?
Level of Testing
1.Unit
2.Integration
does our code work against code we
can’t change?
handler
handler
test by invoking
the handler
Level of Testing
1.Unit
2.Integration
3.Acceptance
does the whole system work?
Level of Testing
unit
integration
acceptance
feedback
confidence
Don’t Mock Types You Can’t Change
Don’t Mock Types You Can’t Change
Services
Paul Johnston
The serverless approach to
testing is different and may
actually be easier.
http://bit.ly/2t5viwK
LambdaAPI Gateway DynamoDB
LambdaAPI Gateway DynamoDB
Unit Tests
LambdaAPI Gateway DynamoDB
Unit Tests
Mock/Stub
is our request correct?
is the request mapping
set up correctly?is the API resources
configured correctly?
are we assuming ...
most Lambda functions are simple
have single purpose, the risk of
shipping broken software has largely
shifted to how they...
optimize towards shipping working
software, even if it means slowing
down your feedback loop…
learning the wrong thing faster does not
help us deliver working software faster
Legacy Monolith Amazon Kinesis Amazon Lambda
Amazon CloudSearchAmazon API Gateway Amazon Lambda
Legacy Monolith Amazon Kinesis Amazon Lambda
Amazon CloudSearchAmazon API Gateway Amazon Lambda
Test Input
Legacy Monolith Amazon Kinesis Amazon Lambda
Amazon CloudSearchAmazon API Gateway Amazon Lambda
Test Input
Validate
CI + CD PIPELINE
Yan
the earlier you consider CI/CD
the more time you save in
the long run
“…We prefer to have the end-to-end
tests exercise both the system and the
process by which it’s built and
deployed…
This s...
Yan
deployment scripts that only
live on the CI box is a disaster
waiting to happen…
Jenkins build config deploys and tests
unit + integration tests
deploy
acceptance tests
if [ "$1" = "deploy" ] && [ $# -eq 4 ]; then
STAGE=$2
REGION=$3
PROFILE=$4
npm install
AWS_PROFILE=$PROFILE 'node_modules/...
if [ "$1" = "deploy" ] && [ $# -eq 4 ]; then
STAGE=$2
REGION=$3
PROFILE=$4
npm install
AWS_PROFILE=$PROFILE 'node_modules/...
if [ "$1" = "deploy" ] && [ $# -eq 4 ]; then
STAGE=$2
REGION=$3
PROFILE=$4
npm install
AWS_PROFILE=$PROFILE 'node_modules/...
build.sh allows repeatable builds on both local & CI
Auto Auto Manual
LOGGING
2016-07-12T12:24:37.571Z 994f18f9-482b-11e6-8668-53e4eab441ae
GOT is off air, what do I do now?
2016-07-12T12:24:37.571Z 994f18f9-482b-11e6-8668-53e4eab441ae
GOT is off air, what do I do now?
UTC Timestamp API Gateway ...
Yan
Logs are not easily searchable
in CloudWatch Logs.
CloudWatch Logs
CloudWatch Logs AWS Lambda ELK stack
…
CloudWatch Events
DISTRIBUTED TRACING
a user
my followers didn’t receive
my new post!
where could the
problem be?
correlation IDs*
* eg. request-id, user-id, yubl-id, etc.
wrap HTTP client & AWS SDK clients
to forward captured correlation IDs
kinesis client
http client
sns client
use X-Ray for performance tracing
Amazon X-Ray
Amazon X-Ray
X-Ray traces do not span over API
Gateway, or async event sources
MONITORING + ALERTING
no place to install agents/daemons
• invocation Count
• error Count
• latency
• throttling
• granular to the minute
• support custom metrics
• same metrics as CW
• better dashboard
• support custom metrics
https://www.datadoghq.com/blog/monitoring-lambda-function...
my code
my code
my code
internet internet
press button something happens
those extra 10-20ms for
sending custom metrics
would compound when
you have microservices
and multiple APIs are
called wit...
Amazon found every 100ms of latency
cost them 1% in sales.
http://bit.ly/2EXPfbA
no more background processing,
other than what the platform provides
console.log(“hydrating yubls from db…”);
console.log(“fetching user info from user-api”);
console.log(“MONITORING|14897953...
CloudWatch Logs AWS Lambda
ELK stack
logs
metrics
CloudWatch
don’t forget to setup dashboards
& CW alarms
CONFIG MANAGEMENT
design for easy & quick
propagation of config changes
me
Environment variables make it
hard to share configurations
across functions.
me
Environment variables make it
hard to implement fine-grained
access to sensitive info.
config service
goes here
SSM
Parameter
Store
sensitive data should be encrypted
in-flight, and at-rest
enforce role-based access to sensitive
configuration values
SSM Parameter Store
HTTPS
role-based access
encrypted in-flight
SSM Parameter Store
encrypt
role-based access
SSM Parameter Store
encrypted at-rest
HTTPS
role-based access
SSM Parameter Store
encrypted in-flight
invest into a robust client library
fetch & cache at cold-start
invalidate at interval & weak signals
“DevOps is a set of practices intended to
reduce the time between committing a
change to a system and the change being
pla...
NoOps
Serverless ops is different…
remember the principles
rethink the approach
API Gateway and Kinesis
Authentication & authorisation (IAM, Cognito)
Testing
Running & Debugging functions locally
Log ag...
@theburningmonk
theburningmonk.com
github.com/theburningmonk
Serverless in production, an experience report (London DevOps)
Serverless in production, an experience report (London DevOps)
Serverless in production, an experience report (London DevOps)
Serverless in production, an experience report (London DevOps)
Serverless in production, an experience report (London DevOps)
Serverless in production, an experience report (London DevOps)
Serverless in production, an experience report (London DevOps)
Serverless in production, an experience report (London DevOps)
Serverless in production, an experience report (London DevOps)
Serverless in production, an experience report (London DevOps)
Serverless in production, an experience report (London DevOps)
Serverless in production, an experience report (London DevOps)
Serverless in production, an experience report (London DevOps)
Serverless in production, an experience report (London DevOps)
Serverless in production, an experience report (London DevOps)
Serverless in production, an experience report (London DevOps)
Serverless in production, an experience report (London DevOps)
Serverless in production, an experience report (London DevOps)
Serverless in production, an experience report (London DevOps)
Serverless in production, an experience report (London DevOps)
Serverless in production, an experience report (London DevOps)
Serverless in production, an experience report (London DevOps)
Serverless in production, an experience report (London DevOps)
Serverless in production, an experience report (London DevOps)
Serverless in production, an experience report (London DevOps)
Serverless in production, an experience report (London DevOps)
Serverless in production, an experience report (London DevOps)
You’ve finished this document.
Download and read it offline.
Upcoming SlideShare
What to Upload to SlideShare
Next
Upcoming SlideShare
What to Upload to SlideShare
Next
Download to read offline and view in fullscreen.

Share

Serverless in production, an experience report (London DevOps)

Download to read offline

AWS Lambda has changed the way we deploy and run software, but this new serverless paradigm has created new challenges to old problems - how do you test a cloud-hosted function locally? How do you monitor them? What about logging and config management? And how do we start migrating from existing architectures? In this talk Yan and Domas will discuss solutions to these challenges by drawing from real-world experience running Lambda in production and migrating from an existing monolithic architecture.

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all
  • Be the first to like this

Serverless in production, an experience report (London DevOps)

  1. 1. in production an experience reportan experience report what you should know before you go to production ServerlessServerless
  2. 2. Yan Cui http://theburningmonk.com @theburningmonk Domas Lasauskas
  3. 3. apr, 2016
  4. 4. hey guys, vote on this post and I’ll announce a winner at 10PM tonight
  5. 5. 10PM traffic
  6. 6. 10PM traffic 70-100x
  7. 7. low utilisation to leave room for spikes EC2 scaling is slow, so scale earlier
  8. 8. lots of $$$ for unused resources
  9. 9. up to 30 mins for deployment deployment required downtime
  10. 10. - Dan North “lead time to someone saying thank you is the only reputation metric that matters.”
  11. 11. “what would good look like for us?”
  12. 12. be small be fast have zero downtime have no lock-step DEPLOYMENTS SHOULD...
  13. 13. FEATURES SHOULD... be deployable independently be loosely-coupled
  14. 14. WE WANT TO... minimise cost for unused resources minimise ops effort reduce tech mess deliver visible improvements faster
  15. 15. nov, 2016
  16. 16. 170 Lambda functions in prod 1.2 GB deployment packages in prod 95% cost saving vs EC2 15x no. of prod releases per month
  17. 17. time is a good fit
  18. 18. 1st function in prod! time is a good fit
  19. 19. ? time is a good fit 1st function in prod!
  20. 20. ALERTING CI / CD TESTING LOGGING MONITORING
  21. 21. Practices ToolsPrinciples what is good? how to make it good? with what?
  22. 22. Principles outlast Tools
  23. 23. 170 functions ? ? time is a good fit 1st function in prod!
  24. 24. SECURITY DISTRIBUTED TRACING CONFIG MANAGEMENT
  25. 25. evolving the PLATFORM
  26. 26. rebuilt search
  27. 27. Legacy Monolith Amazon Kinesis Amazon Lambda Amazon CloudSearch
  28. 28. Legacy Monolith Amazon Kinesis Amazon Lambda Amazon CloudSearchAmazon API Gateway Amazon Lambda
  29. 29. new analytics pipeline
  30. 30. Legacy Monolith Amazon Kinesis Amazon Lambda Google BigQuery
  31. 31. Legacy Monolith Amazon Kinesis Amazon Lambda Google BigQuery 1 developer, 2 days design production (his 1st serverless project)
  32. 32. Legacy Monolith Amazon Kinesis Amazon Lambda Google BigQuery “nothing ever got done this fast at Skype!” - Chris Twamley
  33. 33. - Dan North “lead time to someone saying thank you is the only reputation metric that matters.”
  34. 34. Rebuilt with Lambda
  35. 35. Rebuilt with Lambda
  36. 36. BigQuery
  37. 37. BigQuery
  38. 38. grapheneDB BigQuery
  39. 39. grapheneDB BigQuery
  40. 40. grapheneDB BigQuery
  41. 41. nov, 2016
  42. 42. getting PRODUCTION READY
  43. 43. choose a tried-and-tested deployment framework, don’t invent your own
  44. 44. http://serverless.com
  45. 45. https://github.com/awslabs/serverless-application-model
  46. 46. http://apex.run
  47. 47. https://apex.github.io/up
  48. 48. https://github.com/claudiajs/claudia
  49. 49. https://github.com/Miserlou/Zappa
  50. 50. http://gosparta.io/
  51. 51. TESTING
  52. 52. amzn.to/29Lxuzu
  53. 53. Level of Testing 1.Unit do our objects do the right thing? are they easy to work with?
  54. 54. Level of Testing 1.Unit 2.Integration does our code work against code we can’t change?
  55. 55. handler
  56. 56. handler test by invoking the handler
  57. 57. Level of Testing 1.Unit 2.Integration 3.Acceptance does the whole system work?
  58. 58. Level of Testing unit integration acceptance feedback confidence
  59. 59. Don’t Mock Types You Can’t Change
  60. 60. Don’t Mock Types You Can’t Change Services
  61. 61. Paul Johnston The serverless approach to testing is different and may actually be easier. http://bit.ly/2t5viwK
  62. 62. LambdaAPI Gateway DynamoDB
  63. 63. LambdaAPI Gateway DynamoDB Unit Tests
  64. 64. LambdaAPI Gateway DynamoDB Unit Tests Mock/Stub
  65. 65. is our request correct? is the request mapping set up correctly?is the API resources configured correctly? are we assuming the correct schema? LambdaAPI Gateway DynamoDB is Lambda proxy configured correctly? is IAM policy set up correctly? is the table created? what unit tests will not tell you…
  66. 66. most Lambda functions are simple have single purpose, the risk of shipping broken software has largely shifted to how they integrate with external services observation
  67. 67. optimize towards shipping working software, even if it means slowing down your feedback loop…
  68. 68. learning the wrong thing faster does not help us deliver working software faster
  69. 69. Legacy Monolith Amazon Kinesis Amazon Lambda Amazon CloudSearchAmazon API Gateway Amazon Lambda
  70. 70. Legacy Monolith Amazon Kinesis Amazon Lambda Amazon CloudSearchAmazon API Gateway Amazon Lambda Test Input
  71. 71. Legacy Monolith Amazon Kinesis Amazon Lambda Amazon CloudSearchAmazon API Gateway Amazon Lambda Test Input Validate
  72. 72. CI + CD PIPELINE
  73. 73. Yan the earlier you consider CI/CD the more time you save in the long run
  74. 74. “…We prefer to have the end-to-end tests exercise both the system and the process by which it’s built and deployed… This sounds like a lot of effort (it is), but has to be done anyway repeatedly during the software’s lifetime…” Testing End-to-End
  75. 75. Yan deployment scripts that only live on the CI box is a disaster waiting to happen…
  76. 76. Jenkins build config deploys and tests unit + integration tests deploy acceptance tests
  77. 77. if [ "$1" = "deploy" ] && [ $# -eq 4 ]; then STAGE=$2 REGION=$3 PROFILE=$4 npm install AWS_PROFILE=$PROFILE 'node_modules/.bin/sls' deploy -s $STAGE -r $REGION elif [ "$1" = "int-test" ] && [ $# -eq 4 ]; then STAGE=$2 REGION=$3 PROFILE=$4 npm install AWS_PROFILE=$PROFILE npm run int-$STAGE elif [ "$1" = "acceptance-test" ] && [ $# -eq 4 ]; then STAGE=$2 REGION=$3 PROFILE=$4 npm install AWS_PROFILE=$PROFILE npm run acceptance-$STAGE else usage exit 1 fi
  78. 78. if [ "$1" = "deploy" ] && [ $# -eq 4 ]; then STAGE=$2 REGION=$3 PROFILE=$4 npm install AWS_PROFILE=$PROFILE 'node_modules/.bin/sls' deploy -s $STAGE -r $REGION elif [ "$1" = "int-test" ] && [ $# -eq 4 ]; then STAGE=$2 REGION=$3 PROFILE=$4 npm install AWS_PROFILE=$PROFILE npm run int-$STAGE elif [ "$1" = "acceptance-test" ] && [ $# -eq 4 ]; then STAGE=$2 REGION=$3 PROFILE=$4 npm install AWS_PROFILE=$PROFILE npm run acceptance-$STAGE else usage exit 1 fi install Serverless framework as dev dependency
  79. 79. if [ "$1" = "deploy" ] && [ $# -eq 4 ]; then STAGE=$2 REGION=$3 PROFILE=$4 npm install AWS_PROFILE=$PROFILE 'node_modules/.bin/sls' deploy -s $STAGE -r $REGION elif [ "$1" = "int-test" ] && [ $# -eq 4 ]; then STAGE=$2 REGION=$3 PROFILE=$4 npm install AWS_PROFILE=$PROFILE npm run int-$STAGE elif [ "$1" = "acceptance-test" ] && [ $# -eq 4 ]; then STAGE=$2 REGION=$3 PROFILE=$4 npm install AWS_PROFILE=$PROFILE npm run acceptance-$STAGE else usage exit 1 fi install Serverless framework as dev dependency mitigate version conflicts
  80. 80. build.sh allows repeatable builds on both local & CI
  81. 81. Auto Auto Manual
  82. 82. LOGGING
  83. 83. 2016-07-12T12:24:37.571Z 994f18f9-482b-11e6-8668-53e4eab441ae GOT is off air, what do I do now?
  84. 84. 2016-07-12T12:24:37.571Z 994f18f9-482b-11e6-8668-53e4eab441ae GOT is off air, what do I do now? UTC Timestamp API Gateway Request Id your log message
  85. 85. Yan Logs are not easily searchable in CloudWatch Logs.
  86. 86. CloudWatch Logs
  87. 87. CloudWatch Logs AWS Lambda ELK stack
  88. 88.
  89. 89. CloudWatch Events
  90. 90. DISTRIBUTED TRACING
  91. 91. a user my followers didn’t receive my new post!
  92. 92. where could the problem be?
  93. 93. correlation IDs* * eg. request-id, user-id, yubl-id, etc.
  94. 94. wrap HTTP client & AWS SDK clients to forward captured correlation IDs
  95. 95. kinesis client http client sns client
  96. 96. use X-Ray for performance tracing
  97. 97. Amazon X-Ray
  98. 98. Amazon X-Ray
  99. 99. X-Ray traces do not span over API Gateway, or async event sources
  100. 100. MONITORING + ALERTING
  101. 101. no place to install agents/daemons
  102. 102. • invocation Count • error Count • latency • throttling • granular to the minute • support custom metrics
  103. 103. • same metrics as CW • better dashboard • support custom metrics https://www.datadoghq.com/blog/monitoring-lambda-functions-datadog/
  104. 104. my code
  105. 105. my code
  106. 106. my code internet internet press button something happens
  107. 107. those extra 10-20ms for sending custom metrics would compound when you have microservices and multiple APIs are called within one slice of user event
  108. 108. Amazon found every 100ms of latency cost them 1% in sales. http://bit.ly/2EXPfbA
  109. 109. no more background processing, other than what the platform provides
  110. 110. console.log(“hydrating yubls from db…”); console.log(“fetching user info from user-api”); console.log(“MONITORING|1489795335|27.4|latency|user-api-latency”); console.log(“MONITORING|1489795335|8|count|yubls-served”); timestamp metric value metric type metric namemetrics logs
  111. 111. CloudWatch Logs AWS Lambda ELK stack logs metrics CloudWatch
  112. 112. don’t forget to setup dashboards & CW alarms
  113. 113. CONFIG MANAGEMENT
  114. 114. design for easy & quick propagation of config changes
  115. 115. me Environment variables make it hard to share configurations across functions.
  116. 116. me Environment variables make it hard to implement fine-grained access to sensitive info.
  117. 117. config service goes here
  118. 118. SSM Parameter Store
  119. 119. sensitive data should be encrypted in-flight, and at-rest
  120. 120. enforce role-based access to sensitive configuration values
  121. 121. SSM Parameter Store HTTPS role-based access encrypted in-flight
  122. 122. SSM Parameter Store encrypt role-based access
  123. 123. SSM Parameter Store encrypted at-rest
  124. 124. HTTPS role-based access SSM Parameter Store encrypted in-flight
  125. 125. invest into a robust client library
  126. 126. fetch & cache at cold-start
  127. 127. invalidate at interval & weak signals
  128. 128. “DevOps is a set of practices intended to reduce the time between committing a change to a system and the change being placed into normal production, while ensuring high quality.” https://en.wikipedia.org/wiki/DevOps#Definitions_and_History
  129. 129. NoOps
  130. 130. Serverless ops is different…
  131. 131. remember the principles rethink the approach
  132. 132. API Gateway and Kinesis Authentication & authorisation (IAM, Cognito) Testing Running & Debugging functions locally Log aggregation Monitoring & Alerting X-Ray Correlation IDs CI/CD Performance and Cost optimisation Error Handling Configuration management VPC Security Leading practices (API Gateway, Kinesis, Lambda) Canary deployments http://bit.ly/production-ready-serverless get 40% off with: ytcui
  133. 133. @theburningmonk theburningmonk.com github.com/theburningmonk

AWS Lambda has changed the way we deploy and run software, but this new serverless paradigm has created new challenges to old problems - how do you test a cloud-hosted function locally? How do you monitor them? What about logging and config management? And how do we start migrating from existing architectures? In this talk Yan and Domas will discuss solutions to these challenges by drawing from real-world experience running Lambda in production and migrating from an existing monolithic architecture.

Views

Total views

253

On Slideshare

0

From embeds

0

Number of embeds

3

Actions

Downloads

1

Shares

0

Comments

0

Likes

0

×