I have a project here that is a working signed-url S3 uploader (on real S3.) On localstack, I get 500 error, and logs show this when I try to upload a file:
2020-09-24 11:01:46,055:API: Error on request:
Traceback (most recent call last):
File "/opt/code/localstack/.venv/lib/python3.8/site-packages/werkzeug/serving.py", line 323, in run_wsgi
execute(self.server.app)
File "/opt/code/localstack/.venv/lib/python3.8/site-packages/werkzeug/serving.py", line 312, in execute
application_iter = app(environ, start_response)
File "/opt/code/localstack/.venv/lib/python3.8/site-packages/moto/server.py", line 167, in __call__
return backend_app(environ, start_response)
File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 2464, in __call__
return self.wsgi_app(environ, start_response)
File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 2450, in wsgi_app
response = self.handle_exception(e)
File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask_cors/extension.py", line 161, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 1867, in handle_exception
reraise(exc_type, exc_value, tb)
File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask_cors/extension.py", line 161, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/opt/code/localstack/.venv/lib/python3.8/site-packages/moto/core/utils.py", line 146, in __call__
result = self.callback(request, request.url, {})
File "/opt/code/localstack/.venv/lib/python3.8/site-packages/moto/s3/responses.py", line 237, in ambiguous_response
return self.bucket_response(request, full_url, headers)
File "/opt/code/localstack/.venv/lib/python3.8/site-packages/moto/s3/responses.py", line 246, in bucket_response
response = self._bucket_response(request, full_url, headers)
File "/opt/code/localstack/.venv/lib/python3.8/site-packages/moto/s3/responses.py", line 284, in _bucket_response
body = body.decode("utf-8")
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
What do I need to do to make it work, as it does on real S3?
I'll answer my own question. it was localstack/issues#1410. My example now works.
The short of it is add
s3ForcePathStyle: true
to options, so it correctly generates signed-URL