AWS DB Migration
Short description
Project used to migrate relatively small databases from local machine to cloud and vice versa.
Long description
Project that can migrate your local MySql database to an AWS cloud database and vice versa.
This project runs on AWS Lambda function and on a local machine.
Migration is executed in 3 steps: creating mysql dump file, uploading it to S3, restoring the database from a file.
Migration from local to cloud looks like this: A mysql dump file from a local database is created, the file is uploaded to S3, a lambda function (this project) is invoked to restore a cloud database from a recently uploaded S3 file.
Migration from cloud to local looks like this: A lambda function (this project) is invoked to create a mysql dump file from a cloud database and upload it to S3. The most recent dump file is downloaded and a local database is restored from it.
Why lambda function? Why can't a direct migration between databases be achieved? Well, the answer is simple - of course it can! However in this case your cloud database is most likely deployed incorrectly. The cloud database should NOT be accessible to the whole internet. It should be deployed to a private subnet with a strict security group attached to it. This way the only way a migration between local and cloud can happen is through an additional AWS resource instance e.g. lambda, ec2, ecs, etc. This project has chosen Lambda to keep it light-weight.
Prerequisites
Local prerequisites
- Mysql server installed.
- Mysql client installed.
- Database set up.
- This project installed with:
pip install aws-db-migration
or:
./install.sh
Cloud prerequisites
- Mysql set up on aws cloud (e.g. RDS)
- This project deployed as a lambda function with a configured environment refer to .env.example file).
Usage
Note, this project must be deployed as a Lambda function and have access to your cloud database.
Note, that database credentials can be provided either with a DatabaseCredentials class or through environment variables (refer to .env.example file).
Migration to cloud
from aws_db_migration.run_local import RunLocal
from aws_db_migration.database_credentials import DatabaseCredentials
from aws_db_migration.aws_credentials import AwsCredentials
db_credentials = DatabaseCredentials(
username='username',
password='password',
database_name='database',
host='localhost',
port='3306'
)
aws_credentials = AwsCredentials()
RunLocal(aws_credentials, db_credentials).to_cloud()
Migration from cloud
from aws_db_migration.run_local import RunLocal
from aws_db_migration.database_credentials import DatabaseCredentials
from aws_db_migration.aws_credentials import AwsCredentials
db_credentials = DatabaseCredentials(
username='username',
password='password',
database_name='database',
host='localhost',
port='3306'
)
aws_credentials = AwsCredentials()
RunLocal(aws_credentials, db_credentials).from_cloud()
Adding post/pre triggers
from aws_db_migration.run_local import RunLocal
from aws_db_migration.database_credentials import DatabaseCredentials
from aws_db_migration.aws_credentials import AwsCredentials
def f1():
print('Pre-download!!!')
def f2():
print('Post-download!!!')
runner = RunLocal(AwsCredentials(), DatabaseCredentials())
runner.pre_download = f1
runner.post_download = f2
Release history
3.1.1
Dump databases in single transactions to avoid data corruptions.
3.1.0
Add ability to select database revision.
3.0.3
Using absolute paths to call amazon-linux-mysql(dump) libraries.
3.0.2
Fixed environment bug.
3.0.1
Critical bug (when backing up a database) fix.
3.0.0
Refactor the way aws credentials and parameters are provided.
2.0.4
Add example on how to add triggers.
2.0.3
README fixes.
2.0.2
Add README and HISTORY files.
2.0.1
Add parameter explanations in .env.example file.
2.0.0
Major project refactor and file renames.
Metadata
Release files for aws-db-migration 3.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| aws_db_migration-3.1.1.tar.gz | 19.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aws_db_migration-3.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 42.5 kB
Release files / aws_db_migration-3.1.1.tar.gz
| Download URL | aws_db_migration-3.1.1.tar.gz |
|---|---|
| Size | 19.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
48842a16a9cd1b34a182fb069e9a23391046c443cf6a82cfc493c97fbb80f5d2
|
|
BLAKE2b-256 checksum How to use checksums |
d1aa2f8b8461719722ffffb66bd9ac8bd6411fa55fb17ed21e5abd2c71112925
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/2.7.15+
|
Release files / aws_db_migration-3.1.1-py3-none-any.whl
| Download URL | aws_db_migration-3.1.1-py3-none-any.whl |
|---|---|
| Size | 23.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c693a3f65475749a6d778a89abf3667e5e89d12672c7ca0e670457d2da32cf27
|
|
BLAKE2b-256 checksum How to use checksums |
fa9976f0bada1a0b0a3928f3ce2a20f7b2c38fa94145ed5c81e80247fc989a3f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/2.7.15+
|
Security for aws-db-migration 3.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.