Eine Serverless Function zu schreiben ist denkbar einfach. Und auch die Kombinationen mehrerer FaaS zu einem komplexeren System ist kein Hexenwerk. Was aber, wenn die niedlichen kleinen Funktionen sich zur Laufzeit nicht so verhalten, wie gewünscht? Wie sieht das Monitoring der einzelnen Funktionen und des Systems als Ganzes aus? Und was ist mit Testen? Muss die Funktion dazu immer in der Cloud deployt werden oder kann man das produktive System auch lokal emulieren? Wie wichtig ist der Aspekt der Automatisierung und wie wird diese erreicht? Wie beeinflussen Cold- und Warm-Start das Laufzeitverhalten? Diesen und vielen anderen Herausforderungen wollen wir uns in der Session stellen – Aha-Effekte garantiert!
3. ÜBER MICH
Wer bin ich - und wenn ja, wie viele?
• CIO New Technologies
• Enterprise & Mobile
• Autor, Speaker, Coach & Mentor
• Snowboard & MTB Enthusiast (a.k.a. “stets bemüht“)
Lars Röwekamp (a.k.a. @mobileLarson)
5. “Run your business code
highly-available
in the cloud in response
to events and scale without
any servers to manage.“*
* AWS Lambda Advertising
6. Function as self-contained application
Serverless Function: Entwickler schreibt eine Business-
Funktion in einer der unterstützen Programmiersprachen,
„bundled“ diese mit den entsprechenden Abhängigkeiten
(LIBs) und lädt sie in die Cloud.
Serverless Environment: Führt die Funktion bei „Aufruf“ in
der passenden Runtime effizient, flexibel und hoch skalierbar
aus.
“
7. Serverless no need to maintain
Entwickler: Fokussiert sich ausschließlich auf die
Umsetzung der Business-Logik und das Erstellen des
Function-Bundle.
Cloud Provider: liefert und maintained rundum-sorglos
Umgebung für die Serverless Functions, inklusive etwaiger
Cloud Services (z.B. Storage, DB, Streaming, AI).
“
20. AWS Cloud
Create Thumbnail
Store raw Image
Szenario #1: Datei-/Datenbearbeitung
StoreImage
Logs
CreateThumbnail
Logs
S3 Object
created
1 2
3
4
5
upload
image
21. AWS Cloud
Data Stream Analysis
StreamAnalyzer
Logs
Real-Time Monitoring / Querying
store anomalies
extracted by lambda
function
1
sensor data stream is
uploaded to Kinesis
in real-time
2
3
Lambda runs code to
detect anomalies
4
data immediately
available for interested
parties to query
Szenario #2: Stream Processing
tons of
very important
sensor data
22. Szenario #3: Web Application
AWS Cloud
Web Client
storage related functions
database related functions
additional functions, e.g.
region aware
web app
delivery
1
login via id/pwd
returns JWT
2
6
3
REST
call
4
translated
lambda
trigger
5
lambda
@work
5
lambda
@work
37. trigger
request
Hello World „under the Hood“
Download
Function Code
ZIP
AWS Cloud
Setup
Runtime
Init
Function
COLD START
Execute
Handler
38. trigger
request
Hello World „under the Hood“
Download
Function Code
ZIP
AWS Cloud
Setup
Runtime
Init
Function
COLD START
Execute
Handler
Terminate
Function
40. trigger
request
Hello World „under the Hood“
ZIP
AWS Cloud
COLD START
Terminate
Function
Execute
Handler
Execute
Handler
trigger
request
41. trigger
request
Hello World „under the Hood“
ZIP
AWS Cloud
COLD START
Execute
Handler
Terminate
Function
Execute
Handler
Execute
Handler
trigger
request
trigger
request
42. Lambda
Aufruf
Spaß mit Cold Start
ZIP
AWS Cloud
Active
Container
Active
Container
Active
Container
Cold Start
Container
aktiver
Container
vorhanden?
JA1) NEIN2)
1) Aktiver Container, der nicht
gerade einen Lambda Aufruf
abarbeitet, kann wieder / weiter
verwendet werden.
2) Neuer Container muss erzeugt,
Function Code herunter geladen
und die Runtime neu initialisiert
werden.
43. Spaß mit Cold Start
ZIP
AWS Cloud
Active
Container
Active
Container
Active
Container
Cold Start
Container
aktiver
Container
vorhanden?
JA1) NEIN2)
1) Aktiver Container, der nicht
gerade einen Lambda Aufruf
abarbeitet, kann wieder / weiter
verwendet werden.
2) Neuer Container muss erzeugt,
Function Code herunter geladen
und die Runtime neu initialisiert
werden.
Lambda
Aufruf
PING
PING
PING
45. EVENT
Hello World REALLY „under the Hood“
AWS Cloud
Frontend Invoker
Frontend Invoker
Workers Manager
Workers Manager
Worker
Worker
Worker
Worker
ZIP
ZIP
Load Balancer
Availability Zone
Availability Zone
46. Spaß mit Cold Start
Worker
Instance
Hardware
Guest OS
Sandbox
Lambda Runtime
Your Code
Host OS
Hypervisor
one
Function
one
Account
many
Accounts
EC 2
System
Firecracker*
*https://firecracker-microvm.github.io
52. AWS Cloud
Spaß mit Skalierung
Cold
Start
Execute
Handler
Lambda
No #1
Lambda
No #1
Event
53. AWS Cloud
Spaß mit Skalierung
Cold
Start
Execute
Handler
Lambda
No #1
Lambda
No #1
Event Event
54. AWS Cloud
Spaß mit Skalierung
Cold
Start
Execute
Handler
Lambda
No #1
Lambda
No #1
Event Event
Lambda
No #1 ?
55. AWS Cloud
Spaß mit Skalierung
Cold
Start
Execute
Handler
Lambda
No #1
Lambda
No #1
Event Event
Lambda
No #1 ?
x
56. AWS Cloud
Spaß mit Skalierung
Cold
Start
Execute
Handler
Lambda
No #1
Lambda
No #1
Event Event
Lambda
No #2 !
Cold
Start
Execute
Handler
Lambda
No #2
57. AWS Cloud
Spaß mit Skalierung
Cold
Start
Execute
Handler
Lambda
No #1
Lambda
No #1
Event Event
Lambda
No #2 !
Cold
Start
Execute
Handler
Lambda
No #2
58. AWS Cloud
Spaß mit Skalierung
Cold
Start
Cold
Start
Execute
Handler
Execute
Handler
Lambda
No #1
Lambda
No #2
Lambda
No #2
Lambda
No #1
Event Event Event
59. AWS Cloud
Spaß mit Skalierung
Cold
Start
Cold
Start
Execute
Handler
Execute
Handler
Lambda
No #1
Lambda
No #2
Lambda
No #2
Lambda
No #1
Event Event Event
Lambda
No #1 ?
60. AWS Cloud
Spaß mit Skalierung
Cold
Start
Cold
Start
Execute
Handler
Execute
Handler
Lambda
No #1
Lambda
No #2
Lambda
No #2
Lambda
No #1
Event Event Event
Lambda
No #1 ?
x
61. AWS Cloud
Spaß mit Skalierung
Cold
Start
Cold
Start
Execute
Handler
Execute
Handler
Lambda
No #1
Lambda
No #2
Lambda
No #2
Lambda
No #1
Event Event Event
Lambda
No #2 ?
62. AWS Cloud
Spaß mit Skalierung
Cold
Start
Cold
Start
Execute
Handler
Execute
Handler
Lambda
No #1
Lambda
No #2
Lambda
No #2
Lambda
No #1
Event Event Event
Lambda
No #2 ?
x
63. AWS Cloud
Spaß mit Skalierung
Cold
Start
Cold
Start
Execute
Handler
Execute
Handler
Cold
Start
Execute
Handler
Lambda
No #1
Lambda
No #2
Lambda
No #3
Lambda
No #2
Lambda
No #3
Lambda
No #1
Event Event Event
!
64. AWS Cloud
Spaß mit Skalierung
Cold
Start
Cold
Start
Execute
Handler
Execute
Handler
Cold
Start
Execute
Handler
Lambda
No #1
Lambda
No #2
Lambda
No #3
Lambda
No #2
Lambda
No #3
Lambda
No #1
Event Event Event
65. Event
AWS Cloud
Spaß mit Skalierung
Cold
Start
Event Event Event
Cold
Start
Execute
Handler
Execute
Handler
Cold
Start
Execute
Handler
Lambda
No #1
Lambda
No #2
Lambda
No #3
Lambda
No #2
Lambda
No #3
Lambda
No #1
66. Event
AWS Cloud
Spaß mit Skalierung
Cold
Start
Event Event Event
Cold
Start
Execute
Handler
Execute
Handler
Cold
Start
Execute
Handler
Lambda
No #1
Lambda
No #2
Lambda
No #3
Lambda
No #2
Lambda
No #3
Lambda
No #1
Lambda
No #1 ?
67. Event
AWS Cloud
Spaß mit Skalierung
Cold
Start
Event Event Event
Cold
Start
Execute
Handler
Execute
Handler
Cold
Start
Execute
Handler
Execute
Handler
Lambda
No #1
Lambda
No #2
Lambda
No #3
Lambda
No #2
Lambda
No #3
Lambda
No #1
Lambda
No #1
69. The Road to the Cloud ...
Der Serverless Showcase
70. AWS Cloud
AWS Step Functions workflow: Store Image
Create Thumbnail
Inform Subscribers
Store raw Image
Store Image Information
1
2
Use-Case: Upload Image
upload image
with additional
information
72. AWS Cloud
AWS Step Functions workflow: Store Image
Create Thumbnail
Inform Subscribers
Store raw Image
Store Image Information
1
2
73. AWS Cloud
AWS Step Functions workflow: Store Image
Create Thumbnail
Inform Subscribers
Store raw Image
Store Image Information
1
2
74. AWS Cloud
AWS Step Functions workflow: Store Image
Create Thumbnail
Inform Subscribers
Store raw Image
Store Image Information
1
2
75. AWS Cloud
AWS Step Functions workflow: Store Image
Create Thumbnail
Inform Subscribers
Store raw Image
Store Image Information
1
2
76. AWS Cloud
AWS Step Functions workflow: Store Image
Create Thumbnail
Inform Subscribers
Store raw Image
Store Image Information
1
2
77. AWS Cloud
AWS Step Functions workflow: Store Image
Create Thumbnail
Inform Subscribers
Store raw Image
Store Image Information
1
2
78. AWS Cloud
AWS Step Functions workflow: Store Image
Create Thumbnail
Inform Subscribers
Store raw Image
Store Image Information
1
2
79. AWS Cloud
AWS Step Functions workflow: Store Image
Create Thumbnail
Inform Subscribers
Store raw Image
Store Image Information
1
2
80. AWS Cloud
AWS Step Functions workflow: Store Image
Create Thumbnail
Inform Subscribers
Store raw Image
Store Image Information
1
2
81. AWS Cloud
AWS Step Functions workflow: Store Image
Create Thumbnail
Inform Subscribers
Store raw Image
Store Image Information
1
2
82. “Run your business code
highly-available
in the cloud in response
to events and scale
without any servers to
manage.“*
*(AWS Lambda product description)
83. “Run your business code
highly distributed
and event driven in a non
transparent environment
with no single
point of control.“*
*(my personal interpretation)
86. Testen in der Serverless Welt
„The biggest complexity is not within
the function itself, but in how it interacts
with other functions and services
(a.k.a. cloud components).“
87. #1 Trennen von Businesslogik und Infrastruktur
Testing Best Practices
AWS Cloud
On-Premise
handler
logic
Kandidat für Unit Tests
e
i
u
Kandidat für Integration Tests
Kandidat für End-to-Ende Tests
u
88. #2 Cloud-Infrastruktur Komponenten mocken
Testing Best Practices
AWS Cloud
On-Premise
handler
logic u
u
m
Kandidat für Unit Tests
e
i
u
Kandidat für Integration Tests
Kandidat für End-to-Ende Tests
89. #3 Lokale Umgebung für funktionale Tests verwenden (z.B. SAM local)
Testing Best Practices
AWS Cloud
On-Premise
handler
logic u
via SAM local
via SAM local
SAM
yaml
TEST
u
u
Kandidat für Unit Tests
e
i
u
Kandidat für Integration Tests
Kandidat für End-to-Ende Tests
90. #4 Lokale Umgebung zum Triggern von Integration Tests verwenden
Testing Best Practices
AWS Cloud
On-Premise
handler
logic u
via SAM local
via SAM local
SAM
yaml
TEST
u
u
i
i
Kandidat für Unit Tests
e
i
u
Kandidat für Integration Tests
Kandidat für End-to-Ende Tests
91. #5 Lokale Cloud-Komponenten für Integration Tests*
Testing Best Practices
AWS Cloud
On-Premise
handler
logic u
via DynamoDB local
via FakeS3 via SAM local
via SAM local
SAM
yaml
TEST
u
u
i
i
i
i
WARNUNG: lokale Cloud
Komponenten können
lediglich funktionale
Korrektheit sicherstellen,
nicht aber infrastrukturelle,
wie z.B. DLQs, Timeouts,
Throttling, SLAs, …
Kandidat für Unit Tests
e
i
u
Kandidat für Integration Tests
Kandidat für End-to-Ende Tests
92. #6 temporäre Integration-Cloud für partielle Integration Tests
Testing Best Practices
AWS Cloud
On-Premise
handler
logic u
via SAM local
via SAM local
SAM
yaml
TEST
u
u
via DynamoDB local
via FakeS3
i
i
Temorary Intregration #Dev1
i
i
INT
i
i
Kandidat für Unit Tests
e
i
u
Kandidat für Integration Tests
Kandidat für End-to-Ende Tests
93. #7 permanente Integration-Cloud für End-to-End Tests
Testing Best Practices
AWS Cloud
On-Premise
handler
logic u
via SAM local
via SAM local
SAM
yaml
TEST
u
u
via DynamoDB local
via FakeS3
i
i
Permament Intregration
INT
e
e
e
e
i
i
Kandidat für Unit Tests
e
i
u
Kandidat für Integration Tests
Kandidat für End-to-Ende Tests
97. Testing in Produktion
Ziele des Testens: „Vertrauen gewinnen“
• Outages von Cloud & Cloud-Komponenten
• Outages von 3rd Party Apps
• Bugs / Probleme durch Skalierung
98. Testing in Produktion
Robustes Monitoring und Error Reporting
• Logging
• Tracing
• Metrics
• Alerting
Vorhersagen von Störungen
inklusive automatischer
Regenerierung!
101. Mit einem gut geplantes Monitoring sollten wir in der Lage sein, …
• aufkommende Probleme vorherzusagen
• schnell die Ursache von Problemen zu identifizieren
• automatische Recovery-Prozesse anzustoßen
• notwendige Alarme zu triggern
Real-Life Monitoring
103. Gut geplantes Monitoring berücksichtigt verschiedene Aspekte
• reliability: Komponenten und Kommunikation
• usage: funktional und nicht-funktional
• performance: Dauer, Latenz und Timeouts
• security: Zugriffsrechte, Attacken
• costs: aktuelle Kosten, Kostenentwicklung
Real-Life Monitoring
104. #1 User-facing Latency vermeiden
Monitoring Best Practices
AWS Cloud
My Lambda logs
log
stream
log
data
async
sync
Log Aggregator
log
data
1
very fast and cheap
2
3
time consuming and “expensive”
parse
log stream
105. #2 umfangreiche System-/Anwendungsmetriken sammeln
Monitoring Best Practices
AWS Cloud
My Lambda logs
log
stream
log
data
async
sync
Log Aggregator
metrics
custom
metrics
custom
metrics
log
data
2
3
1
very fast and cheap
parse
log stream
custom
metrics
106. #3 unnötige Kosten vermeiden
Monitoring Best Practices
AWS Cloud
My Lambda logs
log
stream
log
data
async
sync
Log Aggregator
metrics
custom
metrics
custom
metrics
log
data
archive
logs
1
2
custom
metrics
107. #4 Logs und Metriken korrelieren / aggregieren
Monitoring Best Practices
AWS Cloud
My Lambda logs
log
stream
log
data
async
sync
Log Aggregator
metrics
custom
metrics
custom
metrics
log
data
archive
logs
1
correlation
ID
custom
metrics
108. #5 Logging via ENV Vars an Edge Server enablen/disablen
Monitoring Best Practices
AWS Cloud
My Lambda logs
log
stream
log
data
async
sync
Log Aggregator
metrics
custom
metrics
custom
metrics
log
data
archive
logs
DEBUG
on/off
ENV var
1
2
custom
metrics