Di
ff
erent services present di
ff
erent challenges to testing
Slide 14
Slide 14 text
Hard
Easy
Slide 15
Slide 15 text
Hard
Easy
Lambdalith
(e.g. express.js in Lambda)
Slide 16
Slide 16 text
Hard
Easy
Lambdalith
(e.g. express.js in Lambda)
API Gateway
with Lambda
Slide 17
Slide 17 text
Hard
Easy
Lambdalith
(e.g. express.js in Lambda)
Step Functions with
direct integrations
Step Functions with
timeouts or wait state(s)
API Gateway
with Lambda
Slide 18
Slide 18 text
Hard
Easy
Lambdalith
(e.g. express.js in Lambda)
Step Functions with
direct integrations
Step Functions with
timeouts or wait state(s)
Event-Driven Architecture
API Gateway
with Lambda
Slide 19
Slide 19 text
https://testserverlessapps.com
Slide 20
Slide 20 text
https://testserverlessapps.com
Chapter 1: how to test serverless architectures
Chapter 2: testing API Gateway APIs
Chapter 3: testing AppSync APIs
Chapter 4: testing Step Functions
Chapter 5: testing Event-Driven Architectures
Chapter 6: testing in production
Slide 21
Slide 21 text
the RECIPE
to TESTING serverless architectures
Slide 22
Slide 22 text
#1: “remocal” testing for Lambda functions
Slide 23
Slide 23 text
Local testing
Runs code locally
Can use debugger
Change code without deployment
FAST FEEDBACK!
Slide 24
Slide 24 text
Test against mocks
Test against real thing “does it work?”
“does it do what I expect?”
Slide 25
Slide 25 text
Test against mocks
Test against real thing “does it work?”
“does it do what I expect?”
Expectations/Assumptions
are sometimes wrong…
Reality!
Slide 26
Slide 26 text
No content
Slide 27
Slide 27 text
Local testing
Runs code locally
Can use debugger
Change code without deployment
FAST FEEDBACK!
Limited coverage
Prone to false positives
LOW CONFIDENCE
Slide 28
Slide 28 text
Your application consists of more than just your code
Slide 29
Slide 29 text
Your application consists of more than just your code
Your job is to ensure all of it works
Slide 30
Slide 30 text
HIGH CONFIDENCE!
Local testing Remote testing
Runs code locally
Can use debugger
Change code without deployment
FAST FEEDBACK!
Limited coverage
Prone to false positives
LOW CONFIDENCE
Test in the cloud
Realistic tests
Better coverage
Slide 31
Slide 31 text
HIGH CONFIDENCE!
Local testing Remote testing
Runs code locally
Can use debugger
Change code without deployment
FAST FEEDBACK!
Limited coverage
Prone to false positives
LOW CONFIDENCE
Test in the cloud
Realistic tests
Better coverage
Slow deployments
Every change needs deploying…
SLOW FEEDBACK…
Slide 32
Slide 32 text
HIGH CONFIDENCE!
Local testing Remote testing
Runs code locally
Can use debugger
Change code without deployment
FAST FEEDBACK!
Limited coverage
Prone to false positives
LOW CONFIDENCE
Test in the cloud
Realistic tests
Better coverage
Slow deployments
Every change needs deploying…
SLOW FEEDBACK…
Slide 33
Slide 33 text
Local testing Remote testing
Slide 34
Slide 34 text
REMOCAL testing
Runs code locally, talk to real AWS services
Can use debugger
Change code without deployment
Realistic tests
Slide 35
Slide 35 text
No content
Slide 36
Slide 36 text
Cognito
API Gateway
AppSync
EventBridge
Slide 37
Slide 37 text
Cognito
API Gateway
AppSync
EventBridge
IAM, event pattern, etc.
IAM, URL path, method, etc.
IAM, resolver con
fi
g,
resolver template, etc.
Slide 38
Slide 38 text
Your application consists of more than just your code
Your job is to ensure all of it works
Slide 39
Slide 39 text
Auth
Cognito AWS_IAM API Key Lambda authorizer
Request
validation
Request
transform
Integration
Lambda
Direct service
integration
Domain logic
Integrations
Response
transform
IAM
Slide 40
Slide 40 text
Auth
Cognito AWS_IAM API Key Lambda authorizer
Request
validation
Request
transform
Integration
Lambda
Direct service
integration
Domain logic
Integrations
Response
transform
IAM
Unit Test
Remocal Test
E2E Test
Slide 41
Slide 41 text
Auth
Cognito AWS_IAM API Key Lambda authorizer
Request
validation
Request
transform
Integration
Lambda
Direct service
integration
Domain logic
Integrations
Response
transform
IAM
Unit Test
Remocal Test
E2E Test
E2E Test
E2E Test
E2E Test
E2E Test
Slide 42
Slide 42 text
Auth
Cognito AWS_IAM API Key Lambda authorizer
Request
validation
Request
transform
Integration
Lambda
Direct service
integration
Domain logic
Integrations
Response
transform
IAM
Unit Test
Remocal Test
E2E Test
E2E Test
E2E Test
E2E Test
E2E Test
E2E Test E2E Test E2E Test E2E Test
Slide 43
Slide 43 text
Auth
Cognito AWS_IAM API Key Lambda authorizer
Request
validation
Request
transform
Integration
Lambda
Direct service
integration
Domain logic
Integrations
Response
transform
IAM
Unit Test
Remocal Test
E2E Test
E2E Test
E2E Test
E2E Test
E2E Test
E2E Test E2E Test E2E Test E2E Test
Unit Test
Remocal Test
Slide 44
Slide 44 text
DEMO TIME
Slide 45
Slide 45 text
REMOCAL testing
Runs code locally, talk to real AWS services
Can use debugger
Change code without deployment
Realistic tests
AWS resources need to be provisioned
Slide 46
Slide 46 text
#2: Ephemeral environments
Slide 47
Slide 47 text
npx sls deploy -s dev-my-feature
Step 1:
(creates a new “dev-my-feature” environment)
Slide 48
Slide 48 text
npx sls deploy -s dev-my-feature
Step 1:
(creates a new “dev-my-feature” environment)
Step 2: Make code changes, iterate, run remocal tests
against the “dev-my-feature” environment
Slide 49
Slide 49 text
npx sls deploy -s dev-my-feature
Step 1:
(creates a new “dev-my-feature” environment)
Step 2: Make code changes, iterate, run remocal tests
against the “dev-my-feature” environment
Step 3: Commit code and send PR
(CI pipeline runs all tests, etc.)
Slide 50
Slide 50 text
npx sls deploy -s dev-my-feature
Step 1:
(creates a new “dev-my-feature” environment)
Step 2: Make code changes, iterate, run remocal tests
against the “dev-my-feature” environment
Step 3: Commit code and send PR
Step 4: npx sls remove -s dev-my-feature
(destroys the ephemeral environment)
(CI pipeline runs all tests, etc.)
Slide 51
Slide 51 text
npx sls deploy -s dev-my-feature
Step 1:
(creates a new “dev-my-feature” environment)
Step 2: Make code changes, iterate, run remocal tests
against the “dev-my-feature” environment
Step 3: Commit code and send PR
Step 4: npx sls remove -s dev-my-feature
(destroys the ephemeral environment)
(CI pipeline runs all tests, etc.)
Slide 52
Slide 52 text
Insulated environment for development and testing
Slide 53
Slide 53 text
Insulated environment for development and testing
(avoids polluting shared dev/test/staging environments with test data)
Hard
Easy
Lambdalith
(e.g. express.js in Lambda)
Step Functions with
direct integrations
Step Functions with
timeouts or wait state(s)
Event-Driven Architecture
API Gateway
with Lambda
Lambda EventBridge Lambda
SNS Lambda
DynamoDB Lambda
DynamoDB
SQS
DLQ
EventBridge
E2E tests
How to capture what was sent?
How to capture what was sent?
How to capture what was sent?
Slide 109
Slide 109 text
Lambda EventBridge Lambda
SNS Lambda
DynamoDB Lambda
DynamoDB
SQS
DLQ
EventBridge
E2E tests
SNS
How to capture what was sent?
Slide 110
Slide 110 text
#4: Capture async events/messages
Slide 111
Slide 111 text
Lambda EventBridge
System under test
Slide 112
Slide 112 text
Lambda EventBridge
System under test
AppSync (subscription)
Slide 113
Slide 113 text
Lambda EventBridge
Push
System under test
AppSync (subscription)
Slide 114
Slide 114 text
Lambda EventBridge
Push
Shared infra
AppSync (subscription)