AWS re:Invent 2023 - The pragmatic serverless Python developer (OPN305) Flashcards
https://www.youtube.com/watch?v=52W3Qyg242Y
What is Pydantic?
It is data validation library for Python.
How structure the folder?
Business domain: lambda handlers code
Business logic
integrations code
Ex:
- Product
- crud
- handlers
- schemas (pydantic models)
- tests
- e2e
- integration
- unit
- pyproject.toml
- IaC: CDK, AWS SAM, Terraform, …
Ex 2:
- stream_processor
- domain_logic
- handlers
- integrations
- __init__.py
- constants.py
What is Architectural Layers?
Is a way to split responsibility.
Handler:
- No domain code
- Concise responsibilities
-> Configuration > Env. vars > Validation > Call domain > Serialize output
Domain:
- Business logic only
- May be shared by N handlers
- Isolated tests
Integration:
- Adapter pattern
- Contains API/DB code
API Gateway > Handler > Domain > Integration > DynamoDb
Explain how test a serverless application?
- Unit test (locally)
- test schema validations (Pydantic)
- test isolated integration classes
- no deployment required
- fast and repeatable
- Integration tests
- requires deployment
- Run locally & on AWS
- Test runner (pytest) > test data > call > lambda handler (AWS) > assertion
- E2E test
- required deployment
- Run on AWS
- Test runner (pytest) > test data > (call) > Product API (Api Gateway endpoint + lambda) > assertion
- Simulate bad input
- API security tests (invalid authorization / invalida authentication)