Interview Prep/Python for DevOps/Testing, services & metrics

Where are moto's limits, and what do you do about them?

AdvancedConceptTesting, services & metrics
Answer

moto implements most common operations but not every API, field or behaviour: IAM policies are not enforced by default, some timestamps are always "now" (for example snapshot StartTime), CloudWatch only returns metrics you put yourself, and eventual consistency is not simulated. Approaches:

  • For time-based logic, stub the response with unittest.mock or botocore's Stubber, or inject a clock.
  • Keep business logic in pure functions that take dicts, test those directly, and use moto for the API glue.
  • Run a small integration suite against a real sandbox account (or LocalStack) on a schedule.
All Python for DevOps questions Roadmap: Python for automation

More on Testing, services & metrics