title: Accessing S3 Objects with storage class Glacier
body: <p>I wrote a piece of (java) software that downloads objects (archives) from an S3 bucket, extracts the data locally and does operations on it.
  A few days back, I set the lifecycle policy of all the objects in the "folder" within S3 to be moved to glacier automatically 2 days after creation, so that I have the time to DL and extract the data before it's archived. However, when accessing the data programmatically, Amazon Web Services throws an error </p>
  
  <pre><code>Exception in thread "main" com.amazonaws.services.s3.model.AmazonS3Exception: The operation is not valid for the object's storage class
  </code></pre>
  
  <p>I suppose this is due to the fact that the objects' storage classes have been updated to Glacier. 
  So far I have used the following code to access my S3 data:</p>
  
  <pre><code>public static void downloadObjectFromBucket(String bucketName, String pathToObject, String objectName) throws IOException{
      AmazonS3 s3Client = new AmazonS3Client(new ProfileCredentialsProvider());        
      S3Object object = s3Client.getObject(new GetObjectRequest(bucketName, pathToObject));
      InputStream reader = new BufferedInputStream(object.getObjectContent());
      File file = new File(objectName);      
      OutputStream writer = new BufferedOutputStream(new FileOutputStream(file));
      int read = -1;
          while ( ( read = reader.read() ) != -1 ) {
              writer.write(read);
          }
      writer.flush();
      writer.close();
      reader.close();
  }
  </code></pre>
  
  <p>Do I have to update my code or change some settings in the AWS Console? It is unclear to me, since the objects are still in S3 and accessing every S3 object has been working wonderfully up until a few days ago where I adapted the lifecycle policies....</p>