# Could not connect to the endpoint URL

AWS error fixes · Updated 17 November 2026

**Short answer:** The AWS CLI or SDK built a service URL but couldn't open a TCP or TLS connection to it, so the request never reached AWS. The usual causes are a misspelt or wrong Region (which produces a hostname that doesn't exist), a service that isn't offered in that Region, or a machine with no route out: a private subnet without a NAT gateway or VPC endpoint, a firewall or proxy, or a local emulator that isn't running.

## What the error tells you

```
Could not connect to the endpoint URL: "https://ec2.eu-west-2a.amazonaws.com/"
```

This is a client-side connection failure (botocore's `EndpointConnectionError`), not an AWS error code. No credentials were checked and nothing was logged in CloudTrail. Read the hostname in the message first: it shows exactly which Region and service the client was aiming at, and most of the time that alone gives the answer.

## Most common causes

| What you see in the URL | Cause |
|---|---|
| An Availability Zone such as `eu-west-2a`, a typo, or a display name | The Region is set to something that isn't a Region code. Use `eu-west-2`, not `eu-west-2a` or `London`. |
| A real Region and a service that isn't there | Not every service runs in every Region. Check the service's endpoints page. |
| A correct hostname | Network: no internet route, blocked port 443, a proxy that needs `HTTPS_PROXY`, or DNS that can't resolve AWS names. |
| `http://localhost:4566` or another custom host | An `--endpoint-url` or `AWS_ENDPOINT_URL` setting points at an emulator or proxy that isn't listening. |

## How to fix it

1. **Check the Region the CLI resolved.**

   ```
   aws configure list
   aws configure get region --profile prod
   env | grep -E 'AWS_(DEFAULT_)?REGION|AWS_ENDPOINT_URL'
   ```

   Environment variables beat the config file, so a stale `AWS_REGION` in your shell or CI job overrides the profile.

2. **Test the network path directly.**

   ```
   nslookup sts.eu-west-2.amazonaws.com
   curl -sv https://sts.eu-west-2.amazonaws.com/ -o /dev/null 2>&1 | grep -E 'Connected|SSL|timed out'
   ```

   If DNS fails or the connection times out, the problem is the network, not AWS.

3. **On EC2, ECS or Lambda in a VPC**, a private subnet needs a route to a NAT gateway, or an interface VPC endpoint for that service (with private DNS enabled) or a gateway endpoint for S3 and DynamoDB. Check the subnet's route table and the endpoint's security group, which must allow inbound 443 from your workload.

4. **Behind a corporate proxy**, set `HTTPS_PROXY` and, for internal hosts, `NO_PROXY`. Add `--debug` to see which proxy and URL the CLI is using.

5. **With LocalStack or another emulator**, confirm the container is running and the port is published; inside Docker Compose, use the service name instead of `localhost`.

## Gotchas

- **ECR in a private subnet** needs both the `ecr.api` and `ecr.dkr` interface endpoints plus the S3 gateway endpoint, because image layers come from S3. Missing one gives this error from `api.ecr.<region>.amazonaws.com` or a pull timeout.
- **Global services** such as IAM sign requests to a fixed endpoint; a Region typo there may not show up until you call a Regional service.
- **Timeouts that look like this**: `Connect timeout on endpoint URL` is the same family of problem (no route), while [Read timeout on endpoint URL](https://cloudconsole.dev/errors/read-timeout-on-endpoint-url) means the connection worked but the response was too slow.

## Questions

### Why does the AWS CLI say it could not connect to the endpoint URL?

The client couldn't open a connection to the hostname it built from the service and Region. Check the Region spelling first, then DNS and network access to port 443.

### How do I fix could not connect to the endpoint URL localhost 4566?

Port 4566 is LocalStack's default. Start the LocalStack container, make sure the port is published, and from another container use the Compose service name rather than localhost.

### Does a VPC endpoint fix this error in a private subnet?

Yes, if the subnet has no NAT route. Create an interface endpoint for the service with private DNS enabled, or a gateway endpoint for S3 or DynamoDB, and allow 443 in the endpoint's security group.

## When this happens away from your desk

This error usually turns up in a failing deploy job or a container that can't reach AWS. CloudConsole, a phone app for AWS, is being built to show alarms, logs and resources on your phone, which helps you see which workload is affected while you're away from a terminal.

[About the CloudConsole app](https://cloudconsole.dev/aws-console-app) · [Download on the App Store](https://apps.apple.com/app/cloudconsole-for-aws/id6835419710)

## Sources

- [AWS service endpoints](https://docs.aws.amazon.com/general/latest/gr/rande.html)
- [Access an AWS service using an interface VPC endpoint](https://docs.aws.amazon.com/vpc/latest/privatelink/create-interface-endpoint.html)

## Related

- [NoRegionError: You must specify a region](https://cloudconsole.dev/errors/noregionerror-you-must-specify-a-region)
- [Read timeout on endpoint URL](https://cloudconsole.dev/errors/read-timeout-on-endpoint-url)
- [SSL validation failed for https://... certificate verify failed](https://cloudconsole.dev/errors/ssl-validation-failed)
- [How to change the AWS default Region](https://cloudconsole.dev/how-to/change-default-aws-region)
- [Unable to locate credentials](https://cloudconsole.dev/errors/unable-to-locate-credentials)
- [AccessDeniedException: User is not authorized to perform this action because no identity-based policy allows it](https://cloudconsole.dev/errors/accessdenied-no-identity-based-policy-allows)

---

Source: https://cloudconsole.dev/errors/could-not-connect-to-endpoint-url

CloudConsole is an independent iPhone and Android app for Amazon Web Services by Cloudconcur Ltd. It is not affiliated with Amazon Web Services.
