An error occurred (InvalidArgument) when calling the ListBuckets operation: S3 API Requests must be made to API port
Asked Answered
W

1

5

We are using Minio for local testing of S3 AND we have created docker-compose file with Minio and our app dependency is as follows:

Docker-Compose File:

version: "2.1"

services:
  minio:
    image: minio/minio
    container_name: minio
    ports:
      - 9001:9001
    volumes:
      - minio_storage:/data
    environment:
      MINIO_ACCESS_KEY: minio
      MINIO_SECRET_KEY: minio123
      MINIO_REGION: us-east-1
    command: server /data --console-address ":9001"
    mem_limit: 512m

  populate-minio-data:
    container_name: "minio-data"
    image: minio/mc
    volumes:
      - ./hello.txt:/tmp/hello.txt
    entrypoint: >
      /bin/sh -c "
      /usr/bin/mc config host rm local;
      /usr/bin/mc config host add --quiet --api s3v4 local http://minio:9001 minio minio123;
      /usr/bin/mc mb --quiet local/somebucketname1/;
      /usr/bin/mc policy set public local/somebucketname1;
      /usr/bin/mc cp /tmp/hello.txt local/somebucketname1/hello.txt;
      "
    depends_on:
      - minio


  archive-api-app:
    image: openjdk:11
    container_name: "archive-api-app"
    ports:
      - 8091:6001
    volumes:
      - /home/apcuser/dev/projects/ea-archive-service-v2/projects/application/archive-api:/app
    command: [ 'java', '-jar', '/app/build/libs/archive-api-1.0.0.jar' ]
    env_file:
      - ./vars/default.env

volumes:
  minio_storage:

And In java code, I have configured MINIO URL as S3 Endpoint as follows:

 @Bean
    public AmazonS3 getS3Client() {
        return AmazonS3ClientBuilder.standard()
                .withClientConfiguration(new ClientConfiguration().withMaxConnections(maxConnections)
                        .withConnectionTimeout(connectionTimeout).withMaxErrorRetry(maxRetry))
            .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("http://minio:9001", "us-east-1"))
                .build();
    }

Once, I run docker-compose file,I am able to see minio-ui in my local Linux machine as follows:

enter image description here

But I am not seeing any data in Minio, instead, I am seeing the below error while uploading data in minio:

Attaching to minio-data
minio-data             | Removed `local` successfully.
minio-data             | Added `local` successfully.
minio-data             | mc: <ERROR> Unable to make bucket `local/somebucketname1/`. S3 API Requests must be made to API port.
minio-data             | mc: <ERROR> Unable to set policy `public` for `local/somebucketname1`. S3 API Requests must be made to API port.
minio-data             | `/tmp/hello.txt` -> `local/somebucketname1/hello.txt`
minio-data             | mc: <ERROR> Failed to copy `/tmp/hello.txt`. S3 API Requests must be made to API port.
minio-data             | Total: 0 B, Transferred: 0 B, Speed: 0 B/s

Even same error I am seeing When I am trying to list MINIO data from my local linux host machine:

export AWS_ACCESS_KEY_ID=minio
export AWS_SECRET_ACCESS_KEY=minio123
export AWS_REGION=us-east-1

aws --endpoint-url http://127.0.0.1:9001 s3 ls

**An error occurred (InvalidArgument) when calling the ListBuckets operation: S3 API Requests must be made to API port.**

Can anyone help here, please?

Wakerife answered 15/9, 2022 at 8:13 Comment(0)
W
10

The error message indicates that you need to use the API port instead of console port while using mc.

/usr/bin/mc config host add --quiet --api s3v4 local http://minio:9001 minio minio123;

You need to use port 9000 instead of 9001.

Weksler answered 17/9, 2022 at 5:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.