-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Import and/or client order now appears to matter between boto3 and moto #1926
Comments
I think I've figured out how to work around this issue. Calling boto3's The following works:
If this is a FAQ, it might need to be added to the documentation. |
Also ran into this issue, thanks so much for your |
after using mock_s3, it was still making calls to the AWS service. |
I have the same problem, except the workaround above does not work for me... Changing the order of imports doesn't fix it either. Versions:
I'm on Python 2.7, in case that matters at all. |
I had to refactor all my package code to use lazy boto3 resource instantiations. Then everything works OK, even without the So instead of: @dataclass
class S3Util:
client = boto3.resource('s3') Use properties to return on-demand and garbage collect them. Let boto3 manage the resource pools etc. and don't hang on to them. Something like: class S3Util:
@property
def client(self):
return boto3.resource('s3') |
adding in boto3.setup_default_session() inside of the test with the @decorator/@mock_sns worked fine for me.
|
I solved it using
Installing via commit till moto>1.3.8 |
As mentioned, this should be fixed in master, but feel free to reopen if there are still issues. |
I ran into this today and it was solved using the
@spulec Do you know which commit fixes this so I can see if I'm using the right versions? |
Feel free to try the very latest version: |
@spulec I'm also seeing this using the latest master, but can't call |
I was eagerly expecting #1907 and moto 1.3.7 to resolve my failing tests... however, even with all relevant modules up to date, I'm still getting
botocore.exceptions.ClientError: An error occurred (InvalidClientTokenId) when calling the XXX operation: The security token included in the request is invalid.
(for the record, here's my current module versions:)
Trying to reproduce the problem and narrow it down led me to an odd test case. For me, the following code completes successfully:
While this results in the ClientError mentioned previously:
Note that the only difference is that the
mock_iam
import now appears after the definition ofiam_resource
.Of course, you may think as I did, we may just need to re-initialize the iam_resource instance - but sadly that doesn't work:
For me, this is the problem - in my test suite, I have one test file which loads boto3 resources but no mocks, then subsequent test files load the mocks before the boto3 resources, but ClientError is still thrown. If I run pytest with just one test file at a time, all tests pass.
Is this a case of user error? Is there some way I can "reset" boto3's clients and resources after they've first initialized, so that moto can intercept the requests properly? Or is this a moto bug?
The text was updated successfully, but these errors were encountered: