<#6438 [BUG] Can't download data from S3 using pol...
# flyte-github
c
#6438 [BUG] Can't download data from S3 using polars/pandas when running with
--remote
Issue created by HansBambel ### Describe the bug It is impossible for me to get data from S3 using either polars or pandas. The code runs fine when running locally, but as soon as the built docker-container from flyte is used, there is an error when trying to access the S3 bucket. The credentials are correctly read in (I printed them out). When I build a separate docker image with my own
Dockerfile
it works, so the issue must be in the way that Flyte builds the image. The errors: • Using pandas: File "/root/check_s3.py", line 28, in get_stats df = pd.read_parquet( ^^^^^^^^^^^^^^^^ File "/root/.venv/lib/python3.12/site-packages/pandas/io/parquet.py", line 667, in read_parquet return impl.read( ^^^^^^^^^^ File "/root/.venv/lib/python3.12/site-packages/pandas/io/parquet.py", line 274, in read pa_table = self.api.parquet.read_table( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/.venv/lib/python3.12/site-packages/pyarrow/parquet/core.py", line 1774, in read_table dataset = ParquetDataset( ^^^^^^^^^^^^^^^ File "/root/.venv/lib/python3.12/site-packages/pyarrow/parquet/core.py", line 1338, in init finfo = filesystem.get_file_info(path_or_paths) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pyarrow/_fs.pyx", line 588, in pyarrow._fs.FileSystem.get_file_info File "pyarrow/error.pxi", line 155, in pyarrow.lib.pyarrow_internal_check_status File "pyarrow/error.pxi", line 89, in pyarrow.lib.check_status File "pyarrow/_fs.pyx", line 1496, in pyarrow._fs._cb_get_file_info File "/root/.venv/lib/python3.12/site-packages/pyarrow/fs.py", line 322, in get_file_info info = self.fs.info(path) ^^^^^^^^^^^^^^^^^^ File "/root/.venv/lib/python3.12/site-packages/fsspec/asyn.py", line 118, in wrapper return sync(self.loop, func, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/.venv/lib/python3.12/site-packages/fsspec/asyn.py", line 103, in sync raise return_result File "/root/.venv/lib/python3.12/site-packages/fsspec/asyn.py", line 56, in _runner result[0] = await coro ^^^^^^^^^^ File "/root/.venv/lib/python3.12/site-packages/s3fs/core.py", line 1447, in _info out = await self._call_s3( ^^^^^^^^^^^^^^^^^^^^ File "/root/.venv/lib/python3.12/site-packages/s3fs/core.py", line 371, in _call_s3 return await _error_wrapper( ^^^^^^^^^^^^^^^^^^^^^ File "/root/.venv/lib/python3.12/site-packages/s3fs/core.py", line 146, in _error_wrapper raise err OSError: [Errno 22] Bad Request • Using polars: Traceback (most recent call last): File "/root/.venv/lib/python3.12/site-packages/flytekit/core/base_task.py", line 755, in dispatch_execute native_outputs = self.execute(**native_inputs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/.venv/lib/python3.12/site-packages/flytekit/core/python_function_task.py", line 229, in execute return self._task_function(**kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/check_s3.py", line 23, in get_stats df = pl.read_parquet( ^^^^^^^^^^^^^^^^ File "/root/.venv/lib/python3.12/site-packages/polars/_utils/deprecation.py", line 119, in wrapper return function(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/.venv/lib/python3.12/site-packages/polars/_utils/deprecation.py", line 119, in wrapper return function(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/.venv/lib/python3.12/site-packages/polars/io/parquet/functions.py", line 252, in read_parquet return lf.collect() ^^^^^^^^^^^^ File "/root/.venv/lib/python3.12/site-packages/polars/_utils/deprecation.py", line 93, in wrapper return function(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/.venv/lib/python3.12/site-packages/polars/lazyframe/frame.py", line 2224, in collect return wrap_df(ldf.collect(engine, callback)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ polars.exceptions.ComputeError: Generic S3 error: Error performing HEAD https://s3.eu-west-1.amazonaws.com/eidu-mlops/flyte/2025-04-30/curriculum/0000_part_00.parquet in 474.709375ms, after 2 retries, max_retries: 2, retry_timeout: 10s - HTTP error: error sending request This error occurred with the following context stack: [1] 'parquet scan' [2] 'sink' I can't image I'm the only one with this issue, since getting data from S3 is quite common. ### Expected behavior Output from the
describe()
function just like a local run or one built from the separate docker image. ### Additional context to reproduce pyproject.toml [project] name = "polars-docker" version = "0.1.0" description = "Add your description here" requires-python = ">=3.11" dependencies = [ "polars>=1.14.0", "pydantic-settings>=2.6.1", "flytekit>=1.15.3", "flytekitplugins-pydantic>=1.13.15", "flytekitplugins-polars>=1.15.3", "pyarrow>=20.0.0", ]
check_s3.py
import polars as pl import flytekit as fl from pydantic_settings import BaseSettings, SettingsConfigDict import pandas as pd class Settings(BaseSettings): model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8") AWS_ACCESS_KEY_ID: str = "" AWS_SECRET_ACCESS_KEY: str = "" AWS_REGION: str = "eu-west-1" settings = Settings(_env_file=".env") polars_image = fl.ImageSpec( registry="localhost:30000", name="polars_docker_flyte", platform="linux/arm64", requirements="uv.lock", ) @fl.workflow() def build_wf(): get_stats() storage_options = { "aws_access_key_id": settings.AWS_ACCESS_KEY_ID, "aws_secret_access_key": settings.AWS_SECRET_ACCESS_KEY, "aws_region": "eu-west-1", } @fl.task(container_image=polars_image) def get_stats(): print(storage_options) s3_file = ("s3://path/to/single/data/file/0000_part_00.parquet",) # s3_file = "s3://path/to/data/files/*.parquet", df = pl.scan_parquet( s3_file, storage_options=storage_options, ).collect() # Pandas # df = pd.read_parquet( # s3_file, # storage_options={ # "key": settings.AWS_ACCESS_KEY_ID, # "secret": settings.AWS_SECRET_ACCESS_KEY, # "client_kwargs": {"region_name": "eu-west-1"}, # }, # ) print(df.describe()) if name == "__main__": get_stats() My own Dockerfile # An example using multi-stage image builds to create a final image without uv. # First, build the application in the
/app
directory. # See
Dockerfile
for details. FROM ghcr.io/astral-sh/uv:python3.11-bookworm-slim AS builder ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy # Disable Python downloads, because we want to use the system interpreter # across both images. If using a managed Python version, it needs to be # copied from the build image into the final image; see
standalone.Dockerfile
# for an example. ENV UV_PYTHON_DOWNLOADS=0 WORKDIR /app RUN --mount=type=cache,target=/root/.cache/uv \ --mount=type=bind,source=uv.lock,target=uv.lock \ --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ uv sync --frozen --no-install-project --no-dev # Then, use a final image without uv FROM python:3.11-slim-bookworm # It is important to use the image that matches the builder, as the path to the # Python executable must be the same, e.g., using
python:3.11-slim-bookworm
# will fail. # Copy the application from the builder COPY --from=builder --chown=app:app /app /app # Place executables in the environment at the front of the path ENV PATH="/app/.venv/bin:$PATH" Run… flyteorg/flyte