Amazon AWS SDK Uživatelský manuál Strana 18

  • Stažení
  • Přidat do mých příruček
  • Tisk
  • Strana
    / 26
  • Tabulka s obsahem
  • KNIHY
  • Hodnocené. / 5. Na základě hodnocení zákazníků
Zobrazit stránku 17
require 'rubygems'
require 'aws-sdk'
s3 = AWS::S3.new()
bucket_name = 'text-content'
obj_name = 'text-object.txt'
document = s3.buckets[bucket_name].objects[obj_name]
File.open(obj_name, "w") do |f|
f.write(document.read)
end
puts "'#{obj_name}' copied from S3."
Tip
Try running the modified program on your local system to verify that it does not work without
credentials. If you haven't set your AWS credentials in your environment, you will get an
AWS::Errors::MissingCredentialsError exception.
Transfer the modified source to your EC2 instance
Transfer the modified source file to your EC2 instance using scp. Be sure to specify the .pem file you
created earlier, and use the public DNS name of the instance to connect with.The command will look
something like this:
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:
ssh -i ruby-iam-ec2-ssh.pem [email protected]
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:
Version v1.0.0
15
AWS SDK for Ruby Developer Guide
Updating the Sample Program to Use IAM Roles
Zobrazit stránku 17
1 2 ... 13 14 15 16 17 18 19 20 21 22 23 24 25 26

Komentáře k této Příručce

Žádné komentáře