A Go library for mirroring files from a Git repository to an AWS S3 bucket. It uses Git HEAD and ignores changes in the working copy.
go get github.com/alltom/mirror2s3
package main
import (
"context"
"log"
"github.com/alltom/mirror2s3"
)
func main() {
m := mirror2s3.New(
mirror2s3.WithGitRepoRoot("/path/to/git/repo"),
mirror2s3.WithAwsProfile("my-profile"),
mirror2s3.WithAwsRegion("us-east-1"),
mirror2s3.WithBucketURL("s3://my-website-bucket"),
)
ctx := context.Background()
if err := m.Run(ctx); err != nil {
log.Fatal(err)
}
}
WithGitRepoRoot(path)
- Path to the Git repository to mirrorWithAwsProfile(name)
- AWS profile name for authenticationWithAwsRegion(region)
- AWS region where the S3 bucket is locatedWithBucketURL(url)
- S3 bucket URL (e.g., "s3://bucket-name" or "s3://bucket-name/prefix/")
The library uses standard AWS credential resolution:
- Environment variables (
AWS_PROFILE
,AWS_REGION
) - AWS credentials file (
~/.aws/credentials
) - IAM role (when running on EC2/ECS/Lambda)
By default, .gitignore
files are not uploaded. You can modify the IgnoredFiles
variable to customize this behavior:
mirror2s3.IgnoredFiles[".env"] = struct{}{} // Also ignore .env files
- Go 1.24 or later
- Git executable available in PATH (or at
/usr/bin/git
) - AWS credentials with S3 read/write permissions