User guide
run:
[java] Downloading an object
[java] AmazonServiceException
BUILD SUCCESSFUL
Transfer the Compiled Program to Your EC2 Instance
Transfer the program to your EC2 instance using secure copy (scp), along with the SDK for Java libraries.
The sequence of commands looks something like the following. Depending on the Linux distribution that
you used, the user name might be "ec2-user", "root", or "ubuntu". To get the public DNS name of your
instance, select it in the Amazon EC2 console, and then look for Public DNS in the Description tab (for
example, ec2-198-51-100-1.compute-1.amazonaws.com).
scp -p -i my-key-pair.pem GetS3Object.class ec2-user@public_dns:GetS3Object.class
scp -p -i my-key-pair.pem build.xml ec2-user@public_dns:build.xml
scp -r -p -i my-key-pair.pem lib ec2-user@public_dns:lib
scp -r -p -i my-key-pair.pem third-party ec2-user@public_dns:third-party
In the preceding commands, GetS3Object.class is your compiled program, build.xml is the ant file
used to build and run your program, and the lib and third-party directories are the corresponding
library folders from the SDK for Java.
The -r switch indicates that scp should do a recursive copy of all of the contents of the library and
third-party directories from the SDK for Java.
The -p switch indicates that scp should preserve the permissions of the source files when it copies them
to the destination. If you are copying the files from Windows, you might need to fix the permissions on
your instance using the following command:
chmod -R u+rwx GetS3Object.class build.xml lib third-party
Run the Sample Program on the EC2 Instance
To run the program, connect to your EC2 instance. For more information, see Connect to Your Linux
Instance in the Amazon EC2 User Guide for Linux Instances.
If ant is not installed on your instance, you can install it using the yum installer as follows:
sudo yum install ant
Run the program using ant as follows:
ant getS3Object
The program should write the contents of your Amazon S3 object to your command window.
Version v1.0.0
34
AWS SDK for Java Developer Guide
Using IAM Roles for EC2 Instances