
scp -i ruby-iam-ec2-ssh.pem get_object.rb \
Note
If you launched an EC2 machine image other than the Amazon Linux AMI recommended earlier,
you may need to use "root" instead of "ec2-user" when connecting to the instance using ssh or
scp. Additionally, the steps for configuring and running the program in the next section may differ
somewhat.
Run the program within the EC2 instance
To run the program
1. Connect to your EC2 instance with ssh. Use the same public DNS name and .pem file you used to
copy the source code in the preceding section—for example:
2. The Amazon Linux AMI has Ruby 1.8.7 installed by default. However, we recommend using Ruby
1.9 with the AWS SDK for Ruby. To install Ruby 1.9 on the Amazon Linux AMI, use the following
command:
sudo yum install ruby19 rubygems19
3. Set your AMI to use Ruby 1.9 by default by executing the following command:
sudo alternatives --set ruby /usr/bin/ruby1.9
4. Install additional development packages needed by the AWS SDK for Ruby:
sudo yum install -y gcc ruby-devel19 libxml2 libxml2-devel libxslt libxslt-
devel make
5. Install the AWS SDK for Ruby:
sudo gem install aws-sdk --no-ri --no-rdoc
The --no-ri and --no-rdoc options tell gem to not compile the Ruby documentation for the aws-
sdk gem. This will make the installation considerably faster.
6. Run the program:
ruby get_object.rb
If everything is set up correctly, the file should be copied to your EC2 instance just as it was to your local
machine when you were using credentials. This time, however, the credentials you used were not stored
in your program or on your EC2 instance. Instead, IAM managed the credentials for you!
Version v1.0.0
15
AWS SDK for Ruby Developer Guide
Walkthrough: Using IAM Roles to Retrieve an Amazon
S3 Object from an EC2 Instance
Comentários a estes Manuais