amazon glacier Vault Inventory Retrieve Job Initiator - Java AWS

Java examples for AWS:Glacier

Description

amazon glacier Vault Inventory Retrieve Job Initiator

Demo Code


import java.io.IOException;
import java.util.Date;

import com.amazonaws.ClientConfiguration;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.PropertiesCredentials;
import com.amazonaws.services.glacier.AmazonGlacierClient;
import com.amazonaws.services.glacier.model.InitiateJobRequest;
import com.amazonaws.services.glacier.model.InitiateJobResult;
import com.amazonaws.services.glacier.model.JobParameters;


public class VaultInventoryRetrieveJobInitiater {

    public static String vaultName = "GLACIER_TEST";

    public static void main(String[] args) throws IOException {
        ClientConfiguration clientConfiguration = new ClientConfiguration();
        clientConfiguration.setProxyHost("xx.xx.xx.xx");
        clientConfiguration.setProxyPort(0);

        AWSCredentials credentials = new PropertiesCredentials(
                VaultCreator.class
                        .getResourceAsStream("AwsCredentials.properties"));
        AmazonGlacierClient client = new AmazonGlacierClient(credentials,
                clientConfiguration);/*from   w w  w  .  j  a  v a2s.c om*/
        client.setEndpoint("https://glacier.ap-northeast-1.amazonaws.com/");
        try {
            InitiateJobRequest initiateJobRequest = new InitiateJobRequest()
                    .withVaultName(vaultName).withJobParameters(
                            new JobParameters()
                                    .withType("inventory-retrieval"));
            InitiateJobResult initiateJobResult = client
                    .initiateJob(initiateJobRequest);
            String jobId = initiateJobResult.getJobId();
            System.out.println("initiate inventory-retrieval job:jobId="
                    + jobId + ",startTime:" + new Date());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Related Tutorials