S3 endpoint - could not connect to Endpoint URL

Hello good people.
Please can I have some assistance, I am trialing out a test flask app which takes a file input and uploads it to S3.
I am having great difficulty in setting the S3 endpoint URL.
Below is the connection parameters of my code:

NB: Something strange, I must note, the variable below “LOCALSTACK_HOSTNAME”, in the commented out line, This variable refuses to resolve. However I dnt think this is a problem, as when I type the full URL(http://localhost:4566) in my CLI, it does work…So theoretically the URL is correct if I type it without using variables.


ENDPOINT_URL_ = 'http://localhost.localstack.cloud:4566'
#ENDPOINT_URL_ = "http://localhost:4566"
#ENDPOINT_URL_ = f"http://{os.getenv("LOCALSTACK_HOSTNAME")}:{os.getenv("EDGE_PORT")}"
s3client = boto3.client("s3", region_name="us-east-1", endpoint_url = ENDPOINT_URL_,aws_access_key_id="test",
    aws_secret_access_key="test")


As you can see the commented out URL’s is the different variations I have tried, However none works. Please shed some light on what I am doing wrong.
To confirm, I do know it is the correct URL, as if I run the below code in my cli, I get a successful return of my buckets. This proves I guess I have my setup and the URL is indeed correct. To that fact, it refuses to work in my flask app.

awslocal s3 --endpoint-url http://localhost.localstack.cloud:4566 ls

Hello @clinton.bitcoin,

Would it possible to know more about your setup, and where/how is your Flask app deployed? Is it running in Docker?

The LOCALSTACK_HOSTNAME environment variable is only accessible inside Docker containers spawned by LocalStack itself, like lambda functions.

You can read more about LocalStack networking here: Network troubleshooting | Docs

Depending on where your app is running, you will access LocalStack differently.

1 Like