How to integrate Amazon Web Services in your Web Application?

September 1st, 2009 by archit.patel § 1

What is Amazon Web Services (AWS)?
Amazon Web Services (AWS) has provided companies of all sizes with an infrastructure web services platform in the cloud. With AWS you can requisition compute power, storage, and other services–gaining access to a suite of elastic IT infrastructure services as your business demands them.

Amazon Web Services provides a number of benefits for IT organizations which are:cost effective,dependable,flexible.

How  to integrate amazon in your site?
-> You need to get an access_key_id.
-> Authorized your Product API or Access_key.

How to get an access_key_id?
To get an access_key you have to create aws account from the below link:
https://aws-portal.amazon.com/gp/aws/developer/registration/index.html

After submitting the form you will get a mail from amazon. In that mail you will find a link link:
https://aws-portal.amazon.com/gp/aws/developer/account/index.html?ie=UTF8&action=access-key

From this link you will get your access key and private key. Store your public key(access key) and private key(secret key) in your config file. Using this access_key you can access all amazon  books and its details  in your page.

How to make your Product API or Access_key Authorized?
You need to create a two demo files and one function file using below code

1) Function file-  aws_signature.php
2) Example file- example1.php
3) Example file- example2.php

1)Make one file named as aws_signature.php
<?php
function aws_signature($location, $params, $public_key, $private_key)
{
$private_key=”your secret key”;
$method = “GET”;
$hostname = “ecs.amazonaws.”.$location;
$uri = “/onca/xml”;

// additional parameters
$params["Service"] = “AWSECommerceService”;
$params["AWSAccessKeyId"] = $public_key;

// GMT timestamp
$params["Timestamp"] = gmdate(“Y-m-d\TH:i:s\Z”);

// API version
$params["Version"] = “2009-03-31″;

// sort the parameters
ksort($params);

// create the query
$query = array();
foreach ($params as $param=>$value)
{
$param = str_replace(“%7E”, “~”, rawurlencode($param));
$value = str_replace(“%7E”, “~”, rawurlencode($value));
$query[] = $param.”=”.$value;
}
$query = implode(“&”, $query);
$string_to_sign = $method.”\n”.$hostname.”\n”.$url.”\n”.$query;
$signature = base64_encode(hash_hmac(“sha256″, $string_to_sign, $private_key, True));

// create request
$request = “http://”.$hostname.$url.”?”.$query.”&Signature=”.$signature;
// do request
$request=str_replace(” “,”+”,$request);
$response = @file_get_contents($request);
if ($response === False)
{
return False;
}
else
{
// parse XML
$parsed_xml = simplexml_load_string($response);
if ($parsed_xml === False)
{
return False; // no xml
}
else
{
return $parsed_xml;
}
}
//Note:You can use  $parsed_xml as you requested array.You will get all the records from this array.
?>

2)Make one file named as example1.php
//To get the data for particular ISBN.
<?php
include(‘aws_signature.php’);
$isbn=”your book isbn value”;
include(‘aws_signature.php’);
$public_key = “your public key”;
$private_key = “your private key”;

//You can select response group from this site:http://docs.amazonwebservices.com/_
AWSECommerceService/2008-03-03    /DG/index.html?ItemLookup.html

//Operation is ItemLookup for Particular item page.
$parsed_xml = aws_signature(“com”,  array(“Operation”=>”ItemLookup”,”ResponseGroup”=>”VariationSummary,_
SalesRank,Medium,Reviews,ItemAttributes,Offers,Images”,”ItemId”=>$isbn),   $public_key, $private_key);
?>

3)Make one file named as example2.php
//To get all books from amazon without knowing any book isbn value.
<?php
include(‘aws_signature.php’);
$public_key = “YOur public key”;
$private_key = “your private key”;
$new_keyword=”Your keyword”;

//Operation is ItemSearch for all books.
$parsed_xml = aws_signature(“com”,   array(“Operation”=>”ItemSearch”,”SearchIndex”=>”Books”,”ResponseGroup”=>”VariationSummary,_
SalesRank,Medium,Reviews,ItemAttributes,Offers,Images”,”Keywords”=>$new_keyword),  $public_key, $private_key);
?>

Where Am I?

You are currently browsing the Amazon category at Digicorp.