Package: amazon-efs
Amazon EFS (amazon-efs)Amazon EFS (amazon-efs) allows programmatically manipulate EFS data (create, read, delete, list files) from any machine.Prerequisitespythonpipboto3AWS AccountAWS CredentialsInstallpip install amazon-efsWarningEFS should have at least one mount target in a Private subnetLimitsLambda compute envlist_files,upload,download,deleteactions are limited by 15 minutes execution time (AWS Lambda works under the hood)Batch compute envlist_files,upload,downloadactions are not implemented yetBasicsSupported compute environments:Lambda (Default)BatchLambda compute environment (by default):efs = Efs('<file_system_id>')Lambda compute environment:efs = Efs('<file_system_id>', compute_env_name='lambda')Batch compute environment:The "batch_queue" option is requiredefs = Efs('<file_system_id>', {
    'batch_queue': '<batch_queue>',
}, compute_env_name='batch')Lambda compute environmentThis computing environment is used for lightweight operations (lasting no more than 15 minutes).from amazon_efs import Efs

efs_id = 'fs-0d74736bfc*******'
efs = Efs(efs_id)

# Deploying required underlying resources
efs.init()
# Actions (e.g. list_files, upload, download, delete)
files_list = efs.list_files()
# Don't forget to destroy underlying resources at the end of the session
efs.destroy()ActionsList filesfrom amazon_efs import Efs

efs_id = 'fs-0d74736bfc*******'
efs = Efs(efs_id)

efs.init()

files_list = efs.list_files()
print(files_list)
files_list = efs.list_files('dir1')
print(files_list)
files_list = efs.list_files('dir1/dir2')
print(files_list)

efs.destroy()Uploadfrom amazon_efs import Efs

efs_id = 'fs-0d74736bfc*******'
efs = Efs(efs_id)

efs.init()

efs.upload('file.txt')
efs.upload('file.txt', 'dir1/new_file.txt')
efs.upload('file.txt', 'dir1/dir2/new_file.txt')
efs.upload('file.txt', 'dir1/dir3/new_file.txt')
efs.upload('file.txt', 'dir2/dir3/new_file.txt')
efs.upload('file.txt', 'dir2/dir4/new_file.txt')

efs.destroy()Downloadfrom amazon_efs import Efs

efs_id = 'fs-0d74736bfc*******'
efs = Efs(efs_id)

efs.init()

efs.download('dir1/dir3/new_file.txt', 'file1.txt')

efs.destroy()DeleteDelete filefrom amazon_efs import Efs
    
efs_id = 'fs-0d74736bfc*******'
efs = Efs(efs_id)
    
efs.init()
    
efs.delete('dir2/dir3/new_file.txt')
    
efs.destroy()Delete folderfrom amazon_efs import Efs
    
efs_id = 'fs-0d74736bfc*******'
efs = Efs(efs_id)
    
efs.init()
    
efs.delete('dir1/dir2/*')
efs.delete('dir1/*')
    
efs.destroy()Async deleteUse it if you want to schedule deletion and monitor progress yourself.from amazon_efs import Efs
    
efs_id = 'fs-0d74736bfc*******'
efs = Efs(efs_id)
    
state = efs.init()
    
http_response_status_code = efs.delete('dir2/dir3/new_file.txt')Then, after the job is completed, destroy the infrastructure.efs = Efs(efs_id, { 'state': state })
efs.destroy()Batch compute environmentThis computing environment is used for heavy operations (lasting more than 15 minutes).ActionsDeleteThe "batch_queue" option is requiredDelete filefrom amazon_efs import Efs
    
efs_id = 'fs-0d74736bfc*******'
batch_queue = '<batch_queue>'
efs = Efs(efs_id, {
  'batch_queue': batch_queue,
}, compute_env_name='batch')
    
efs.init()
    
efs.delete('dir2/dir3/new_file.txt')
    
efs.destroy()Delete folderfrom amazon_efs import Efs
    
efs_id = 'fs-0d74736bfc*******'
batch_queue = '<batch_queue>'
efs = Efs(efs_id, {
  'batch_queue': batch_queue,
}, compute_env_name='batch')
    
efs.init()
    
efs.delete('dir1/dir2/*')
efs.delete('dir1/*')
    
efs.destroy()Async deleteUse it if you want to schedule deletion and monitor progress yourself.from amazon_efs import Efs
    
efs_id = 'fs-0d74736bfc*******'
batch_queue = '<batch_queue>'
efs = Efs(efs_id, {
  'batch_queue': batch_queue,
}, compute_env_name='batch')
    
state = efs.init()
    
batch_job_arn = efs.delete('dir2/dir3/new_file.txt')Then, after the job is completed, destroy the infrastructure.efs = Efs(efs_id, { 'state': state }, compute_env_name='batch')
efs.destroy()StateYou can destroy underlying infrastructure even after destroying EFS object from RAM if you saved thestatefrom amazon_efs import Efs

efs_id = 'fs-0d74736bfc*******'
efs = Efs(efs_id)

state = efs.init()

# Destroy object
del efs

efs = Efs(efs_id, { 'state': state })

files_list = efs.list_files()
print(files_list)

efs.destroy()TagsYou can add custom tags to underlying resourcesfrom amazon_efs import Efs

efs_id = 'fs-0d74736bfc*******'
efs = Efs(efs_id, {
    'tags': {
        'k1': 'v1',
        'k2': 'v2'
    }
})

efs.init()

files_list = efs.list_files()
print(files_list)

efs.destroy()Loggingfrom amazon_efs import Efs
import logging

fs_id = 'fs-0d74736bfc*******'

logger = logging.getLogger()
logging.basicConfig(level=logging.ERROR, format='%(asctime)s: %(levelname)s: %(message)s')

efs = Efs(fs_id, logger=logger)