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

@mock_sqs interfering with acm client #7169

Closed
jhw opened this issue Dec 31, 2023 · 5 comments
Closed

@mock_sqs interfering with acm client #7169

jhw opened this issue Dec 31, 2023 · 5 comments
Labels

Comments

@jhw
Copy link

jhw commented Dec 31, 2023

Hello

I have the following script (dev/list_certificates2.py)

from moto import mock_sqs

import boto3, unittest

# @mock_sqs # <- UNCOMMENT TO FAIL
class HelloTest(unittest.TestCase):
    
    def test_handler(self):
        acm=boto3.client("acm", region_name="us-east-1")
        print (acm.list_certificates())
        self.assertEqual(2, 2)

if __name__=="__main__":
    unittest.main()

If I run it as per above I get the following -

(env) jhw@Justins-Air expander2 % python dev/list_certificates2.py
{'CertificateSummaryList': [{..}]}

But if I uncomment @mock_sqs I get the following -

(env) jhw@Justins-Air expander2 % python dev/list_certificates2.py
E
======================================================================
ERROR: test_handler (__main__.HelloTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/jhw/work/expander2/env/lib/python3.10/site-packages/moto/core/models.py", line 139, in wrapper
    result = func(*args, **kwargs)
  File "/Users/jhw/work/expander2/dev/list_certificates2.py", line 10, in test_handler
    print (acm.list_certificates())
  File "/Users/jhw/work/expander2/env/lib/python3.10/site-packages/botocore/client.py", line 535, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/Users/jhw/work/expander2/env/lib/python3.10/site-packages/botocore/client.py", line 983, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (UnrecognizedClientException) when calling the ListCertificates operation: The security token included in the request is invalid.

----------------------------------------------------------------------
Ran 1 test in 0.396s

FAILED (errors=1)

??? @mock_sqs is interfering with acm ??

Running moto 4.2.10

Thank you

@bblommers
Copy link
Collaborator

Hi @jhw,

that is the expected behaviour. Every decorator mocks the AWS credentials for security purposes, to ensure the test doesn't accidentally reach out to AWS.

If you want to mock both ACM and SQS, you can add both decorators.

@mock_acm
@mock_sqs
class HelloTest():
    ...

If you want to only mock a single service, and allow AWS access to another service, that is currently not supported.

#4597 is a feature request to configure this.
#3111 has a workaround that might work though.

@jhw
Copy link
Author

jhw commented Dec 31, 2023

OK noted. Thank you.

@jhw jhw closed this as completed Dec 31, 2023
@bblommers
Copy link
Collaborator

Hi @jhw , we've just created a new alpha-release where this is now possible: moto==5.0.0alpha2

The new mock_aws-decorator has a new config-parameter which allows you to specify which services should passthrough to AWS:

@mock_aws(
    config={"core": {
        "mock_credentials": False, 
        "passthrough": {
            "services": ["acm"]
    }}}
)

See the release announcement here: #7198

Are you able to upgrade and verify that this works for you?

@jhw
Copy link
Author

jhw commented Jan 15, 2024 via email

@mikeyjarvis19
Copy link

Hi @jhw , we've just created a new alpha-release where this is now possible: moto==5.0.0alpha2

The new mock_aws-decorator has a new config-parameter which allows you to specify which services should passthrough to AWS:

@mock_aws(
    config={"core": {
        "mock_credentials": False, 
        "passthrough": {
            "services": ["acm"]
    }}}
)

See the release announcement here: #7198

Are you able to upgrade and verify that this works for you?

This new config option in the 5.0 release was exactly what I needed, and solved the issue I was having when hitting SSM after mocking out SQS. Thank you!

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

3 participants