Amazon EFS (amazon-efs) allows programmatically manipulate EFS data (create, read, delete, list files) from any machine.
Project description
Amazon EFS (amazon-efs)
Amazon EFS (amazon-efs) allows programmatically manipulate EFS data (create, read, delete, list files) from any machine.
Prerequisites
- python
- pip
- boto3
- AWS Account
- AWS Credentials
Install
pip install amazon-efs
Warning
EFS should have at least one mount target in a Private subnet
Limits
list_files, upload, download, delete actions are limited by 15 minutes execution time (AWS Lambda works under the hood)
Basics
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()
Actions
List files
from 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()
Upload
from 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()
Download
from 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()
Delete
Delete file
from amazon_efs import Efs
efs_id = 'fs-0d74736bfc*******'
efs = Efs(efs_id)
efs.init()
efs.delete('dir2/dir3/new_file.txt')
efs.destroy()
Delete folder
from amazon_efs import Efs
efs_id = 'fs-0d74736bfc*******'
efs = Efs(efs_id)
efs.init()
efs.delete('dir1/dir2/*')
efs.delete('dir1/*')
efs.destroy()
State
You can destroy underlying infrastructure even after destroying EFS object from RAM if you saved the state
from 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()
Tags
You can add custom tags to underlying resources
from 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()
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
amazon-efs-0.0.13.tar.gz
(7.9 kB
view hashes)
Built Distribution
Close
Hashes for amazon_efs-0.0.13-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6cdcbeb6495dadeb734e6a1c1a0bb09f22ff5ab6257d3807a6d8fe11fb1fb50e |
|
MD5 | 63432edcd327d10baf361279dfac07ea |
|
BLAKE2b-256 | 28652c2ca96d3121236c4472a0320f74847bf101aafba169a2319ecd20d28818 |