Giter Site home page Giter Site logo

s3fileuploader's Introduction

Build Status Coverage Status

Mini programa para subir archivos a un bucket S3

El objetivo de este programa es enviar archivos almacenados en la máquina local a un bucket en el servicio S3 de AWS.

Es importante destacar que para que funcione el envío, las credenciales dadas a boto3 (librería cliente de aws) deben tener permisos de escritura.

Requisitos

  • Python 3
  • dependencias (mirar archivo requirements.txt)

Instalación

Se recomienda la utilización de un entorno virtual, puedes crearlo dentro de la misma carpeta.

virtualenv venv

En caso de tener python 2.7 por defecto es necesario definir que sea python3 para el entorno virtual

virtualenv -p python3 venv

Luego se debe activar el entorno virtual e instalar las dependencias.

# activar
source venv/bin/activate
 
# instalar dependencias
pip install -r requirements.txt

El siguiente paso es generar el archivo que almacenará las llaves de acceso a aws. Este archivo debe llamarse .env y su contenido es el siguiente:

AWS_ACCESS_KEY_ID='PUT_HERE_YOUR_ACCESS_KEY'
AWS_SECRET_ACCESS_KEY='PUT_HERE_YOUR_SECRET_ACCESS_KEY'

PUT_HERE_YOUR_ACCESS_KEY y PUT_HERE_YOUR_SECRET_ACCESS_KEY se obtienen de un usuario de aws (https://console.aws.amazon.com/iam/home?#/users), sección 'Credenciales de seguridad'

Ejecutar pruebas

Para comprobar que todo está en orden puede ejecutar los tests.

python -m unittest discover

Ejecutar programa

Existen dos comandos: upload_to_s3.py y delete_object_in_s3.py. El primero sube uno o más archivos a un bucket en S3 y el segundo permite eliminar un objecto (archivo) en s3.

Ejemplo de ejecución

Comando upload_to_s3.py

python upload_to_s3.py ruta/a/archivo*.gz nombre_bucket

Notar que la ruta al archivo puede ser un patrón, esto permite subir varios archivos a la vez.

Ayuda

# consultar ayuda
python upload_to_s3.py --help

usage: upload_to_s3.py [-h] [--omit-filename-check] [--replace]
                       file [file ...] bucket

move document to S3 bucket

positional arguments:
  file                  data file path. It can be a pattern, e.g. /path/to/file or /path/to/file*.zip
  bucket                bucket name. Valid options are:

optional arguments:
  -h, --help            show this help message and exit
  --omit-filename-check It Accepts filenames with distinct format to YYYY-mm-dd.*
  --replace             It replaces file if exists in bucket, default behavior ask to user a confirmation

Comando delete_object_in_s3.py

python delete_object_in_s3.py nombre_archivo nombre_bucket

A diferencia del comando anterior el primer parámetro es el nombre del archivo, no la ruta en el disco local.

Ayuda

# consultar ayuda
python delete_object_in_s3.py --help
 
usage: delete_object_in_s3.py [-h] filename bucket

delete an object from S3 bucket

positional arguments:
  filename    filename to delete in bucket
  bucket      bucket name. Valid options are:

optional arguments:
  -h, --help  show this help message and exit

Comando download_from_s3.py

python download_from_s3.py nombre_archivo nombre_bucket --destination-path /home/user

El primer parámetro es el nombre del archivo a descargar, el segundo corresponde al nombre del bucket en que se encuentra el archivo, y por último, existe un parámetro opcional que permite definir la ruta donde se guardará el archivo, si es omitido el archivo será guardado en el current working directory (dado por os.getcwd())

Ayuda

# consultar ayuda
python download_from_s3.py --help
 
usage: download_from_s3.py [-h] [--destination-path DESTINATION_PATH]
                           filename [filename ...] bucket

download one or more objects from S3 bucket

positional arguments:
  filename              one or more filenames
  bucket                bucket name

optional arguments:
  -h, --help            show this help message and exit
  --destination-path DESTINATION_PATH
                        path where files will be saved, if it is not provided
                        we will use current path

s3fileuploader's People

Contributors

felipinbombin avatar bastianleaf avatar mzunigag avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.