pythonamazon-s3minio

S3 Minio: An error occurred (400) when calling the HeadBucket operation: Bad Request"}


I am trying to run S3 environment locally

I created docker-compose dile

services:
  # docker-compose up is not working on MacOS because of EFK services 
  s3:
    image: minio/minio
    command: server --console-address ":9001" /data
    container_name: minio-s3
    ports:
      - "9000:9000"
      - "9001:9001"
    volumes:
      - minio_storage:/data
    environment:
      MINIO_ROOT_USER: minio
      MINIO_ROOT_PASSWORD: minio_pass
      MINIO_ACCESS_KEY: ***
      MINIO_SECRET_KEY: ***
      MINIO_DOMAIN: s3minio.ru
    restart: always
    networks:
      default:
        aliases:
          - api.s3minio.ru

Logged into http://127.0.0.1:9001/browser, created buckets, created access and secret keys Updated docker-compose file with access and secret keys

My code

import boto3
import botocore

access_key = None
secret_key = None

access_key = "CNLliwavcrqJIWAbfb7i"
secret_key = "VGEAJoqb0q1vJpqVqqe2Nno5F97xQsvQmtj7cQiw"

aws_config = boto3.session.Config (
    signature_version='s3v4',
    connect_timeout=100,
)
s3_client = boto3.client('s3',
        endpoint_url="http://127.0.0.1:9001",
        aws_access_key_id=access_key,
        aws_secret_access_key=secret_key,
        aws_session_token=None,
        config=aws_config,
        verify=False
)
s3_client.head_bucket(Bucket="bucket-in")

Error

Traceback (most recent call last):
  ...python3.8/site-packages/botocore/client.py", line 719, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (400) when calling the HeadBucket operation: Bad Request

Solution

  • Change the port in endpoint_url="http://127.0.0.1:9001" to 9000.

    Port 9001 is web-ui for Minio, port 9000 is actual S3 endpoint.