Nov 17, 20264 min read

Migrate Fly.io Redis to Amazon ElastiCache

Move data from an Upstash Redis database created with fly redis to ElastiCache in your own AWS account, either by copying keys lazily through fly redis proxy or by exporting an RDB from the Upstash console.

Illustration for Migrate Fly.io Redis to Amazon ElastiCache

Fly Redis is an Upstash Redis database provisioned inside your Fly organization with fly redis create. Apps in that org reach it over a private IPv6 address. Once the app moves to AWS, those keys have to reach Amazon ElastiCache without emptying sessions or queues.

This guide moves the data to ElastiCache in your own AWS account. It starts with Encore, which provisions ElastiCache from Go and copies keys lazily, then covers an RDB export from the Upstash console.

Ways to move Fly Redis to ElastiCache at a glance

Encore lazy copyUpstash RDB exportStart empty
Write freezeNoYeswrites after the export are missedNo
Best forKeys with a TTLA full snapshot of the current datasetPure caches
Access neededA tunnel or a temporary path to the Upstash URLThe Upstash consoleNo
TargetElastiCache provisioned from GoElastiCache you provisionElastiCache you provision

Reaching Fly Redis from outside

The redis://...upstash.io URL that fly redis status prints is restricted to the Fly organization network. From a laptop, fly redis connect proxies local port 16379 and opens redis-cli, and fly redis proxy leaves a tunnel you can point a migration tool at. Upstash does not support the replication handshake, so redis-cli --rdb is the wrong export tool here.

Inventory the keyspace through the tunnel before choosing a strategy, and record the Redis version and whether eviction is enabled.

How do you migrate Fly Redis to ElastiCache with Encore?

Encore

Encore brings infrastructure from code: the Redis cluster and a typed keyspace are declared in the service that uses them, and deploying to AWS creates ElastiCache, as listed in the AWS infrastructure docs. During the copy window, a go-redis client can read the old database through a controlled path while live traffic fills ElastiCache.

A coding agent can add the keyspace and the fallback load path in the same change. Store any password as an Encore secret so it is not in the repository.

Set up the app

Get started
brew install encoredev/tap/encore &&
encore app create
Copy

Run in your terminal to get started locally.

// carts/carts.go package carts import ( "context" "time" "encore.dev/beta/errs" "encore.dev/storage/cache" "github.com/redis/go-redis/v9" ) var cluster = cache.NewCluster("carts", cache.ClusterConfig{ EvictionPolicy: cache.AllKeysLRU, }) type Cart struct { SKU string `json:"sku"` Qty int `json:"qty"` } var Carts = cache.NewStructKeyspace[string, Cart](cluster, cache.KeyspaceConfig{ KeyPattern: "cart/:key", DefaultExpiry: cache.ExpireIn(30 * 24 * time.Hour), }) // Password or full URL used with fly redis proxy during rehearsal. var secrets struct { FlyRedisURL string } func source(ctx context.Context) (*redis.Client, error) { opt, err := redis.ParseURL(secrets.FlyRedisURL) if err != nil { return nil, err } return redis.NewClient(opt), nil } func load(ctx context.Context, id string) (*Cart, error) { rdb, err := source(ctx) if err != nil { return nil, err } defer rdb.Close() var cart Cart if err := rdb.HGetAll(ctx, "cart:"+id).Scan(&cart); err != nil { return nil, err } if cart.SKU == "" { return nil, cache.Miss } ttl, err := rdb.PTTL(ctx, "cart:"+id).Result() if err != nil { return nil, err } if ttl <= 0 { ttl = 30 * 24 * time.Hour } if err := Carts.With(cache.ExpireIn(ttl)).SetIfNotExists(ctx, id, cart); err != nil && !errs.Is(err, cache.KeyExists) { return nil, err } _ = rdb.Del(ctx, "cart:"+id).Err() return &cart, nil }

On a miss in ElastiCache, load reads the old cart and its remaining lifetime from the Fly Redis URL, writes it into the new keyspace with that TTL, and deletes the old key. Point FlyRedisURL at redis://default:<password>@localhost:16379 while fly redis proxy is running for a rehearsal. After the longest TTL has passed, remove the secret field and the fallback, and destroy the Fly Redis database once you are sure nothing still reads it. Encore provisions an IAM role for the service.

Best fit: apps leaving Fly whose Redis data has a natural expiry, with no freeze on writes.

Export an RDB from the Upstash console

For a full snapshot, open the database in the Upstash console, go to Backups, choose Backup and Export, and download the .rdb file when it finishes. That file is the dataset at export time; writes after it are not included. Redis Functions are not included in the export. Stop writers first if you need a consistent cutover, then seed ElastiCache from the file in a private subnet.

Best fit: a complete copy of a keyspace that can tolerate a write freeze around the export.

How to choose

Pick Encore with a lazy copy when the data expires on its own and you want ElastiCache created from the service code. Pick an Upstash RDB export when you want a full snapshot and a short write freeze is fine. Let pure caches start empty either way.

Frequently asked questions

How do I export data from Fly.io Redis?

Fly Redis is an Upstash database in your Fly organization. redis-cli --rdb usually cannot use the replication handshake against Upstash, so export an RDB from the Upstash console under Backups, Backup and Export, or copy keys through fly redis proxy with SCAN, DUMP and RESTORE. For local inspection, fly redis connect opens a tunnel and a redis-cli session.

How do I migrate Fly.io Redis to ElastiCache with Encore?

Declare the cluster with cache.NewCluster and a typed keyspace, keep a go-redis client pointed at fly redis proxy or at the URL fly redis status shows, and on a cache miss copy the key and its PTTL into the Encore keyspace with SetIfNotExists. Encore provisions ElastiCache in your AWS account on deploy.

Can I reach Fly Redis from my laptop?

The redis:// URL is on the Fly organization's private IPv6 network and does not resolve from a laptop. Use fly redis proxy or fly redis connect to open a local tunnel, and keep that tunnel only for development or a migration pass, not as a production path from AWS.

Do I need to migrate a cache at all?

If the database is a pure cache that can be rebuilt, start ElastiCache empty. Migrate sessions, queues or other keys that would drop work in progress if they disappeared.

Deploy to your cloud on AWS and Google Cloud
without managing infrastructure

Encore lets developers and agents define application infrastructure directly in code, then automatically provisions it from local development to production in your AWS or GCP account.

~/orders — claude
Claude Code
Claude Code v2.1.180Opus 5.5~/orders