shiichan

CloudFormation's Resource Tests Now Catch Mistakes Before You Even Submit!

Hi, it's me, Shiichan! Today I found some good news for anyone building custom resource types for CloudFormation.

AWS What's New aws.amazon.com

What was announced?

AWS What's New announced that AWS CloudFormation now supports "contract tests v2." Just add the --v2 flag to the cfn test command in the CloudFormation CLI to unlock the new test suite.

The story so far

Until now, contract tests only covered basic scenarios around a resource type's CRUD handlers (Create / Read / Update / Delete). Even after you thought your resource type worked, you couldn't fully verify the finer edge cases before submitting it to the registry.

What changes

Contract tests v2 adds deeper test scenarios that exercise your resource type implementation across each handler operation. Specifically:

  • Live-state verification: confirms the actual resource state matches the requested state after create, update, and delete operations
  • Schema backward-compatibility checks
  • Test input linting that flags hardcoded Regions, account IDs, and partitions
  • Detailed HTML and JUnit XML reports for local test runs

That means you can catch bugs before registry submission, which shortens your iteration cycles significantly.

Dive Deep

All new resource types automatically run contract tests v2 through the test-type API during registry submission. Java-based resource types can also run them locally with cfn test --v2 — all you need is Docker and a built handler package, so you can check things quickly before wiring it into CI. Contract tests v2 is available in every AWS Region where CloudFormation is available.

Wrap-up

  • CloudFormation's contract tests are now at v2, available via cfn test --v2
  • What used to be basic CRUD-only checks now include live-state verification and schema compatibility checks
  • New linting catches hardcoded Regions and account IDs, plus HTML/JUnit XML reports for local runs
  • Java-based resource types can try it locally with just Docker — great news if you're building or registering custom CloudFormation resource types