Wednesday 26 September 2012

Amazon Web Services


Amazon Web Services

Amazon Web Services (AWS) is a collection of remote computing services (also called web services) that together make up a cloud computing platform.

The AWS gems have been designed to provide a robust, fast, and secure interface to Amazon EC2, EBS, S3, SQS, SDB, and CloudFront.

  • Aws::EC2 -- Interface to Amazon EC2 (Elastic Compute Cloud) and the associated EBS (Elastic Block Store)
  • Aws::S3 and Aws::S3Interface -- interface to Amazon S3 (Simple Storage Service)
  • Aws::Sqs and Aws::SqsInterface -- interface to Amazon SQS (Simple Queue Service)
  • Aws::SdbInterface -- interface to Amazon SDB (SimpleDB).
  • Aws::AcfInterface -- interface to Amazon CloudFront, a content distribution service
  • Aws::ElbInterface 00 interface to Amazon Load Balancing service
  • Aws::MonInterface -- interface to Amazon CloudWatch monitoring service
  • Aws::Iam -- for AWS Identity and Access Management

Getting Started with the AWS SDK for Ruby

Get Set Up

To get set up, you must sign up for Amazon Web Services, get your AWS credentials, and set up your environment.

Sign Up for AWS Products

Before you can begin, you must sign up for each AWS product you want to use. The sample included in the SDK uses Amazon S3, so we'll use that product as an example here.

To sign up for a product

  1. Go to the home page for the product, for example aws.amazon.com/s3
  2. Click the sign-up button on the top right corner of the page.
  3. Follow the on-screen instructions. If you don't already have an AWS account, you are prompted to create one as part of the sign-up process.
AWS sends you a confirmation e-mail after the sign-up process is complete. You can view your current account activity or manage your account at any time, by going to aws.amazon.com and clicking the Account tab.

Get Your Credentials

To use the AWS SDK for Ruby, you need your AWS Access Key ID and Secret Access Key.

To get your AWS Access Key ID and Secret Access Key

  1. Click Account and then click Security Credentials. The Security Credentials page displays ( you might be prompted to log in).
  2. Scroll down to Access Credentials and make sure the Access Keys tab is selected. The AWS Access Key ID appears in the Access Key column.
  3. To view the Secret Access Key, click Show.

Important! Your Secret Access Key is a secret, which only you and AWS should know. It is important to keep it confidential to protect your account. Store it securely in a safe place. Never include it in your requests to AWS, and never e-mail it to anyone. Do not share it outside your organization, even if an inquiry appears to come from AWS or Amazon.com. No one who legitimately represents Amazon will ever ask you for your Secret Access key.

Set Up Your environment

The AWS Ruby gem runs on Ruby 1.8.7 and later. If you have an older version of Ruby, RVM is a great way to get started using the latest version.

Install the SDK

To install the AWS Ruby gem, just enter:
gem install aws-sdk


Run the Samples
Now that you’ve installed the gem, you can run the samples, which you can find in our GitHub repository:
$ git clone git://github.com/amazonwebservices/aws-sdk-for-ruby.git
$ cd aws-sdk-for-ruby/samples/


The subdirectories of the samples directory contain several code samples that you can run. These samples demonstrate basic usage of the SDK features.

To run the Amazon S3 Sample

  1. Create a file named config.yml in the samples directory as follows:
# Fill in your AWS Access Key ID and Secret Access Key
access_key_id : REPLACE_WITH_ACCESS_KEY_ID
secret_access_key: REPLACE_WITH_SECRET_ACCESS_KEY


  1. Run a sample script with the Ruby interpreter. For example, to run the s3/upload_file.rb sample:
$ echo “Hello, World!” > helloworld.txt
$ ruby s3/upload_file.rb unique-bucket-name helloworld.txt



To use the AWS ORM in a Rails 3 application

  1. Install the gem:
$ gem install aws-sdk


  1. Start a new Rails project
$ gem install rails
$ rails new myapp
$ cd myapp/


  1. Add the following line to your Gemfile:
gem ‘aws-sdk’


  1. Install dependencies:
$ bundle install


  1. Now you need to configure AWS with your access credentials. You can use a config initializer script (e.g. config/Initializers/aws.rb) and use Ruby to configure your AWS credentials:
AWS.config({
 :access_key_id => ‘REPLACE_WITH_ACCESS_KEY_ID’
 :secret_access_key => ‘REPLACE_WITH_SECRET_ACCESS_KEY’,
})

or you can create a config/aws.yml file that will also be automatically loaded with Rails:

# Just like the config/database.yml this file requires an entry for each environment

development:
 access_key_id : REPLACE_WITH_ACCESS_KEY_ID
 secret_access_key: REPLACE_WITH_SECRET_ACCESS_KEY
test:
 <<: *development
production:
 <<: *development



  1. Create app/models/my_record.rb as follows:
class MyRecord < AWS::Record::Base
 string_attr :name
end


  1. Create the SimpleDB domain:
$ rails console
> MyRecord.create_domain

Now, you can play around with the model by creating some records and querying them:
> MyRecord.find(:all).to_a
=> []
> MyRecord.new(:name => “The first one”).save
=> true
> MyRecord.new(:name => “The second one”).save
=> true
> MyRecord.where(‘name like ?’, “%first%”).count
=> 1

Exit the rails console before continuing to the next step:
> exit


  1. Generate a scaffold controller for your model:
$ rails generate scaffold_controller MyRecord name:string
$ rails server



  1. Add a route to your scaffold controller in config/routes.rb:
Myapp::Application.routes.draw do
# add this line:
resources :my_records
end


  1. Now, you can create records in the browser at localhost:3000/my_records.



Amazon SimpleDB (beta)

Amazon SimpleDB is a highly available and flexible non-relational data store that offloads the work of database administration. Developers simply store and query data items via web services requests and Amazon SimpleDB does the rest.

Unbound by the strict requirements of a relational database, Amazon SimpleDB is optimized to provide high availability and flexibility, with title or no administrative burden. Behind the scenes, Amazon SimpleDB creates and manages multiple geographically distributed replicas of your data automatically to enable high availability and data durability.

You can change your data model on the fly, and data is automatically indexed for you. With Amazon SimpleDB, you can focus on application development without worrying about infrastructure provisioning, high availability, software maintenance, schema and index management, or performance tuning.

Amazon SimpleDB Functionality

Amazon SimpleDB provides a simple web services interface to create and store multiple data sets, query your data easily, and return the results. your data is automatically indexed, making it easy to quickly find the information that you need. These is no need to predefine a schema or change a schema if new data is added later. And scale-out is as simple as creating new domains, rather than building out new servers.

To use Amazon SimpleDB you:

  1. Build your data set
    • Choose a Region for your Domain(s) to optimize for latency, minimize costs, or address regulatory requirements. Amazon SimpleDB is currently available in the US East (Northern Virginia), US West (Oregon), US West (Northern California), EU (Ireland), Asia Pacific (Singapore), Asia Pacific (tokyo), and South America (Sao Paulo) Regions.
    • Use CreateDomain, DeleteDomain, ListDomains, DomainMetadata to create and manage query domains
    • Use Put,Batch Put, & Delete to create and manage the data set within each query domain
  2. Retrieve your data
    • Use GetAttributes to retrieve a specific item
    • Use Select to query your data set for items that meet specified criteria
  3. Pay only for the resources that you consume












More Info. See  below links


No comments:

Post a Comment