title: How to resolve javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
body: <p>I am trying to download a file from a url using Apache commons FileUtils on AWS Lambda.
  But i am get this exception.</p>
  <pre><code>javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
  at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:994)
  at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1367)
  at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1395)
  at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1379)
  at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
  at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
  at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1564)
  at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
  at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:263)
  at java.net.URL.openStream(URL.java:1045)
  at org.apache.commons.io.FileUtils.copyURLToFile(FileUtils.java:1478)
  </code></pre>
  <p>I have using java 8 in AWS Lambda.
  I have tried</p>
  <pre><code>System.setProperty(&quot;https.protocols&quot;, &quot;SSLv3,TLSv1,TLSv1.1,TLSv1.2&quot;);
  </code></pre>
  <pre><code>Security.setProperty(&quot;jdk.tls.disabledAlgorithms&quot;, &quot;&quot;);
  </code></pre>
  <pre><code>public static void addSslToTrustStore() throws NoSuchAlgorithmException, KeyManagementException {
          TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
              public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                  return null;
              }
  
              public void checkClientTrusted(X509Certificate[] certs, String authType) {
              }
  
              public void checkServerTrusted(X509Certificate[] certs, String authType) {
              }
          }
          };
  
          // Install the all-trusting trust manager
          SSLContext sc = SSLContext.getInstance(&quot;SSL&quot;);
          sc.init(null, trustAllCerts, new java.security.SecureRandom());
          HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
  
          // Create all-trusting host name verifier
          HostnameVerifier allHostsValid = new HostnameVerifier() {
              public boolean verify(String hostname, SSLSession session) {
                  return true;
              }
          };
  
          // Install the all-trusting host verifier
          HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
      }
  </code></pre>
  <p>These were all the options I found online, but didn't worked for me.
  File gets downloaded on my local with ou any exception but throws exception on lambda.
  Please help me.</p>