getmoto / moto

A library that allows you to easily mock out tests based on AWS infrastructure.

Home Page:http://docs.getmoto.org/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error when I try to use scaffolding to create shield

archinksagar opened this issue · comments

I tried the following command and selected shield, it creates one operation but gives an error.
python3 scripts/scaffold.py

Traceback (most recent call last):
  File "moto/scripts/scaffold.py", line 694, in <module>
    main()
  File "moto/.venv/lib/python3.12/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "moto/.venv/lib/python3.12/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/moto/.venv/lib/python3.12/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "moto/.venv/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "moto/scripts/scaffold.py", line 663, in main
    operation = select_operation(service)
                ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "moto/scripts/scaffold.py", line 92, in select_operation
    implemented, operation_names = get_operations(service_name)
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "moto/scripts/scaffold.py", line 109, in get_operations
    moto_client, _name = get_moto_implementation(service_name)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "moto/scripts/implementation_coverage.py", line 21, in get_moto_implementation
    else backends[0]["global"]
         ~~~~~~~~~~~^^^^^^^^^^
  File "moto/moto/core/base_backend.py", line 295, in __getitem__
    return super().__getitem__(region_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'aws'

Hi @archinksagar,

if you change the last line in moto/shield/models.py from:

shield_backends = BackendDict(ShieldBackend, "shield")

to

shield_backends = BackendDict(ShieldBackend, "ec2")

it should work again, and you can continue to use scripts/scaffold.py for other methods.


The argument is used to retrieve the list of regions that this service is available in, using boto3. The problem here is that boto3 exposes an empty list - i.e., it thinks that shield is not available in any region.

Changing it to ec2 ensures that boto3 (and therefore Moto) has a list of regions where shield is available. (ec2 is available in more regions than shield, so it's not entirely correct, but it's a good enough solution.)

Related: #6078

Thanks for the solution, it worked!

Great, happy to hear that @archinksagar. I'll close this then, but let us know if you run into any other issues!