User guide
Build and run the modified program. Since no credentials are stored in the program, unless you have
your AWS credentials specified in your environment, it's likely that you'll get an AmazonServiceException.
For example:
$ ant
Buildfile: /path/to/my/GetS3ObjectApp/build.xml
build:
[javac] Compiling 1 source file to /path/to/my/GetS3ObjectApp
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).You will also need to copy the SDK
for Java libraries.The sequence of commands will look something like the following:
scp -p -i key-pair-eclipse-1.pem GetS3Object.class \
ec2-user@ec2-ex-am-pl-e01.compute-1.amazonaws.com:GetS3Object.class
scp -p -i key-pair-eclipse-1.pem build.xml \
ec2-user@ec2-ex-am-pl-e01.compute-1.amazonaws.com:build.xml
scp -r -p -i key-pair-eclipse-1.pem lib \
ec2-user@ec2-ex-am-pl-e01.compute-1.amazonaws.com:lib
scp -r -p -i key-pair-eclipse-1.pem third-party \
ec2-user@ec2-ex-am-pl-e01.compute-1.amazonaws.com:third-party
Note
If you launched an AMI other than the Amazon Linux AMI recommended earlier, you may need
to use "root" instead of "ec2-user" when connecting to the instance using SCP or SSH.
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 may need to fix the permissions on your
instance by using the following command:
chmod -R u+rwx GetS3Object.class build.xml lib third-party
Run the Program
To run the program, use SSH to connect to your EC2 instance.
Version v1.0.0
35
AWS SDK for Java Developer Guide
Using IAM Roles for EC2 Instances