title: How to create an s3 download link which will expire only after 6 days
body: <p>I want to generate an s3 link to download a file, the link should be live for at least 6 days. I have tried with options InstanceProfileCredentialsProvider(false)(Which worked only for 24 hours), ProfileCredentialsProvider(doesn't even create a link ), Access Key</p>
  
  <p>Access key of IAM user worked, but this user key will expire after some days so every time I have to change the same in the code and also I think it is not a good practice to expose the key in the code. </p>
  
  <p>Is there any other way I can generate an s3 download link which will expire only after 6 days.</p>
  
  <p>Below is the code snippet:- </p>
  
  <pre><code>AmazonS3 s3Client  = AmazonS3ClientBuilder.standard().withCredentials(new InstanceProfileCredentialsProvider(false))
                      .build();
  java.util.Date expiration = new java.util.Date();
  long milliSeconds = expiration.getTime();
  milliSeconds += 1000 * 60 * 60 * 24 * 7; // Add 7 days.
  expiration.setTime(milliSeconds);
  GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest("s3bucket",
                      "fileLocationpath");
  generatePresignedUrlRequest.setMethod(HttpMethod.GET);
  generatePresignedUrlRequest.setExpiration(expiration);
  link =  s3Client.generatePresignedUrl(generatePresignedUrlRequest);
  </code></pre>