Redis "Could Not Connect to Redis at 127.0.0.1:6379: Connection Refused" and "Connection Timed Out": Every Fix on Amazon Linux 2023 (Valkey), Docker, Lambda and ElastiCache

Logeshwaran
—

Could not connect to Redis at 127.0.0.1:6379: Connection refused means nothing is listening on that address and port: the server isn't running, it's listening somewhere else, or you're inside a container where 127.0.0.1 is the container itself. Connection timed out is a different animal: something is at that address, but a firewall, security group or routing rule is dropping your packets, and that is the ElastiCache version of the error almost every time. The surprise for people on Amazon Linux 2023 is that the package is called valkey, not redis: dnf install redis gives you nothing useful, the client is valkey-cli, and the error text says "Could not connect to Valkey". This page walks both errors from the message to the fix, on Amazon Linux 2023, Docker, EC2, Lambda and ElastiCache, including the TLS flag that turns a working endpoint into "Connection reset by peer" when you leave it out.

Ethan, a developer, built the booking site for his friend Jake's phone repair shop. The site keeps sessions in a cache. On his laptop it has always been "127.0.0.1:6379". The week he moved the cache to ElastiCache, the site stopped logging anyone in, and the log said Connection timed out, over and over, for an hour, while the cache sat in the console showing a healthy green Available.

⚡ Quick Answer

• Connection refused, local: the server is down or on another port. Amazon Linux 2023: sudo dnf install valkey && sudo systemctl enable --now valkey, then valkey-cli ping. All causes.

• Connection refused, Docker: your app is using 127.0.0.1; use the service name (redis, cache) instead. Why.

• Connection timed out, ElastiCache: the cache's security group must allow port 6379 from the client's security group, and the client must be inside the VPC. Test with valkey-cli -h ENDPOINT -p 6379 --tls --askpass -t 5 ping from an EC2 instance in the same subnet. The checks in order.

• Connection reset by peer, or TLS errors: the cache has in-transit encryption (every Serverless cache does) and your client didn't use TLS. The flag per client.

Lambda: attach it to private subnets in the cache's VPC. Your laptop: it can't reach a VPC cache without a VPN or a tunnel, except a Serverless cache with a public endpoint.

🧭 NEW HERE? READ THESE FIRST

New to ElastiCache, or to the AWS network pieces around it? These five pages make the rest of this one easy:

📌 Bookmark this; the ElastiCache checklist is the part you will come back for.

Refused or timed out: read which one you have first

The two messages look alike in a log, and they point in opposite directions, so settle this before you touch anything:

MessageWhat the network is telling youWhere to look
Connection refusedYour packet arrived and the machine answered "nothing is listening here." Fast, usually under a second.The server: not running, wrong port, bound to another address, or you're in a container talking to itself.
Connection timed outYour packet left and nothing ever came back. Slow: 40 seconds by default for valkey-cli.The path: security group, network ACL, route table, subnet, VPN. On ElastiCache this is the one you'll see.
Connection reset by peerSomething answered and then hung up during the handshake.TLS: the server wants an encrypted connection and you sent plain text. Also a proxy or load balancer in the way.
NOAUTH Authentication requiredYou're connected. The server wants a password.Not a network problem at all; pass the password or the IAM token.
DENIED Running in protected modeYou're connected from another machine and the server has no password and protected mode on.Set a password or turn protected mode off, on the server.
Name or service not known / getaddrinfoThe hostname didn't resolve.A typo in the endpoint, or DNS: a cache endpoint only resolves inside AWS.

In practice, "refused" is almost always local and "timed out" is almost always cloud. If your laptop says refused, the next section is yours. If your EC2 instance, Lambda function or container says timed out against a .cache.amazonaws.com name, skip to the ElastiCache checks.

Jake: "The console says Available. How can the cache be fine and the site not reach it?"

Ethan: "Available means the cache is up. It says nothing about whether your server is allowed to talk to it. Timed out is the firewall's way of saying no without saying anything."

Connection refused on your own machine: the five causes, in order

Start with the server, because nine times out of ten there isn't one. The exact message from the client is Could not connect to Redis at 127.0.0.1:6379: Connection refused, or Could not connect to Valkey at 127.0.0.1:6379: Connection refused from the newer client. Then:

1. The server isn't running

On any Linux with systemd, ask it directly. The unit is valkey on Amazon Linux 2023 and Fedora, redis-server on Debian, Ubuntu and Kali, redis on older Amazon Linux and CentOS:

systemctl is-active valkey          # Amazon Linux 2023
systemctl is-active redis-server    # Debian, Ubuntu, Kali
sudo ss -ltnp | grep -E '6379|redis|valkey'

If is-active says inactive and ss shows nothing on 6379, that's your answer. Start it and make it survive a reboot in one command:

sudo systemctl enable --now valkey          # or redis-server
valkey-cli ping                              # PONG

On a Mac with Homebrew, brew services start redis (or valkey), and on a machine where you installed it by hand, redis-server or valkey-server in a terminal keeps it running only while that terminal is open.

2. Amazon Linux 2023: the package is valkey, not redis

This is the one that costs people an afternoon. On Amazon Linux 2023, the package that gives you a cache server is valkey, the open-source fork of Redis that AWS backs. It installs valkey-server, valkey-cli, valkey-benchmark and the rest, under /usr/bin, with its config at /etc/valkey/valkey.conf and its log at /var/log/valkey/valkey.log. There is no redis-cli on the box afterwards; type it and you get command not found. The second package, redis6, exists for people who need the old engine and ships its binaries with a 6 in the name: redis6-server, redis6-cli. Both can be installed side by side; neither one starts on its own.

sudo dnf install -y valkey
rpm -q valkey                      # valkey-9.0.6-1.amzn2023...
sudo systemctl enable --now valkey
valkey-cli ping                    # PONG
valkey-cli INFO server | grep -E '^(valkey_version|redis_version|tcp_port|config_file)'

That last command answers a question people ask a lot: the server reports both valkey_version:9.0.6 and redis_version:7.2.4, because Valkey keeps a Redis compatibility version for clients that check it. Your existing Redis client libraries work unchanged. The service name you use with systemctl is valkey, and the one for the old package is redis6.

3. It's listening on a different port or address

The default port is 6379, but a config file, a Docker -p mapping or a second instance can move it. Compare what the client is dialing with what the server is bound to:

sudo ss -ltnp | grep -E 'valkey|redis'
# LISTEN 0 511 127.0.0.1:6379 ... users:(("valkey-server",pid=...))
grep -nE '^(bind|port|protected-mode|requirepass|tls-port) ' /etc/valkey/valkey.conf

Two lines in that output matter. port 6379 is what to dial. bind 127.0.0.1 -::1, the default, means the server only answers on the loopback address, so a connection from any other machine, or from another container, is refused even though the server is up. That is correct for a server on the same box as the app and the cause of the next two sections when it isn't.

4. You're connecting from a different machine

If the client is on another host and the server has the default bind 127.0.0.1, the result is Connection refused at the server's address, instantly. Fix it on the server, in valkey.conf:

bind * -::*            # answer on every interface (or list the one private address)
protected-mode yes
requirepass Cache-pass-123
sudo systemctl restart valkey
valkey-cli -h 10.0.1.20 -a Cache-pass-123 ping     # from the other machine

Change bind without setting a password and you'll trade the refusal for a long message starting DENIED Running in protected mode because protected mode is enabled and no password is set for the default user. The server is doing you a favor: it refuses to serve strangers without a password. Of the four options it lists, set requirepass and leave protected mode on; turning protected mode off on a server that any machine can reach is how caches end up on the public internet.

Once a password is set, every client needs it, including the one on the same box: a plain valkey-cli ping now says NOAUTH Authentication required. Pass it with -a, which prints a warning about your shell history, or better with --askpass, or through the environment variable REDISCLI_AUTH (VALKEYCLI_AUTH also works), which keeps it out of ps and history. A wrong password gets WRONGPASS invalid username-password pair or user is disabled, which at least tells you the network is fine.

5. The server crashed on start

If systemctl start returns without error and is-active still says failed, read the log before you reinstall anything. A full disk, a dir that doesn't exist, a bad line in the config or a port already taken all show up there in one line:

sudo journalctl -u valkey -n 30 --no-pager
sudo tail -n 20 /var/log/valkey/valkey.log
sudo valkey-server /etc/valkey/valkey.conf --test-memory 1 2>&1 | head   # quick sanity run

A healthy start ends with Ready to accept connections tcp. If you see that line and still get refused, you're dialing the wrong address or port, and section 3 has the comparison.

Connection refused in Docker and Docker Compose: 127.0.0.1 is the wrong address

Inside a container, 127.0.0.1 means this container. Your app container has no Redis in it, so 127.0.0.1:6379 is refused, immediately, while the cache container sits healthy next to it. The address you want is the service name from docker-compose.yml, which Docker's internal DNS resolves to the cache container:

services:
  cache:
    image: valkey/valkey:9        # or redis:7
  web:
    build: .
    environment:
      REDIS_URL: redis://cache:6379   # the service name, not 127.0.0.1
    depends_on:
      - cache

From the app container, the two addresses behave like this (the official Valkey image, version 9.1.2, on a shared network):

valkey-cli -h 127.0.0.1 ping    # Could not connect to Valkey at 127.0.0.1:6379: Connection refused
valkey-cli -h cache ping        # PONG
valkey-cli -h cache -p 6380 ping  # Could not connect to Valkey at cache:6380: Connection refused

Three things about the official image that explain the other Docker questions. It starts with protected-mode no and bind * -::*, so other containers on the same Docker network connect without a password; that is fine behind Docker's network and dangerous the moment you publish the port to the world. It publishes nothing by itself: from the host, 127.0.0.1:6379 is refused until you add -p 6379:6379 (or ports: in Compose), and with 127.0.0.1:6379:6379 you keep it off your network card. And a bare docker run redis on the host, followed by redis-cli ping on the same host, is the classic "refused": the container is running, the port isn't mapped.

The ordering trap comes last. depends_on starts the cache container first, but Valkey takes a moment to load its data file before it listens; an app that connects on its first line can get one Connection refused and crash. Either retry the connection in the app with a short backoff, or add a health check to the cache service and make depends_on wait on condition: service_healthy.

Jake: "So on my laptop the address is 127.0.0.1, in Docker it's the word cache, and in AWS it's that long name?"

Ethan: "Three environments, three addresses. The mistake is always the same: carrying one of them into the next place."

ElastiCache "Connection timed out": the checks, in order

An ElastiCache cache has no public IP address. It lives inside your VPC, and the only things that can reach it are machines inside that VPC, or in a VPC connected to it by peering, a transit gateway, or a VPN. That one fact answers the three most common situations before any checklist: your laptop can't connect to it (no route exists), a Lambda function that isn't attached to the VPC can't connect to it, and an EC2 instance in a different VPC can't connect to it without peering. In all three, the symptom is a timeout, because packets go out and nothing comes back.

For a client that is inside the VPC and still times out, work down this list. Each check takes a minute, and the order is by how often it's the cause.

1. The cache's security group doesn't allow the client

A security group is a firewall around the cache. It has to contain an inbound rule for TCP port 6379 (11211 for Memcached) whose source is the client's security group, or the client's private IP range. The most common wrong state: the cache was created with the VPC's default security group, which allows traffic only from members of that same default group, and your EC2 instance, Lambda function or ECS task uses a different group. Look at the cache first, then the client:

# which security group is on the cache?
aws elasticache describe-cache-clusters --cache-cluster-id my-cache --show-cache-node-info \
  --query 'CacheClusters[0].SecurityGroups'
# Serverless:
aws elasticache describe-serverless-caches --serverless-cache-name my-cache \
  --query 'ServerlessCaches[0].SecurityGroupIds'

# what does that group allow in?
aws ec2 describe-security-groups --group-ids sg-0123456789abcdef0 \
  --query 'SecurityGroups[0].IpPermissions'

The fix is one rule: inbound, TCP, 6379, source = the client's security group ID. Referencing a group rather than an IP means every instance, task or function that wears that group gets in, and nothing else does:

aws ec2 authorize-security-group-ingress \
  --group-id sg-CACHE \
  --protocol tcp --port 6379 \
  --source-group sg-CLIENT

Security groups are stateful, so you need no outbound rule on the cache side, and the client's group needs only its default "allow all outbound". If a colleague tightened the client's outbound rules, add TCP 6379 to the cache's group there too. One reassurance from the ElastiCache guidance, in case you find 0.0.0.0/0 on the cache's group: that does not expose the cache to the internet, because it has no public address; it just means every machine in the VPC can reach it, which is still wider than you want.

2. The client isn't in the VPC, or isn't in a subnet with a route

Confirm where the client actually is. For an EC2 instance, the console shows its VPC and subnet; for a Lambda function, the VPC configuration on the function's settings page, which is empty by default, and empty means "not in any VPC", so the cache is unreachable from it no matter what you do to security groups. For an ECS task, the awsvpc network configuration on the service. Then compare with the cache's subnet group:

aws elasticache describe-cache-subnet-groups --cache-subnet-group-name my-subnet-group \
  --query 'CacheSubnetGroups[0].{Vpc:VpcId,Subnets:Subnets[].SubnetIdentifier}'
aws lambda get-function-configuration --function-name booking-api --query 'VpcConfig'

Same VPC: move on to check 3. Different VPCs: you need VPC peering (or a transit gateway) with routes in both directions and a security group rule that references the peer's IP range, since a group ID from another VPC can't be referenced across non-peered VPCs. Lambda not in a VPC: attach it to two private subnets in the cache's VPC and a security group, and expect two side effects that catch people the first time. Attaching a function to a VPC removes its internet access until a NAT gateway exists on those subnets; our Lambda-in-a-VPC guide covers that. And putting a function in a public subnet doesn't give it a public IP or internet either; private subnets are the right choice.

aws lambda update-function-configuration --function-name booking-api \
  --vpc-config SubnetIds=subnet-aaa,subnet-bbb,SecurityGroupIds=sg-CLIENT

3. The endpoint is the wrong one for the cache type

ElastiCache has four kinds of addresses, and clients that use the wrong one either time out or fail in stranger ways. Copy the right one from the console or the CLI rather than typing it:

Cache typeEndpoint to useWhere it is
Serverless (Valkey, Redis OSS or Memcached)The single cache endpointdescribe-serverless-caches, field Endpoint.Address, port 6379
Cluster mode disabled, with replicasPrimary endpoint for writes, reader endpoint for readsThe cluster's detail page; primary follows failovers, node endpoints don't
Cluster mode disabled, one nodeThe node endpointThere is no primary endpoint on a single node
Cluster mode enabledThe configuration endpoint, with a cluster-aware client (-c in valkey-cli)Starts with clustercfg.; a plain client gets MOVED errors instead of data
aws elasticache describe-serverless-caches --serverless-cache-name my-cache \
  --query 'ServerlessCaches[0].Endpoint'
aws elasticache describe-replication-groups --replication-group-id my-cache \
  --query 'ReplicationGroups[0].NodeGroups[0].{Primary:PrimaryEndpoint,Reader:ReaderEndpoint}'

Two endpoint mistakes produce a timeout rather than an error: a node endpoint copied from a node that has since been replaced, and a hostname from a cache in another Region. A hostname that doesn't resolve at all (Name or service not known) usually means you're trying it from outside AWS; the .cache.amazonaws.com names resolve to private addresses and only inside the VPC's DNS.

4. In-transit encryption is on and the client is talking plain text

Every ElastiCache Serverless cache has in-transit encryption enabled, with no way to turn it off, and node-based caches have it when the box was checked at creation. A client without TLS against a TLS-only cache does not get a clean error: it typically gets Connection reset by peer, or a hang that your library reports as a timeout. The full fix per client is in the TLS section; the quick test from an EC2 instance in the VPC is:

sudo dnf install -y valkey
valkey-cli -h my-cache-abc123.serverless.use1.cache.amazonaws.com -p 6379 --tls --askpass -t 5 ping

That -t 5 is worth keeping in every test: it caps the connection attempt at five seconds, so a real timeout reads Connection timed out in six seconds instead of forty.

5. A network ACL or a route table in the way

Security groups allow by default and are stateful; network ACLs sit on the subnet, are stateless, and are the usual cause when the security groups look right and it still times out. A custom ACL needs inbound TCP 6379 on the cache's subnets from the client's range, and because replies go back on an ephemeral port, inbound TCP 1024 to 65535 on the client's subnet from the cache's range, with outbound rules to match. The VPC's default ACL allows everything; if someone created a locked-down one, this is where the packets die. Route tables matter only across VPCs: with peering, both route tables need a route to the other VPC's CIDR through the peering connection.

aws ec2 describe-network-acls --filters Name=association.subnet-id,Values=subnet-aaa \
  --query 'NetworkAcls[0].Entries[?Egress==`false`]'

6. The worked example: the Lambda function that timed out for an hour

Ethan's booking API ran as a Lambda function that was never attached to a VPC, because it only ever talked to DynamoDB and the internet. He created a Serverless Valkey cache in the VPC's default security group, pasted the endpoint into the function's environment, and every request timed out. In order, the checks above gave: security group on the cache = the default group; function's VPC config = none. Two changes fixed it: a security group for clients (sg-booking-api), a rule on the cache's group allowing TCP 6379 from it, and the function attached to the two private subnets with that group. The first invocation after the change took a few seconds longer while Lambda built its network interfaces, then the sessions came back. The third change came the next morning: the function's call to a payments API now timed out, because a VPC-attached function has no internet until a NAT gateway exists. That's the price of the fix, and the Lambda-in-a-VPC guide linked above is the page for it.

Jake: "An hour of 'timed out' and the whole fix was two rules?"

Ethan: "Two rules and a subnet. The hour went on reading the console's green Available and assuming it meant reachable."

TLS: the flag each client needs, and what happens without it

Three different failures, all from one cause, the client sending plain text to a server that only speaks TLS:

What you didWhat you get
Plain client, TLS-only serverError: Connection reset by peer
--tls, but a certificate the client doesn't trust (self-signed, or a missing CA bundle)SSL_connect failed: certificate verify failed
--tls with a trusted certificate, no passwordNOAUTH Authentication required., which means TLS is now fine
--tls --askpass, correct passwordPONG

For ElastiCache the certificate is signed by a public authority that Amazon Linux already trusts, so --tls is enough; --cacert is for your own Valkey server with your own certificate, or you can add that CA to the system trust store (/etc/pki/ca-trust/source/anchors/ then update-ca-trust on Amazon Linux) and drop the flag. From April 28, 2026, ElastiCache requires TLS 1.2 or newer on supported engine versions, and public endpoints require TLS 1.3, which current clients handle on their own. The flag per client library:

ClientTLS onNote
valkey-cli / redis6-cli (Amazon Linux 2023)--tls --askpassAdd -c for a configuration endpoint
redis-py (Python)redis.Redis(host=..., port=6379, ssl=True, password=...) or the URL scheme rediss://Two s's in the scheme
node-redis / ioredis (Node.js)rediss:// URL, or { socket: { tls: true } } / { tls: {} }Cluster mode: use the cluster client with the configuration endpoint
Lettuce / Jedis (Java)rediss:// URI, or .ssl(true) on the builder
PHPRedisPrefix the host with tls://
A client with no TLS supportRun stunnel on the client host: it listens on 127.0.0.1:6379 and forwards over TLS to the endpointThe app then connects to 127.0.0.1 as before

IAM authentication, which Serverless public endpoints require and node caches can use, replaces the password with a short-lived signed token: the GLIDE client generates and refreshes it for you, the Developer Toolkit for ElastiCache generates it for other libraries, and the user name is an IAM-enabled ElastiCache user such as the system-managed default.iam-user. A token lives for 15 minutes, so a long-running app needs a client that refreshes.

Connecting from your laptop: what works and what doesn't

A VPC cache is unreachable from your laptop, by design, and the timeout you get is not a bug. Your options, from quick to proper:

  • Test from inside. Open a Session Manager or SSH session to an EC2 instance in the same VPC, install valkey, and run the -t 5 test above. This is the fastest way to prove whether the cache or your path is the problem.
  • Tunnel through an instance. ssh -L 6379:ENDPOINT:6379 ec2-user@bastion makes 127.0.0.1:6379 on your laptop reach the cache through the bastion; your app and valkey-cli then connect to localhost, with --tls still required if the cache has it. The bastion's security group must be allowed into the cache's.
  • A VPN. AWS Client VPN or a Site-to-Site VPN puts your laptop on the VPC's network, which is the right answer for a team that does this daily.
  • A Serverless cache with a public endpoint. New since Valkey 9.0 on Serverless: create the cache with connection type Public, and it's reachable over the internet, with IAM authentication and TLS 1.3 required on every connection, so there is no password-only access to turn it into a leak. For a development cache that your laptop and your Lambda both need, this removes the tunnel.
aws elasticache create-serverless-cache \
  --serverless-cache-name dev-public-cache \
  --engine valkey --major-engine-version 9 \
  --connection-type public \
  --user-group-id default.iam-user-group

What doesn't work: assigning the cache a public IP (there's no such setting), pointing a load balancer at it, or opening its security group to 0.0.0.0/0 (which, again, changes nothing from outside the VPC). The old port-forwarding trick, an EC2 instance in a public subnet forwarding 6379 to the cache with iptables, still works and is still the thing to remove before anyone forgets it exists.

Timeouts that aren't network problems: client settings worth setting

Once the connection works, a second kind of "timed out" appears under load: the client gave up waiting for a reply. ElastiCache's own guidance is to set two separate timeouts in every client, a short connect timeout so a dead path fails fast, and a longer command timeout that covers slow operations like MULTI/EXEC, Lua scripts and big values. In redis-py that is:

import redis
client = redis.Redis(
    host="my-cache-abc123.serverless.use1.cache.amazonaws.com", port=6379,
    ssl=True, password=None,                 # IAM token or password as your cache requires
    socket_connect_timeout=0.1,              # fail fast if the path is dead
    socket_timeout=2,                        # give every command up to 2 s
)
client.set("session:42", "ok")
client.blpop("queue", timeout=1)             # blocking ops: shorter than socket_timeout

Blocking commands such as BLPOP need their own timeout set lower than the socket timeout, or the socket timeout fires first and looks like a failure. On Lambda, keep the client outside the handler so the connection is reused across invocations, and set a connect timeout well under the function's timeout, so a bad security group produces a readable error in a second rather than a 30-second function timeout with no message.

Kali Linux and other Debian-based systems

The package names flip back on Debian and its descendants, which includes Kali: the package is redis-server (Valkey is in the Debian archive too as valkey), the service is redis-server, the config is /etc/redis/redis.conf, and the client is redis-cli. Everything else on this page applies: bind 127.0.0.1 ::1 by default, protected mode on, port 6379.

sudo apt update && sudo apt install -y redis-server
sudo systemctl enable --now redis-server
redis-cli ping
redis-cli -h ENDPOINT -p 6379 --tls --askpass -t 5 ping    # Debian's redis-cli is built with TLS

If you're on Kali for security work and want to test whether a cache is exposed, the same -t 5 probe against a public IP is the honest check: refused means closed, timed out means filtered, PONG without a password means someone has a problem.

The messages, decoded

MessageCauseFix
Could not connect to Redis/Valkey at 127.0.0.1:6379: Connection refusedNo server on that address and portStart the service; in Docker use the service name; check port and bind
Could not connect ... : Connection timed outPackets dropped: security group, ACL, route, or the client isn't in the VPCThe ElastiCache checklist, in order
Error: Connection reset by peerTLS-only server, plain client--tls / rediss://
SSL_connect failed: certificate verify failedUntrusted certificate--cacert, or add the CA to the trust store
NOAUTH Authentication requiredPassword set, none given--askpass, REDISCLI_AUTH, or the IAM token
WRONGPASS invalid username-password pairWrong password or wrong userCheck the ElastiCache user and its access string
DENIED Running in protected modeRemote client, no password, protected mode onSet requirepass (keep protected mode on)
MOVED 12182 10.0.1.5:6379Cluster mode enabled, plain clientCluster-aware client, or -c, with the configuration endpoint
Name or service not knownEndpoint doesn't resolveTypo, wrong Region, or you're outside the VPC
redis-cli: command not found (Amazon Linux 2023)The package is valkeydnf install valkey, use valkey-cli

Frequently asked questions about Redis and Valkey connection errors

What does "Could not connect to Redis at 127.0.0.1:6379: Connection refused" mean?

Nothing is listening on that address and port: the server isn't running, it's on another port or address, or you're inside a container where 127.0.0.1 is the container itself.

How do I start Redis on Amazon Linux 2023?

The package is valkey: sudo dnf install valkey, then sudo systemctl enable --now valkey, then valkey-cli ping. For the old engine, the package is redis6 with redis6-cli.

Why is there no redis-cli on Amazon Linux 2023?

Amazon Linux 2023 ships Valkey instead of Redis. The client is valkey-cli, and the redis6 package provides redis6-cli if you need the Redis 6 engine.

Why does Redis refuse connections in Docker Compose?

Your app is dialing 127.0.0.1, which is its own container. Use the cache service's name from docker-compose.yml as the host, and add a port mapping if the host itself needs access.

Why does ElastiCache say Connection timed out?

The client can't reach the cache: usually the cache's security group lacks an inbound rule for port 6379 from the client, or the client is outside the VPC, such as a Lambda function with no VPC configuration.

Can ElastiCache be made public?

Node-based caches, no: they have no public address. ElastiCache Serverless for Valkey 9.0 and later can be created with a public endpoint, which requires IAM authentication and TLS 1.3 on every connection.

How do I connect to ElastiCache from my laptop?

Through an SSH tunnel via an EC2 instance in the VPC, through a Client VPN, or by using a Serverless cache with a public endpoint. A direct connection to a VPC cache times out by design.

Which ElastiCache endpoint should I use in cluster mode?

The configuration endpoint, which starts with clustercfg, with a cluster-aware client. In valkey-cli add -c so it follows MOVED and ASK redirections.

Why does the connection work from one EC2 instance and not another?

The working instance's security group is allowed into the cache's group and the other one's isn't, or the two instances are in different VPCs or subnets with different network ACLs.

What port and TLS settings does ElastiCache use?

Port 6379 for Valkey and Redis OSS, 11211 for Memcached. Every Serverless cache requires TLS; node-based caches require it if in-transit encryption was enabled at creation. Use --tls in valkey-cli or a rediss:// URL.

Why do I get Connection reset by peer from ElastiCache?

The cache has in-transit encryption and the client connected without TLS. Add --tls, ssl=True, or the rediss:// scheme.

How do I test an ElastiCache connection with redis-cli?

From an EC2 instance in the same VPC: valkey-cli -h ENDPOINT -p 6379 --tls --askpass -t 5 ping. A PONG proves the path; a timeout in six seconds points at the security group.

Does a Lambda function need to be in a VPC to use ElastiCache?

Yes, for a cache with a VPC endpoint: attach the function to private subnets in the cache's VPC with a security group the cache allows. Expect to add a NAT gateway if the function also needs the internet.

What does DENIED Running in protected mode mean?

A remote client reached a server that has no password and protected mode on. Set requirepass in the config and restart; turning protected mode off on a reachable server is how caches get exposed.

How long does valkey-cli wait before Connection timed out?

About 40 seconds by default. Pass -t 5 to cap the connection attempt at five seconds while you troubleshoot.

Is Valkey compatible with my Redis client library?

Yes. Valkey reports a Redis compatibility version (redis_version 7.2.4 alongside valkey_version 9.x) and speaks the same protocol, so existing clients connect unchanged.

For readers preparing for an AWS certification

We have been covering AWS certifications alongside our fixes, so here is a short extra for readers studying for one. If you only came for the fix, you already have it; feel free to skip this part.

Exams that test this topic: Solutions Architect – Associate (SAA-C03) • Developer – Associate (DVA-C03 from December 1, 2026) • CloudOps Engineer – Associate (SOA-C03).

Here are the exam-style questions this topic tends to raise, with the reasoning you need to answer them:

1. A Lambda function cannot reach an ElastiCache cluster. What do you check first?

That the function runs in the same VPC and the cache's security group allows port 6379 from the function's security group.

2. In-transit encryption is on for the cache. What must clients do?

Connect with TLS.

3. Several web servers must share user sessions. What is a common choice?

Amazon ElastiCache (Valkey or Redis OSS) as the session store.

4. The cache must survive the loss of a node or an Availability Zone. What do you configure?

Replicas with Multi-AZ and automatic failover.

5. Data should be cached only after it is first requested. Which strategy is that?

Lazy loading (cache-aside). Write-through updates the cache on every write instead.

6. You want a cache without sizing nodes. What do you use?

ElastiCache Serverless.

Exam codes and dates change often. Our AWS certification changes page keeps track of what is current.

Ethan's two rules and a subnet took ten minutes once he stopped reading the word Available as a promise. Jake's booking site logs people in again, the sessions live in a cache nobody outside the VPC can see, and the payments call works because a NAT gateway followed the function into the subnet the next day. Jake's verdict: "So refused means nobody's home, and timed out means someone's home and won't open the door." Ethan said that was the whole page in one sentence.

📌 If you keep one line from this page

Refused means nothing is listening (start the service, or use the Docker service name); timed out means the path is blocked (the cache's security group must allow 6379 from the client's group, and the client must be inside the VPC); reset by peer means add --tls.

Amazon Linux 2023: dnf install valkey, valkey-cli · test: valkey-cli -h ENDPOINT --tls --askpass -t 5 ping · Lambda: private subnets + security group.

Revision note. Written October 15, 2026, with Valkey 9 on Amazon Linux 2023, the official Valkey 9 container image, and ElastiCache Serverless public endpoints in place. "A closed door is still a door," says a Tamil proverb; find who holds the key before you break it down.

Related