Skip to main content

A CLI/SDK which automatically uploads pip packages and directories to aws efs to be used in aws lambda

Project description

🚀 efsync - Open-Source MLOps tool for running serverless machine learning

Downloads Open In Colab pypi package deployment PyPI version

efsync is an CLI/SDK tool, which automatically syncs files and dependencies to AWS EFS. The CLI is easy to use, you only need access to an AWS Account, an AWS EFS-filesystem up and running. I wrote an article with an complete walkthrough. you can check this one out here or simply start with the Quick Start. Efsync enables you to install dependencies with the AWS Lambda runtime directly into your EFS filesystem and use them in your AWS Lambda function. It enables you either combine this with syncing files from S3 or uploading them with SCP. You can also sync files from S3 and upload with SCP without installing Pip dependencies.

i created several examples for every usecase.

CLI Example

Outline

🏃🏻‍♂️ Quick Start

Example in Google Colab. Open In Colab

  1. Install via pip3
pip3 install efsync
  1. sync your pip dependencies or files to AWS EFS

usage with the cli

efsync -cf efsync.yaml

or with python

from efsync import efsync

efsync('efsync.yaml')

⚙️ Configurations

There are 4 different ways to use efysnc in your project. You can create a yaml configuration and use the SDK, you can create a python dict and use the SDK, you can create a yaml configuration and use the CLI, or you can use the CLI with parameters. Below you can find examples for each of these. I also included afterwards configuration examples for the different use cases.

Configuration with yaml file efsync.yaml

#standard configuration
efs_filesystem_id: fs-2adfas123 # aws efs filesystem id (moint point)
subnet_Id: subnet-xxx # subnet of which the efs is running in
ec2_key_name: efsync-asd913fjgq3 # required key name for starting the ec2 instance
clean_efs: all # Defines if the EFS should be cleaned up before. values: `'all'`,`'pip'`,`'file'` uploading
# aws profile configuration
aws_profile: efsync # aws iam profile with required permission configured in .aws/credentials
aws_region: eu-central-1 # the aws region where the efs is running

# pip dependencies configurations
efs_pip_dir: lib # pip directory on ec2
python_version: 3.8 # python version used for installing pip dependencies -> should be used as lambda runtime afterwads
requirements: requirements.txt # path + file to requirements.txt which holds the installable pip dependencies

# s3 config
s3_bucket: my-bucket-with-files # s3 bucket name from files should be downloaded
s3_keyprefix: models/bert # s3 keyprefix for the files
file_dir_on_ec2: ml # name of the directory where your file from <file_dir> will be uploaded

# upload files with scp to efs
file_dir: local_dir # extra local directory for file upload like ML models
from efsync import efsync

efsync('efsync.yaml')

Configuration with CLI Parameters

efsync  --efs_filesystem_id  fs-2adfas123 \
        --subnet_Id subnet-xxx \
        --ec2_key_name efsync-asd913fjgq3 \
        --clean_efs all \
        --aws_profile efysnc \
        --aws_region yo-region-1 \
        --efs_pip_dir lib \
        --python_version 3.8 \
        --requirements requirements.txt \
        --s3_bucket my-bucket-with-files \
        --s3_keyprefix models/bert \
        --file_dir local_dir \
        --file_dir_on_ec2 ml

Configuration with CLI and yaml

efsync -cf efsync.yaml

Configuration with python dictonary

config = {
  'efs_filesystem_id': 'fs-2adfas123', # aws efs filesystem id (moint point)
  'subnet_Id': 'subnet-xxx', # subnet of which the efs is running in
  'ec2_key_name':'efsync-asd913fjgq3',  # required key name for starting the ec2 instance
  'clean_efs': 'all', # Defines if the EFS should be cleaned up before. values: `'all'`,`'pip'`,`'file'` uploading
  'aws_profile': 'efysnc', # aws iam profile with required permission configured in .aws/credentials
  'aws_region': 'eu-central-1', # the aws region where the efs is running
  'efs_pip_dir': 'lib',  # pip directory on ec2
  'python_version': 3.8,  # python version used for installing pip dependencies -> should be used as lambda runtime afterwads
  'requirements': 'requirements.txt', # path + file to requirements.txt which holds the installable pip dependencies
  'file_dir': 'local_dir', # extra local directory for file upload like ML models
  'file_dir_on_ec2': 'ml', # name of the directory where your file from <file_dir> will be uploaded
  's3_bucket': 'my-bucket-with-files', # s3 bucket name from files should be downloaded
  's3_keyprefix': 'models/bert' # s3 keyprefix for the files
}

from efsync import efsync

efsync(config)

✍🏻 Usecase Configuration with yaml examples

Only installing Pip dependencies

#standard configuration
efs_filesystem_id: fs-2adfas123 # aws efs filesystem id (moint point)
subnet_Id: subnet-xxx # subnet of which the efs is running in
ec2_key_name: efsync-asd913fjgq3 # required key name for starting the ec2 instance
clean_efs: all # Defines if the EFS should be cleaned up before. values: `'all'`,`'pip'`,`'file'` uploading
# aws profile configuration
aws_profile: efsync # aws iam profile with required permission configured in .aws/credentials
aws_region: eu-central-1 # the aws region where the efs is running

# pip dependencies configurations
efs_pip_dir: lib # pip directory on ec2
python_version: 3.8 # python version used for installing pip dependencies -> should be used as lambda runtime afterwads
requirements: requirements.txt # path + file to requirements.txt which holds the installable pip dependencies

Installing Pip dependencies and syncing files from s3 to efs

#standard configuration
efs_filesystem_id: fs-2226b27a # aws efs filesystem id (moint point)
subnet_Id: subnet-17f97a7d # subnet of which the efs is running in
ec2_key_name: efsync-asd913fjgq3 # required key name for starting the ec2 instance
clean_efs: all # Defines if the EFS should be cleaned up before. values: `'all'`,`'pip'`,`'file'` uploading
# aws profile configuration
aws_profile: efsync # aws iam profile with required permission configured in .aws/credentials
aws_region: eu-central-1 # the aws region where the efs is running

# pip dependencies configurations
efs_pip_dir: lib # pip directory on ec2
python_version: 3.8 # python version used for installing pip dependencies -> should be used as lambda runtime afterwads
requirements: requirements.txt # path + file to requirements.txt which holds the installable pip dependencies

# s3 config
s3_bucket: efsync-test-bucket # s3 bucket name from files should be downloaded
s3_keyprefix: distilbert # s3 keyprefix for the files
file_dir_on_ec2: ml # name of the directory where your file from <file_dir> will be uploaded

Only syncing files from s3 to efs

#standard configuration
efs_filesystem_id: fs-2226b27a # aws efs filesystem id (moint point)
subnet_Id: subnet-17f97a7d # subnet of which the efs is running in
ec2_key_name: efsync-asd913fjgq3 # required key name for starting the ec2 instance
clean_efs: all # Defines if the EFS should be cleaned up before. values: `'all'`,`'pip'`,`'file'` uploading
# aws profile configuration
aws_profile: efsync # aws iam profile with required permission configured in .aws/credentials
aws_region: eu-central-1 # the aws region where the efs is running

# s3 config
s3_bucket: efsync-test-bucket # s3 bucket name from files should be downloaded
s3_keyprefix: distilbert # s3 keyprefix for the files
file_dir_on_ec2: ml # name of the directory where your file from <file_dir> will be uploaded

Installing Pip dependencies and uploading local files with scp to efs

#standard configuration
efs_filesystem_id: fs-2226b27a # aws efs filesystem id (moint point)
subnet_Id: subnet-17f97a7d # subnet of which the efs is running in
ec2_key_name: efsync-asd913fjgq3 # required key name for starting the ec2 instance
clean_efs: all # Defines if the EFS should be cleaned up before. values: `'all'`,`'pip'`,`'file'` uploading
# aws profile configuration
aws_profile: efsync # aws iam profile with required permission configured in .aws/credentials
aws_region: eu-central-1 # the aws region where the efs is running

# upload files with scp to efs
file_dir: local_dir # extra local directory for file upload like ML models
file_dir_on_ec2: ml # name of the directory where your file from <file_dir> will be uploaded

Only uploading local files with scp to efs

#standard configuration
efs_filesystem_id: fs-2226b27a # aws efs filesystem id (moint point)
subnet_Id: subnet-17f97a7d # subnet of which the efs is running in
ec2_key_name: efsync-asd913fjgq3 # required key name for starting the ec2 instance
clean_efs: all # Defines if the EFS should be cleaned up before. values: `'all'`,`'pip'`,`'file'` uploading
# aws profile configuration
aws_profile: efsync # aws iam profile with required permission configured in .aws/credentials
aws_region: eu-central-1 # the aws region where the efs is running

# pip dependencies configurations
efs_pip_dir: lib # pip directory on ec2
python_version: 3.8 # python version used for installing pip dependencies -> should be used as lambda runtime afterwads
requirements: requirements.txt # path + file to requirements.txt which holds the installable pip dependencies

# upload files with scp to efs
file_dir: local_dir # extra local directory for file upload like ML models
file_dir_on_ec2: ml # name of the directory where your file from <file_dir> will be uploaded

🏗 Examples

I provided several jupyter notebooks with examples. There are examples for installing pip dependencies only, installing pip dependencies and syncing files from s3 to efs, downloading only files from s3, installing pip dependencies and uploading files from local with scp and only uploading files with scp. All examples can be run in a Google Colab Notebook.

simplest usage:

from efsync import efsync

efsync('efsync.yaml')

CLI Parameteres

cli_short cli_long default description
-h --help - displays all commands
-r --requirements requirements.txt path of your requirements.txt
-cf --config_file - path of your efsync.yaml
-py --python_version 3.8 Python version used to install dependencies
-epd --efs_pip_dir lib directory where the pip dependencies will be installed on efs
-efi --efs_filesystem_id - File System ID from the EFS filesystem
-ce --clean_efs - Defines if the EFS should be cleaned up before. values: 'all','pip','file' uploading
-fd --file_dir tmp directory where all other files will be placed
-fdoe --file_dir_on_ec2 tmp name of the directory where your file from <file_dir> will be uploaded
-ap --aws_profile efsync name of the used AWS profile
-ar --aws_region eu-central-1 aws region where the efs is running
-sbd --subnet_Id - subnet id of the efs
-ekn --ec2_key_name - temporary key name for the ec2 instance
-s3b --s3_bucket - s3 bucket name from where the files will be downloaded instance
-s3k --s3_keyprefix - s3 keyprefix of the directory in s3. Files will be downloaded recursively

🔗 Connect with me

Personal Website Twitter Medium LinkedIn

🏥 Contributing

If you want to contribute be sure to review the contributions guidelines.

📃 License

A copy of the License is provided in the LICENSE file in this repository.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

efsync-0.9.24.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

efsync-0.9.24-py3-none-any.whl (20.8 kB view details)

Uploaded Python 3

File details

Details for the file efsync-0.9.24.tar.gz.

File metadata

  • Download URL: efsync-0.9.24.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for efsync-0.9.24.tar.gz
Algorithm Hash digest
SHA256 5411bb4f1d3b3624be004ca2b798c6c75462b8deed2d55b7093d3e69862effc9
MD5 37a07772697348bfb3a18c3bd81d0ce1
BLAKE2b-256 4ca48bf5e1ef15b3ce423d2c7179e09b2ad04d827f7afea354fbd44b832c5acd

See more details on using hashes here.

Provenance

File details

Details for the file efsync-0.9.24-py3-none-any.whl.

File metadata

  • Download URL: efsync-0.9.24-py3-none-any.whl
  • Upload date:
  • Size: 20.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for efsync-0.9.24-py3-none-any.whl
Algorithm Hash digest
SHA256 dacc5c3577474676ccfca812948b7c3bbbc38ec1dea1ff8c8d1a5298b117a286
MD5 d94d753e2ea2fca447e11ccff4de93e4
BLAKE2b-256 bcafcd7139d8b037a53a02c857a357bc675e330a1d4b54e09d821f416a1599d4

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page