User guide

Create your Application
We'll now build the application that will run on the Amazon EC2 instance. First, create a directory that
you can use to hold your tutorial files. Call it something like GetS3ObjectApp.
Next, copy the SDK for Java libraries into your newly-created tutorial directory. If you downloaded the
SDK for Java to your ~/Downloads directory, you can copy them with the following commands:
cp -r ~/Downloads/aws-java-sdk-1.7.5/lib .
cp -r ~/Downloads/aws-java-sdk-1.7.5/third-party .
Here is the program that we'll be transferring to your EC2 instance. Open a new file, call it
GetS3Ojbect.java, and type (or paste) the following code:
import java.io.*;
import com.amazonaws.auth.*;
import com.amazonaws.services.s3.*;
import com.amazonaws.services.s3.model.*;
import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonServiceException;
public class GetS3Object {
private static String bucketName = "text-content";
private static String key = "text-object.txt";
public static void main(String[] args) throws IOException
{
AmazonS3 s3Client = new AmazonS3Client();
try
Version v1.0.0
33
AWS SDK for Java Developer Guide
Using IAM Roles for EC2 Instances