| Did this page help you? Yes No Tell us about it... |
The AWS SDK for Java exposes an API to create an import 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 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);To create an import 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:AKIAIOSFODNN7EXAMPLE secretKey:wJalrXUtnFEMI/K7MDENG/bPxRfiCYzEXAMPLEKEY
Note, if your program can't find the properties file, be aware that the 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.
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 ImportCreateJobSample {
private static String manifestFilePath = "***Provide-Explicit-Manifest-File-Path***";
public static void main(String args[]) throws IOException {
AmazonImportExportClient client =
new AmazonImportExportClient(
new PropertiesCredentials(
ImportCreateJobSample.class.getResourceAsStream("AWSCredentials.properties")));
String manifest = readManifestFile(manifestFilePath);
CreateJobRequest createRequest = new CreateJobRequest().withManifest(manifest).withJobType("Import");
// 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.
Run the code.
The response includes all the information you need to ship your storage device to AWS.