AWS S3 CLI - Connection was closed before we received a valid response from endpoint

Viewed 18053
$ aws s3 ls s3://

Connection was closed before we received a valid response from endpoint URL: 
"https://s3.amazonaws.com/".

What could be the problem?

4 Answers

At first I had the same problem but there are about 2 things that helped solve the error. First, I was using Kaspersky cloud protection and when I turned it off, after a few hours the program worked just swiftly.

The second solution was to use an IP addresses and this really worked out as I kept on trying it with VPN on and OFF several times, Whenever I could connect the VPN, this worked and whenever I disconnected it, it failed and brought the same error to me.

Conclusion: This seems to be a problem due to the network connection and IP address blocking. At the time this error occured, I could not access any social media platform because in my country we have to pay to use the social media platforms. This appeared to me as a partial indicator for the problem above.

Hope this will help. Thanks

In my case mentioning region in aws configure solved the issue.
Earlier I had only set Access key ID and Secret access key and left the region part blank. And while upload files to S3 using aws s3 cp, some files were failing with(and not every file), so I was sure it's not related to the firewall:

upload failed: ./xyz to s3://bucket_name/path/to/object/directory/xyz Connection was closed before we received a valid response from endpoint URL: "https://bucket_name.s3.amazonaws.com/path/to/object/directory/xyz".

In my case I had a bad connexion, so I fixed it by adding the --cli-connect-timeout flag (int) at the end of the command, eg: --cli-connect-timeout 6000

The maximum socket connect time in seconds. If the value is set to 0, the socket connect will be blocking and not timeout. The default value is 60 seconds.

Based on this response in the official AWS CLI repo the problem could be in the bundle size. Lambda quotas. If it exceeds 50Mb the endpoint just doesn't allow the connection and you see just hung request. The workarounds suggested by AWS:

  1. Upload the deployment package to your function from an Amazon Simple Storage Service (Amazon S3) bucket.
  2. If your deployment package contains native libraries, you can build the deployment package with AWS Serverless Application Model (AWS SAM). You can use the AWS SAM CLI sam build command with the --use-container to create your deployment package. This option builds a deployment package inside a Docker image that is compatible with the Lambda execution environment.
Related