Buy me a coffeeBuy me a coffee
Backup MongoDB docker container to AWS S3 bucket

Backup MongoDB docker container to AWS S3 bucket

Hey, guys! While working on Moneta backend deployment with docker, I get stuck with consistency and DB backup problem. FYI this is our docker component structure:


The problem was to make DB backups automated straight to AWS S3 bucket. I found the solution in this amazing repo with docker container 🦄 But all unicorns disappeared when I got an error:

A client error (InvalidRequest) occurred when calling the PutObject operation: The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256.

Our S3 bucket located in Ohio region and works only with v4 authorization mechanism. So I made the fork of halvves repo and added v4 support, rebuilt docker image and tried again. Not so fast, gringo 😀

A client error (PermanentRedirect) occurred when calling the PutObject operation: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.

AWS CLI wants to have an explicit declaration for some regions (like my Ohio one), check more about it here AWS docs. In my case it was additional --region us-east-2 in AWS CLI command but I wanted to make this more convenient to use. So I added env variable BUCKET_REGION for this docker container (which is optional btw, if your bucket in a region like US East (N. Virginia) us-east-1) and with the command like this all finally work:

docker run -d \
  --env AWS_ACCESS_KEY_ID=myaccesskeyid \
  --env AWS_SECRET_ACCESS_KEY=mysecretaccesskey \
  --env BUCKET=mybucketname \
  --env BUCKET_REGION=mybucketregion \
  --env BACKUP_FOLDER=a/sub/folder/path/ \
  --env INIT_BACKUP=true \
  --link my_mongo_db:mongodb \


Feel free to use this updated version with AWS CLI v4 authorization mechanism and additional --region declaration. Source code you can find in my repo and ready to use docker container on docker hub deenoize/mongodb-backup-s3/


Ruslan Galba

About Ruslan Galba

Entrepreneur / CEO @hellotegra award winning digital agency / Founder @heytaboo chocolate and @heymoneta blockchain / Share stories @designhopeless