How to use MinIO with the same function as S3 Use docker-compose

Overview

I tried to make it usable with docker for development even in the situation where AWS services can not be used due to various circumstances (contract problems, budget, etc.). The title is MinIO, but DynamoDB and MySQL are also available.

Advance preparation

docker-compose

version: '3.7'
services:
  dynamodb-local:
    build: ./dynamodb
    volumes:
      - dynamodb_data:/home/dynamodblocal/data
    ports:
      - 8000:8000
    command: -jar DynamoDBLocal.jar -dbPath ./data
  mysql:
    image: mysql:5.7
    command: mysqld --character-set-server=utf8 --collation-server=utf8_unicode_ci
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: 'password'
    ports:
      - 3306:3306
  minio1:
    image: minio/minio:RELEASE.2020-08-27T05-16-20Z
    volumes:
      - data1-1:/data1
      - data1-2:/data2
    ports:
      - "9000:9000"
    environment:
      MINIO_ACCESS_KEY: minio
      MINIO_SECRET_KEY: minio123
    command: server data1
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
      interval: 30s
      timeout: 20s
      retries: 3
volumes:
  dynamodb_data:
  db_data: {}
  data1-1:
  data1-2:
FROM amazon/dynamodb-local

WORKDIR /home/dynamodblocal

# UID=1000 → DynamoDB Local execution user
RUN mkdir data && chown -R 1000 data
minio1_1          | Endpoint:  http://172.20.0.4:9000  http://127.0.0.1:9000
minio1_1          |
minio1_1          | Browser Access:
minio1_1          |    http://172.20.0.4:9000  http://127.0.0.1:9000

Implementation of S3 function

import boto3
import os
from datetime import datetime

endpoint_url = os.getenv('S3_ENDPOINT', 'http://192.168.99.100:9000/')
aws_access_key_id = os.getenv('S3_ACCESS_KEY_ID', 'minio')
aws_secret_access_key_id = os.getenv('S3_SECRET_ACCESS_KEY_ID', 'minio123')

s3 = boto3.resource(
    's3',
    aws_access_key_id=aws_access_key_id,
    aws_secret_access_key=aws_secret_access_key_id,
    endpoint_url=endpoint_url
)

bucket=s3.Bucket('testbukcet')
bucket.create()
bucketPath=os.path.join('dir',datetime.now().strftime('%Y%m%d%H%M%S'),'out','test.csv')
filePath=bucketPath.replace('\\','/')
bucket.upload_file('test.csv',filePath)

Recommended Posts

How to use MinIO with the same function as S3 Use docker-compose
[Java] How to use the hasNext function
[Processing × Java] How to use the function
How to use the link_to method
How to use the include? method
How to use the wrapper class
How to use mssql-tools with alpine
How to add the delete function
How to use the same Mapper class in multiple data sources with Spring Boot + MyBatis
[Note] How to restart the Windows container set up with docker-compose
[Java] How to use the File class
How to use BootStrap with Play Framework
[Rails] How to use rails console with docker
[Java] How to use the HashMap class
[Rails] How to use the map method
[Java] How to use the toString () method
Studying how to use the constructor (java)
[Processing × Java] How to use the loop
[Swift] How to implement the countdown function
How to use the function implemented in Kotlin Interface introduced in Maven as the default implementation from Java 8
[Processing × Java] How to use the class
How to implement TextInputLayout with validation function
How to monitor nginx with docker-compose with datadog
[Java] How to use the Calendar class
How to deploy to AWS using NUXTJS official S3 and CloudFront? With docker-compose
How to access Socket directly with the TCP function of Spring Integration
How to use the camera module OV7725 (ESP32-WROVER-B)
[Java] How to use Thread.sleep to pause the program
Use with_options to group the same validations together!
How to use MyBatis2 (iBatis) with Spring Boot 1.4 (Spring 4)
How to use built-in h2db with spring boot
[Swift] How to implement the LINE login function
How to use Java framework with AWS Lambda! ??
[swift5] How to implement the Twitter share function
How to implement the breadcrumb function using gretel
[Swift] How to link the app with Firebase
[For beginners] How to implement the delete function
Output of how to use the slice method
How to use Java API with lambda expression
How to use the replace () method (Java Silver)
How to use nfs protocol version 2 with ubuntu 18.04
How to use docker compose with NVIDIA Jetson
How to use nginx-ingress-controller with Docker for Mac
[Ruby basics] How to use the slice method
[Rails6] How to connect the posting function generated by Scaffold with the user function generated by devise
How to delete the tweet associated with the user when you delete it at the same time
How to change the action with multiple submit buttons
If you use SQLite with VSCode, use the extension (how to see the binary file of sqlite3)
How to run the SpringBoot app as a service
How to use Map
How to use rbenv
How to use Oracle JDK 9 EA with Travis CI
How to make LINE messaging function made with Ruby
How to use letter_opener_web
How to use with_option
How to use fields_for
How to use java.util.logging
[Ruby On Rails] How to use simple_format to display the entered text with line breaks
How to use Z3 library in Scala with Eclipse
How to use collection_select
[Rails] I don't know how to use the model ...