title: "Unable to execute HTTP request: Connect to <bucket-name>.s3.amazonaws.com:443 failed: connect timed out
body: <p>I am trying to write a Lambda function in java which connects to S3 and then fetch the data.</p>
  <p>When I run it locally, using main function it works fine and returns the result.
  Buit when I upload it to AWS lambda and the run it, I get this error message:</p>
  <blockquote>
  <p>&quot;errorMessage&quot;: &quot;Unable to execute HTTP request: Connect to bucket-name.s3.amazonaws.com:443 [bucket-name.s3.amazonaws.com/52.217.1.172] failed: connect timed out&quot;,
  &quot;errorType&quot;: &quot;com.amazonaws.SdkClientException&quot;,</p>
  </blockquote>
  <p>I have my S3 bucket as public.</p>
  <p>My pom.xml:</p>
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;com.amazonaws&lt;/groupId&gt;
      &lt;artifactId&gt;aws-java-sdk&lt;/artifactId&gt;
      &lt;version&gt;1.11.493&lt;/version&gt;
  &lt;/dependency&gt;
      &lt;dependency&gt;
      &lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;
      &lt;artifactId&gt;httpcore&lt;/artifactId&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;com.amazonaws&lt;/groupId&gt;
      &lt;artifactId&gt;aws-lambda-java-core&lt;/artifactId&gt;
      &lt;version&gt;1.1.0&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  <p>My request Handler:</p>
  <pre><code>public class LambdaRequestHandler implements RequestHandler&lt;String, String&gt; {
  @Autowired
  public ClaimSuffixNumberService csService;
      @Override
      public String handleRequest(String input, Context context) {
          if(csService == null) {
              csService = Application.getBean(ClaimSuffixNumberService.class);
          }
          String result= csService.readAndMakeCall(&quot;claimSuffix&quot;);
          return result;
      }
  }
  </code></pre>
  <p>My service</p>
  <pre><code>public String getObject(String fileName) {
      System.out.println(&quot;Inside Get Object&quot;);
      try {
          BasicAWSCredentials awsCreds = new BasicAWSCredentials(&quot;access-key&quot;,&quot;secret-key&quot;);
          AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
                                  .withRegion(Regions.US_EAST_1)
                                  .withCredentials(new AWSStaticCredentialsProvider(awsCreds))
                                  .build();
          System.out.println(s3Client);
          S3Object s3object = s3Client.getObject(new GetObjectRequest(bucket-name, object-name));
          InputStream is = s3object.getObjectContent();
          String content = StreamUtils.copyToString(is, 
   StandardCharsets.UTF_8);
          return content;
      } catch (IOException e) {
          e.printStackTrace();
      }
      return null;
  }
  
  public String readAndMakeCall(String fileName) {
      try {
          System.out.println(&quot;Reading for &quot; + fileName);
          String content = getObject(fileName);
          ObjectMapper mapper = new ObjectMapper();
          mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
          List&lt;ClaimSuffixNumber&gt; claimSuffixList = mapper.readValue(content, mapper.getTypeFactory().constructCollectionType(List.class, ClaimSuffixNumber.class));
          System.out.println(claimSuffixList.toString());
          for(ClaimSuffixNumber i: claimSuffixList) {
              System.out.println(i);
          }
          return claimSuffixList.toString();
      } catch (IOException e) {
          e.printStackTrace();
      }
      return &quot; &quot;;
  }
  </code></pre>