Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when I try to use scaffolding to create shield #7745

Closed
archinksagar opened this issue Jun 3, 2024 · 3 comments
Closed

Error when I try to use scaffolding to create shield #7745

archinksagar opened this issue Jun 3, 2024 · 3 comments
Labels

Comments

@archinksagar
Copy link
Contributor

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'
@bblommers
Copy link
Collaborator

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

@archinksagar
Copy link
Contributor Author

Thanks for the solution, it worked!

@bblommers
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants