localstack icon indicating copy to clipboard operation
localstack copied to clipboard

Localstack failing on CreateComputeResource with KeyError on maxvCpus

Open agibsonccc opened this issue 3 years ago • 2 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Current Behavior

I'm using the aws java v2 sdk when attempting to create one. My main use case is setting up a cluster for aws batch. Any hints? Thanks!

Stack trace:

localstack_main | Traceback (most recent call last):
localstack_main |   File "/opt/code/localstack/localstack/aws/chain.py", line 57, in handle
localstack_main |     handler(self, self.context, response)
localstack_main |   File "/opt/code/localstack/localstack/aws/handlers/service.py", line 121, in __call__
localstack_main |     handler(chain, context, response)
localstack_main |   File "/opt/code/localstack/localstack/aws/handlers/service.py", line 91, in __call__
localstack_main |     skeleton_response = self.skeleton.invoke(context)
localstack_main |   File "/opt/code/localstack/localstack/aws/skeleton.py", line 153, in invoke
localstack_main |     return self.dispatch_request(context, instance)
localstack_main |   File "/opt/code/localstack/localstack/aws/skeleton.py", line 165, in dispatch_request
localstack_main |     result = handler(context, instance) or {}
localstack_main |   File "/opt/code/localstack/localstack/aws/forwarder.py", line 59, in _call
localstack_main |     return fallthrough_handler(context, req)
localstack_main |   File "/opt/code/localstack/localstack/services/moto.py", line 84, in proxy_moto
localstack_main |     status, headers, content = dispatch_to_moto(context)
localstack_main |   File "/opt/code/localstack/localstack/services/moto.py", line 114, in dispatch_to_moto
localstack_main |     return dispatch(request, request.url, request.headers)
localstack_main |   File "/opt/code/localstack/.venv/lib/python3.10/site-packages/moto/core/responses.py", line 205, in dispatch
localstack_main |     return cls()._dispatch(*args, **kwargs)
localstack_main |   File "/opt/code/localstack/.venv/lib/python3.10/site-packages/moto/core/responses.py", line 315, in _dispatch
localstack_main |     return self.call_action()
localstack_main |   File "/opt/code/localstack/.venv/lib/python3.10/site-packages/moto/core/responses.py", line 405, in call_action
localstack_main |     response = method()
localstack_main |   File "/opt/code/localstack/.venv/lib/python3.10/site-packages/moto/batch/responses.py", line 49, in createcomputeenvironment
localstack_main |     name, arn = self.batch_backend.create_compute_environment(
localstack_main |   File "/opt/code/localstack/.venv/lib/python3.10/site-packages/moto/batch/models.py", line 1100, in create_compute_environment
localstack_main |     self._validate_compute_resources(compute_resources)
localstack_main |   File "/opt/code/localstack/.venv/lib/python3.10/site-packages/moto/batch/models.py", line 1158, in _validate_compute_resources
localstack_main |     if int(cr["maxvCpus"]) < 0:
localstack_main | KeyError: 'maxvCpus'
localstack_main | 2022-08-01T02:47:03.885  INFO --- [   asgi_gw_0] localstack.request.aws     : AWS batch.CreateComputeEnvironment => 500 (InternalError)
localstack_main | 2022-08-01T02:47:04.201 ERROR --- [   asgi_gw_0] l.aws.handlers.logging     : exception during call chain
localstack_main | Traceback (most recent call last):
localstack_main |   File "/opt/code/localstack/localstack/aws/chain.py", line 57, in handle
localstack_main |     handler(self, self.context, response)
localstack_main |   File "/opt/code/localstack/localstack/aws/handlers/service.py", line 121, in __call__
localstack_main |     handler(chain, context, response)
localstack_main |   File "/opt/code/localstack/localstack/aws/handlers/service.py", line 91, in __call__
localstack_main |     skeleton_response = self.skeleton.invoke(context)
localstack_main |   File "/opt/code/localstack/localstack/aws/skeleton.py", line 153, in invoke
localstack_main |     return self.dispatch_request(context, instance)
localstack_main |   File "/opt/code/localstack/localstack/aws/skeleton.py", line 165, in dispatch_request
localstack_main |     result = handler(context, instance) or {}
localstack_main |   File "/opt/code/localstack/localstack/aws/forwarder.py", line 59, in _call
localstack_main |     return fallthrough_handler(context, req)
localstack_main |   File "/opt/code/localstack/localstack/services/moto.py", line 84, in proxy_moto
localstack_main |     status, headers, content = dispatch_to_moto(context)
localstack_main |   File "/opt/code/localstack/localstack/services/moto.py", line 114, in dispatch_to_moto
localstack_main |     return dispatch(request, request.url, request.headers)
localstack_main |   File "/opt/code/localstack/.venv/lib/python3.10/site-packages/moto/core/responses.py", line 205, in dispatch
localstack_main |     return cls()._dispatch(*args, **kwargs)
localstack_main |   File "/opt/code/localstack/.venv/lib/python3.10/site-packages/moto/core/responses.py", line 315, in _dispatch
localstack_main |     return self.call_action()
localstack_main |   File "/opt/code/localstack/.venv/lib/python3.10/site-packages/moto/core/responses.py", line 405, in call_action
localstack_main |     response = method()
localstack_main |   File "/opt/code/localstack/.venv/lib/python3.10/site-packages/moto/batch/responses.py", line 49, in createcomputeenvironment
localstack_main |     name, arn = self.batch_backend.create_compute_environment(
localstack_main |   File "/opt/code/localstack/.venv/lib/python3.10/site-packages/moto/batch/models.py", line 1100, in create_compute_environment
localstack_main |     self._validate_compute_resources(compute_resources)
localstack_main |   File "/opt/code/localstack/.venv/lib/python3.10/site-packages/moto/batch/models.py", line 1158, in _validate_compute_resources
localstack_main |     if int(cr["maxvCpus"]) < 0:
localstack_main | KeyError: 'maxvCpus'

Expected Behavior

The compute resource gets created.

How are you starting LocalStack?

With a docker-compose file

Steps To Reproduce

How are you starting localstack (e.g., bin/localstack command, arguments, or docker-compose.yml)

docker-compose.yml

Client commands (e.g., AWS SDK code snippet, or sequence of "awslocal" commands)

Using the aws java sdk. Can provide stripped example if relevant.

Environment

- OS:Fedora 35
- LocalStack: latest

Anything else?

Nothing I can think of yet.

agibsonccc avatar Aug 01 '22 02:08 agibsonccc

Welcome to LocalStack! Thanks for reporting your first issue and our team will be working towards fixing the issue for you or reach out for more background information. We recommend joining our Slack Community for real-time help and drop a message to LocalStack Pro Support if you are a Pro user! If you are willing to contribute towards fixing this issue, please have a look at our contributing guidelines and our developer guide.

localstack-bot avatar Aug 01 '22 02:08 localstack-bot

Thanks for reporting @agibsonccc .

Can provide stripped example if relevant.

If you could share a few snippets of your client code calling CreateComputeEnvironment, that would be super helpful. Thanks!

Also, just to confirm - which version are you using, does the problem persist after pulling the latest Docker image?


Update: it seems that the computeResources.maxvCpus parameter is required, as per the API specs - it is likely missing in your case, and hence causing the API call to fail. We'll run a few parity tests against AWS, to see if that is the expected behavior. Thanks

whummer avatar Aug 09 '22 12:08 whummer

Hi again @agibsonccc , quick update - we have now added a few enhancements to make the parameter validation for Batch jobs more robust, and to improve parity with AWS. When you get a chance, can you please pull the latest Docker image and give it another try? Please let us know if the problem persists.. Thanks!

whummer avatar Sep 24 '22 10:09 whummer