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

Moto V5 release 🚀 - Breaking Changes ⚠️ #7198

Closed
bblommers opened this issue Jan 7, 2024 · 3 comments
Closed

Moto V5 release 🚀 - Breaking Changes ⚠️ #7198

bblommers opened this issue Jan 7, 2024 · 3 comments
Milestone

Comments

@bblommers
Copy link
Collaborator

bblommers commented Jan 7, 2024

Hello all!

We have just released Moto v5, containing a number of breaking changes.

New decorator

All service-specific decorators have been replaced with single decorator.

@mock_aws
def test():
    ...

Having a single decorator simplifies the usage of Moto, fixes a whole class of bugs surrounding state management, and will make it easier for us to add additional features in the future.

Were you using the mock_batch_simple or mock_lambda_simple decorator? These can be replaced with a new config-parameter:

@mock_aws(config={
    "batch": {"use_docker": False},
    "lambda": {"use_docker": False}
})
def test():
    ...

Passthrough AWS requests

You can also configure Moto to let some requests through to AWS. By default everything will still be mocked, except for requests that match a URL configured here, or that are part of a service listed here.

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

Note the mock_credentials part. Moto explicitly mocks AWS credentials, to ensure that we're not accidentally reaching out to AWS. This safeguard has to be disabled for this feature to work, as you will get InvalidCredentials exceptions if the credentials are still mocked.

IAM Managed Policies

Moto no longer loads AWS Managed Policies by default. They will only be created if explicitly configured to do so:
@mock_aws(config={"iam": {"load_aws_managed_policies": True}})

Or by setting an environment variable:
MOTO_IAM_LOAD_MANAGED_POLICIES=true

MotoServer

When starting the MotoServer, the service-argument (i.e.: moto_server s3) is no longer supported. It is recommended to use a single MotoServer instance, instead of a specific instance per AWS service.

We've just released 5.0.0 with these changes. Please try it out, and raise any issues that you find.

The documentation for v5 can be found here: http://docs.getmoto.org/en/5.0.0/

@bblommers
Copy link
Collaborator Author

Moto V5 is now out. See the documentation here:

http://docs.getmoto.org/en/5.0.0/

jmsanders added a commit to dagster-io/dagster that referenced this issue Jan 29, 2024
Moto 5 changes its public API away from individual service mocks and
toward a generalized `mock_aws` decorator/context manager.

getmoto/moto#7198
@archinksagar
Copy link
Contributor

@bblommers Is Moto V5 backward compatible, Can we still use service-specfic decorators for existing tests?

@bblommers
Copy link
Collaborator Author

@archinksagar No, all service-specific decorators have been removed. The functionality carries over for 99% of usecases though, so a simple find-replace within your tests (@mock_[_a-z0-9]+ -> @mock_aws) should be enough to start using V5.

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

No branches or pull requests

2 participants