| « PreviousNext » | |
![]() ![]() ![]() | Did this page help you? Yes | No | Tell us about it... |
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
|
2 | Create an instance of the |
3 | Send the create job request by calling the
|
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
Create a properties file, AWSCredentials.properties, and
provide your Access Key ID and Secret Key value.
Following is an example credentials file.
accessKey: secretKey:wJalrXUtnFEMI/K7MDENG/bPxRfiCYzEXAMPLEKEY
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).
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.
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();
}
}Update the code by providing your manifest file path and specifying Import or Export for the job type .
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.