AWS Import/Export
Developer Guide (API Version 2010-06-03)
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Go to the Kindle Store to download this guide in Kindle format.Did this page help you?  Yes | No |  Tell us about it...

Sending a CreateJob Request Using the AWS SDK for Java

The AWS SDK for Java exposes an API to create an import job or an export job. You can then use the information in the response to send your storage device to AWS.

Create Job Process

1

Create an instance of the AmazonImportExportClient class by providing your AWS credentials.

2

Create an instance of the CreateJobRequest class by providing job information, such as the job type and the manifest.

3

Send the create job request by calling the AmazonImportExportClient.createRequest method.


The following Java code sample demonstrates creating an import job using the preceding steps.

AmazonImportExportClient client =
   new AmazonImportExportClient(
   new PropertiesCredentials(
       ImportCreateJobSample.class.getResourceAsStream("AWSCredentials.properties")));
String manifest = readManifestFile(manifestFilePath);
CreateJobRequest createRequest = new CreateJobRequest().withManifest(manifest).withJobType("Import");
CreateJobResult createResult = client.createJob(createRequest);

The following Java code sample demonstrates creating an export job using the preceding steps.

AmazonImportExportClient client =
   new AmazonImportExportClient(
   new PropertiesCredentials(
       ImportCreateJobSample.class.getResourceAsStream("AWSCredentials.properties")));
String manifest = readManifestFile(manifestFilePath);
CreateJobRequest createRequest = new CreateJobRequest().withManifest(manifest).withJobType("Export");
CreateJobResult createResult = client.createJob(createRequest);

To send a CreateJob request and print the response using Java

  1. Create a properties file, AWSCredentials.properties, and provide the Access Key ID and Secret Key value for your IAM user. For more information, see Using IAM with AWS Import/Export.

    Following is an example credentials file.

    accessKey:<Your Access Key ID>
    secretKey:<Your Secret Key>

    Note

    You cannot use the same AWSCredentials.properties file that you use with the AWS Import/Export Web Service tool. The fields are not the same.

    The AWSCredentials.properties file must be saved in the same directory as the produced .class file. Thus, if your class is in a package, or if your IDE puts your .class files in a different location, you will have to determine the appropriate directory to save your properties file. Also, the path to your manifest file must be explicit, including the full path to the file (such as C:\\Users\\UserName\\MyManifest.txt).

  2. Create a manifest file describing your job.

    For an example manifest, see Create Your First Amazon S3 Import Job or Create Your First Amazon S3 Import Job.

  3. Copy the following Java class to a file in your project.

    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.IOException;
    import com.amazonaws.auth.PropertiesCredentials;
    import com.amazonaws.services.importexport.AmazonImportExportClient;
    import com.amazonaws.services.importexport.model.CreateJobRequest;
    import com.amazonaws.services.importexport.model.CreateJobResult;
    
    public class ImportExportCreateJobSample {
    	private static String manifestFilePath = "[Provide-Explicit-Manifest-File-Path]";
     
        public static void main(String args[]) throws IOException { 	
              AmazonImportExportClient client =
                new AmazonImportExportClient(
                    new PropertiesCredentials(
                        ImportExportCreateJobSample.class.getResourceAsStream("AWSCredentials.properties")));
          
            String manifest = readManifestFile(manifestFilePath);
    
            CreateJobRequest createRequest = new CreateJobRequest().withManifest(manifest).withJobType("[Import|Export]");
    
            // Call service.
            CreateJobResult createResult = client.createJob(createRequest);
    
            // Process result.
            System.out.println();
            System.out.println();
            System.out.println("********************************");
            System.out.println("* RECEIVED SUCCESSFUL RESPONSE *");
            System.out.println("********************************");
            System.out.println("jobId: " + createResult.getJobId());
            System.out.println("signature: " + createResult.getSignature());
            System.out.println("jobType: " + createResult.getJobType());
            System.out.println();
            System.out.println("*******************************************************");
            System.out.println("* signatureFileContents - write this to a file called *");
            System.out.println("* SIGNATURE in the root of your disk                  *");
            System.out.println("*******************************************************");
            System.out.println(createResult.getSignatureFileContents());
            System.out.println();
            System.out.println("********************************************");
            System.out.println("* SEND YOUR STORAGE DEVICE TO THIS ADDRESS *");
            System.out.println("********************************************");
            System.out.println(createResult.getAwsShippingAddress());
        }
    
        public static String readManifestFile(String filename) throws IOException {
            StringBuilder manifest = new StringBuilder();
    
            BufferedReader input = new BufferedReader(new FileReader(filename));
            try {
                String line = null;
                while ((line = input.readLine()) != null) {
                    manifest.append(line);
                    manifest.append(System.getProperty("line.separator"));
                }
            } finally {
                input.close();
            }
            return manifest.toString();
        }
    }
  4. Update the code by providing your manifest file path and specifying Import or Export for the job type .

  5. Run the code.

    For an Amazon S3 import or export job, AWS Import/Export sends a response that includes a job ID, a signature value, and an AWS shipping address. The response also saves a SIGNATURE file to your computer.

    For an AWS EBS or Amazon Glacier import job, AWS Import/Export sends a response that includes a job ID and shipping instructions. It also places a PDF file in the Amazon S3 log bucket you identified in your manifest. The PDF file contains job information, shipping instructions, and a barcode.