0

Context

We have code which gets IPs from many AWS accounts within our organisation. Running this code returns IPs from each enabled region but throws exceptions for each disabled region.

We have wrapped the code in a guard clause, ensuring we only pull IPs if the region is enabled. This guard clause uses boto3's 'ec2' client to describe_regions.

We want to test the guard clause functionality with Moto.

Current State

Moto provides a @mock_ec2 decorator and has implemented describe_regions. We use this, but the mock returns all regions by default. We want to change the number of regions returned.

A stubbed response for the mocked describe_regions would work best, but having experience with Moto, I've never seen anything like this.

We've attempted to use boto3's 'account' client enable_region and disable_region. Moto does not provide any mocking functionality for the account level. As a result, we cannot make calls against the virtual account in use by Moto.

Desired State

We can change the response Moto generates when it makes the describe_regions call.

We use Moto extensively

Joe
  • 678
  • 9
  • 24
  • 1
    See my answer here: https://stackoverflow.com/a/76179037/13245310 Different question, but you can you use the same approach to change the response of `describe_regions` – Bert Blommers May 05 '23 at 17:52

0 Answers0