All files in users' projects are stored in Redis by IDE-server. When Redis runs out of memory, there will be eviction and the stored data could be deleted.
To prevent this situation, Project-Backup-Lambda periodically picks out projects that are not recently accessed but have active flags, and then migrates them from Redis to AWS S3.
- AWS EventBridge triggers
select_project
Lambda function every 30 minutes. It enqueues the project IDs that should be processed to AWS SQS. - AWS SQS triggers
backup_project
Lambda function for each message.
- Query
user_projects
table to select the projects that are not accessed for 10 minutes but have active flags. - For each project queried, send its ID to AWS SQS.
For each project from AWS SQS, the following processes are done:
- Get a file list of the project from Redis.
- Iterating the list, get file contents from Redis, and save the contents onto temporary directory.
- Compress the directory.
- Upload the compressed one to AWS S3.
- Remove the data from Redis.
- Set its flag as inactive.
- Node.js v14
- Python 3.9+
-
Install serverless framework and a plugin.
$ npm i serverless && sls plugin install -n serverless-python-requirements
-
Copy a config file and modify it for you.
$ cp configs.yml.example configs.yml
Note: You may have to use private subnets depending on your network configs.
-
Set SSH tunneling for you to be able to access AWS Elasticache.
AWS Elasticache can only be accessed from the same VPC of it.
$ ssh -i <ssh_pem_key> <EC2_user>@<EC2_IP_address> -f -N -L 6379:<Redis_endpoint>:6379
-
To run functions, just use python.
$ python handler.py
- Configure AWS credentials. Check out here to see how to do that.
- Deploy with serverless:
$ sls deploy