Started here: localstack/localstack#12933 (comment)
Then moved here: aws/aws-cli#9629
Which helped me figure out the issue. awslocal patches create_client to configure the s3 endpoint specifically when running certain commands.
It looks like v1.41.9 of aws-cli wraps create_client in create_nested_client. I'm not an avid python user so I'm not 100% sure what is going on here but it seems like this overrides the wrapping that awslocal does.
I think the solution should be pretty simple. There is an AWS_ENDPOINT_URL that can be set per service or for all services. Setting this environment variable in prepare_environment should replace the necessity of a lot of the rest of the wrapper I think