What is S3 in AWS ? What is it used for?

S3 stands for Simple Storage Service. You can think of it like ftp storage, where you can move files to and from there, but not mount it like a filesystem. AWS automatically puts your snapshots there, as well as AMIs (Amazon Machine Image) there. Encryption should be considered for sensitive data, as S3 is a proprietary technology developed by Amazon themselves, and as yet unproven vis-a-vis a security standpoint.

What are the security laws which are implemented to secure data in a cloud ?

The security laws which are implemented to secure data in cloud are

  • Processing: Control the data that is being processed correctly and completely in an application
  • File: It manages and control the data being manipulated in any of the file
  • Output reconciliation: It controls the data which has to be reconciled from input to output
  • Input Validation: Control the input data
  • Security and Backup: It provides security and backup it also controls the security breaches logs

What is “ EUCALYPTUS” in Cloud Computing

“ EUCALYPTUS” stands for Elastic Utility Computing Architecture For Linking Your Programs To Useful Systems”

Use of “EUCALYPTUS” in cloud computing?

“Eucalyptus” is an open source software infrastructure in cloud computing, which is used to implement clusters in cloud computing platform. It is used to build public, hybrid and private clouds. It has the ability to produce your own data center into a private cloud and allows you to use its functionality to many other organizations.

What are the different deployment models that Cloud Computing supports ?

Cloud computing supports many deployment models and they are as follows:

Private Cloud
Organizations choose to build there private cloud as to keep the strategic, operation and other reasons to themselves and they feel more secure to do it. It is a complete platform which is fully functional and can be owned, operated and restricted to only an organization or an industry. More organizations have moved to private clouds due to security concerns. Virtual private cloud is being used that operate by a hosting company.

Public Cloud
These are the platforms which are public means open to the people for use and deployment. For example, google, amazon etc. They focus on a few layers like cloud application, infrastructure providing and providing platform markets.

Hybrid Clouds
It is the combination of public and private cloud. It is the most robust approach to implement cloud architecture as it includes the functionalities and features of both the worlds. It allows organizations to create their own cloud and allow them to give the control over to someone else as well.

OPENSTACK CLOUD PLATFORM

OpenStack: The Open Source Cloud Operating System

OpenStack is a collaborative software project designed to create freely available code, badly needed standards, and common ground for the benefit of both cloud providers and cloud customers. OpenStack is currently divided into three projects:

OPENSTACK COMPUTE: open source software and standards for large-scale deployments of automatically provisioned virtual compute instances

OPENSTACK OBJECT STORAGE: open source software and standards for large-scale, redundant storage of static objects.

OPENSTACK IMAGE SERVICE: provides discovery, registration, and delivery services for virtual disk images.

FEATURES:

Control and Flexibility.

Industry Standard.

Proven Software.

Compatible and Connected.

Amazon FPS: How does it work

Amazon Flexible Payments Service is a payment service designed for developers.
Unlike other payment services, there are mainly 3 actors in a typical Amazon FPS transaction:

Sender —> Caller —> Receiver

Sender is the buyer (customer) – the person who makes the payment
Receiver is the seller (business) – the person who received the payment
Caller is the developer (code) – this makes the API calls

Steps in an Amazon FPS payment transaction are:

  1. When the “buyer” is ready to make the payment, he is taken to a “Co-Branded” (here we use the Co-Branded Service API)
  2. The “buyer” will then login into his Amazon Payments account and:
    1. Authorize the payment
    2. Confirm the authorization. A “sender token” will be generated at this point
  3. The “buyer” is then redirected back to the “seller” website. The return URL is decided by the redirectURL parameter. At this point the “seller” gets the “sender token” (attached with the redirectURL parameter).
  4. The “seller” then initiates a “pay” request with the “sender token” (here we use the Amazon FPS API)
  5. Amazon will then process this “pay” request and send back an appropriate response – payment status.

As you can see there are 2 interfaces that you will need to implement:

  1. Co-Branded API: to get the buyer authorization and confirmation
  2. Amazon FPS API: to process the payment.

Also, when you use Amazon FPS you and your customer will both need Amazon Payments accounts (if, a buyer doesn’t have a Amazon Payments account then, one will be created during the payment process)

The different types of Amazon Payments accounts are:

  1. Personal Account:
    You can send and receive payments via bank accounts or amazon payment accounts BUT. not credit card
  2. Business Account:
    All the features of a Personal Account + can process credit card payments
  3. Developer Account:
    A Business Account that can make Amazon web services calls – hence, this is also called a “caller account
  4. Sandbox Account:
    This account allows you to make Amazon web services calls to the test environment without any charges.

To use Amazon FPS in your site you will need an AWS Account (for the access credentials), Amazon FPS Developer Account (to make API calls and accept payments) and a Sandbox Account (to test the web services).

Always test your test in the Sandbox before making it live!

In the next post I will explain how to integrate these APIs and accounts.

SimpleFPS – PHP Amazon FPS Library

SimpleFPS – PHP Amazon FPS Library

SimpleFPS allows PHP developers to stop worrying about some of the low-level implementation details of Amazon FPS.

Download SimpleFPS – PHP Amazon FPS Library from http://sampleapps.s3.amazonaws.com/SimpleFPS.zip

Extract the zip file and put it in the location that you need that to be.

Go to the SimpleFPS/SimpleFPS/sample/ and inside that we will find one config.php file.

We have to provide the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to that file to get connected to the database.

We have to change the permission of the log.txt file to writable.

Now our SimpleFPS is ready and browsable.

In the SimpleFPS we can Make payments, Get account balance, View account activity etc….

Making Payments

Click on the Make Payment of $1 link.

make.jpg

This will be redirected to the amazon payments page where it will ask for the login information.

pay.jpg

For the testing purpose we have to get a sandbox account.

( For creating a sandbox account click here )

After login it will ask for confirmation where it will show to whom to be paid and also the billing information

confirl.JPG

When we confirm the payment is being done. The result will be send to a returning URL that is being provided by us.

res.JPG

Creating Simple CRUD using Amazon Simple db

Download sample php library from the link http://developer.amazonwebservices.com/connect/entry.jspa?externalID=1135

Extract the zip file and put it in the location that you need that to be.

The folder structure will be like this.

dir.jpg

We have to provide the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to every file to get connected to the database.

Now to get the list of all the domains we have to do these steps.

1.Open a clean copy of ListDomainsSample.php.
2.Remove any comment marks from the invokeListDomains($service, $request); line and add the following line after the @TODO: set request line:
$request = new Amazon_SimpleDB_Model_ListDomains();
3.Run the sample.
Amazon SimpleDB returns the list of domains within the account

Code for ListDomainsSample.php

<?php
/**
* PHP Version 5
*
* @category Amazon
* @package Amazon_SimpleDB
* @copyright Copyright 2008 Amazon Technologies, Inc.
* @link http://aws.amazon.com
* @license http://aws.amazon.com/apache2.0 Apache License, Version 2.0
* @version 2007-11-07
*/
/*******************************************************************************
* __ _ _ ___
* ( )( \/\/ )/ __)
* /__\ \ / \__ \
* (_)(_) \/\/ (___/
*
* Amazon Simple DB PHP5 Library
* Generated: Thu Aug 28 06:20:51 PDT 2008
*
*/

/**
* List Domains Sample
*/

include_once (‘.config.inc.php’);

/************************************************************************
* Instantiate Implementation of Amazon SimpleDB
*
* AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY constants
* are defined in the .config.inc.php located in the same
* directory as this sample
***********************************************************************/
$service = new Amazon_SimpleDB_Client(‘1T477KF4HAV4SWT4T982′,
‘622gIa+NcAhJFe2ulJ3XBrd5NRIUb2OhkCTjn5uR’);
/************************************************************************
* Uncomment to try out Mock Service that simulates Amazon_SimpleDB
* responses without calling Amazon_SimpleDB service.
*
* Responses are loaded from local XML files. You can tweak XML files to
* experiment with various outputs during development
*
* XML files available under Amazon/SimpleDB/Mock tree
*
***********************************************************************/
// $service = new Amazon_SimpleDB_Mock();

/************************************************************************
* Setup request parameters and uncomment invoke to try out
* sample for List Domains Action
***********************************************************************/
// @TODO: set request. Action can be passed as Amazon_SimpleDB_Model_ListDomainsRequest
// object or array of parameters
require_once (‘Amazon/SimpleDB/Model/ListDomainsRequest.php’);
$request = new Amazon_SimpleDB_Model_ListDomainsRequest();
invokeListDomains($service, $request);

/**
* List Domains Action Sample
* The ListDomains operaton lists all domains associated with the Access Key ID. It returns
* domain names up to the limit set by MaxNumberOfDomains. A NextToken is returned if there are more
* than MaxNumberOfDomains domains. Calling ListDomains successive times with the
* NextToken returns up to MaxNumberOfDomains more domain names each time.
*
* @param Amazon_SimpleDB_Interface $service instance of Amazon_SimpleDB_Interface
* @param mixed $request Amazon_SimpleDB_Model_ListDomains or array of parameters
*/
function invokeListDomains(Amazon_SimpleDB_Interface $service, $request)
{
try {
$response = $service->listDomains($request);

// echo (“Service Response<br />”);
// echo (“=============================================================================\n”);

//echo(” ListDomainsResponse<br />”);
if ($response->isSetListDomainsResult()) { ?><title>Create and Listing of Domains —— Amazon Simple DB Test by Sreeraj</title>
<h2 style=”color:#FF0000; font-family:Arial, Helvetica, sans-serif;”>
<?php echo(“Domains ( Tables )<br />”);?></h2>
<?php
$listDomainsResult = $response->getListDomainsResult();
$domainNameList = $listDomainsResult->getDomainName();?>
<table border=”1″ cellpadding=”5″ style=” border-collapse:collapse; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:14px; margin-bottom:20px;”>
<tr>
<th>Domain Name</th>
<th>Actions</th>
</tr>
<?php foreach ($domainNameList as $domainName) { ?>
<tr>
<td><?php echo(” ” . $domainName);?></td>
<td><a style=”text-decoration:none; font-family:Arial, Helvetica, sans-serif; font-size:12px;” href=”DeleteDomainSample.php?dom_name=<?php echo $domainName;?>” onClick=”return confirm(‘Do You want to delete Domain <?php echo $domainName;?>?’);”>[ Delete ]</a>  <a style=”text-decoration:none; font-family:Arial, Helvetica, sans-serif; font-size:12px;” href=”SimpleCrud.php?dom_name=<?php echo $domainName;?>”>[ C R U D ]</a></td>
</tr>
<?php }?>
</table>
<a style=”text-decoration:none; font-family:Arial, Helvetica, sans-serif; font-size:12px;” href=”CreateDomainSample.php”>[ Add New Domain ]</a>
<?php if ($listDomainsResult->isSetNextToken())
{
// echo(” NextToken<br />”);
// echo(” ” . $listDomainsResult->getNextToken() . “\n”);
}
}
if ($response->isSetResponseMetadata()) {
//echo(” ResponseMetadata<br />”);
$responseMetadata = $response->getResponseMetadata();
if ($responseMetadata->isSetRequestId())
{
// echo(” RequestId\n”);
// echo(” ” . $responseMetadata->getRequestId() . “\n”);
}
if ($responseMetadata->isSetBoxUsage())
{
// echo(” BoxUsage\n”);
// echo(” ” . $responseMetadata->getBoxUsage() . “\n”);
}
}

} catch (Amazon_SimpleDB_Exception $ex) {
echo(“Caught Exception: ” . $ex->getMessage() . “\n”);
echo(“Response Status Code: ” . $ex->getStatusCode() . “\n”);
echo(“Error Code: ” . $ex->getErrorCode() . “\n”);
echo(“Error Type: ” . $ex->getErrorType() . “\n”);
echo(“Request ID: ” . $ex->getRequestId() . “\n”);
echo(“XML: ” . $ex->getXML() . “\n”);
}
}

Now lets see how to create a new domain in the database.
1.Open a clean copy of CreateDomainSample.php.
2.Remove any comment marks from the invokeCreateDomain($service, $request); line and add the following lines after the // @TODO: set request line:

require_once (‘Amazon/SimpleDB/Model/CreateDomain.php’);
$request = new Amazon_SimpleDB_Model_CreateDomain();
$request->setDomainName(‘MyStore’);
3.Run the sample.
The MyStore domain is created.

Code for CreateDomainSample.php

<?php
/**
* PHP Version 5
*
* @category Amazon
* @package Amazon_SimpleDB
* @copyright Copyright 2008 Amazon Technologies, Inc.
* @link http://aws.amazon.com
* @license http://aws.amazon.com/apache2.0 Apache License, Version 2.0
* @version 2007-11-07
*/
/*******************************************************************************
* __ _ _ ___
* ( )( \/\/ )/ __)
* /__\ \ / \__ \
* (_)(_) \/\/ (___/
*
* Amazon Simple DB PHP5 Library
* Generated: Thu Aug 28 06:20:51 PDT 2008
*
*/

/**
* Create Domain Sample
*/

include_once (‘.config.inc.php’);

/************************************************************************
* Instantiate Implementation of Amazon SimpleDB
*
* AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY constants
* are defined in the .config.inc.php located in the same
* directory as this sample
***********************************************************************/
$service = new Amazon_SimpleDB_Client(‘1T477KF4HAV4SWT4T982′,
‘622gIa+NcAhJFe2ulJ3XBrd5NRIUb2OhkCTjn5uR’);

/************************************************************************
* Uncomment to try out Mock Service that simulates Amazon_SimpleDB
* responses without calling Amazon_SimpleDB service.
*
* Responses are loaded from local XML files. You can tweak XML files to
* experiment with various outputs during development
*
* XML files available under Amazon/SimpleDB/Mock tree
*
***********************************************************************/
// $service = new Amazon_SimpleDB_Mock();

/************************************************************************
* Setup request parameters and uncomment invoke to try out
* sample for Create Domain Action
***********************************************************************/
// @TODO: set request. Action can be passed as Amazon_SimpleDB_Model_CreateDomainRequest
// object or array of parameters
require_once (‘Amazon/SimpleDB/Model/CreateDomainRequest.php’);
$request = new Amazon_SimpleDB_Model_CreateDomainRequest();
// Edited By Sreeraj 29/11/08
if(isset($_POST) && !empty($_POST))
{print “<pre>”;
print_r($_POST);
$domain_name = $_POST[‘domain’];
$request->setDomainName($domain_name);
invokeCreateDomain($service, $request);
}

/**
* Create Domain Action Sample
* The CreateDomain operation creates a new domain. The domain name must be unique
* among the domains associated with the Access Key ID provided in the request. The CreateDomain
* operation may take 10 or more seconds to complete.
*
* @param Amazon_SimpleDB_Interface $service instance of Amazon_SimpleDB_Interface
* @param mixed $request Amazon_SimpleDB_Model_CreateDomain or array of parameters
*/
function invokeCreateDomain(Amazon_SimpleDB_Interface $service, $request)
{
try {
$response = $service->createDomain($request);
header(“Location: SimpledbManage.php”);

} catch (Amazon_SimpleDB_Exception $ex) {
echo(“Caught Exception: ” . $ex->getMessage() . “\n”);
echo(“Response Status Code: ” . $ex->getStatusCode() . “\n”);
echo(“Error Code: ” . $ex->getErrorCode() . “\n”);
echo(“Error Type: ” . $ex->getErrorType() . “\n”);
echo(“Request ID: ” . $ex->getRequestId() . “\n”);
echo(“XML: ” . $ex->getXML() . “\n”);
}
}
?>
<html>
<head>
<title>Create and Listing of Domains —— Amazon Simple DB Test by Sreeraj</title>
<script type=”text/javascript” src=”jquery.js”></script>
<script type=”text/javascript”>
function find_total_elements()
{
var tot = 0;
var id_value = 0;
jQuery(document).find(“input[@id^=first_name]”).each(function()
{
tot = tot + 1
});
id_value = tot + 1;

/* for updating the hidden field */
jQuery(“#tot_product”).val(id_value);

/* Product form for adult */
next_fields = ” <p id=\”product_”+id_value+”\” style=\”width:450px;\”><span style=\”font-family:Arial, Helvetica, sans-serif; font-size:14px; color:#006600; font-weight:bold;\”>Field Name</span>”;
next_fields +=”<input type=\”hidden\” name=\”type[]\” id=\”type\” value=\”adult\”/>”
//next_fields += ” <tr><td width=\”35%\”><font color=\”#333333\” face=\”Verdana\” size=\”1\”><span style=\”font-size: 8.5pt; font-family: Verdana; color: rgb(51, 51, 51);\”>First Name </span></font></td><td width=\”32%\”><font color=\”#333333\” face=\”Verdana\” size=\”1\”><span style=\”font-size: 8.5pt; font-family: Verdana; color: rgb(51, 51, 51);\”>Middle Name </span></font></td><td width=\”33%\”><font color=\”#333333\” face=\”Verdana\” size=\”1\”><span style=\”font-size: 8.5pt; font-family: Verdana; color: rgb(51, 51, 51);\”>Last Name</span></font></td></tr><tr>”;
next_fields += “<td height=\”24\” align=\”center\” valign=\”top\”><input type=\”text\” name=\”firstname[]\” id=\”first_name_”+id_value+”\” style=\”width:130px;\” />”;

div_id = id_value – 1;
$( “#product_”+div_id+”” ).after( next_fields );
}

</script>
</head>
<body>
<form method=”post”>
<h2 style=”color:#FF0000; font-family:Arial, Helvetica, sans-serif;”>Create Domains ( Tables )</h2>
<span style=”font-family:Arial, Helvetica, sans-serif; font-size:14px; color:#006600; font-weight:bold;”>Domain name: </span><input type=”text” name=”domain” id=”domain” /><br />
<p id=”product_1″ style=”width:460px;height:10px;text-align:center”><span style=”font-family:Arial, Helvetica, sans-serif; font-size:14px; color:#006600; font-weight:bold;”>Field Name</span>

<input type=”hidden” name=”tot_product” id=”tot_product” value=”1″/>
<input type=”hidden” name=”type[]” id=”type” value=”adult”/>
<input type=”text” name=”firstname[]” id=”first_name_1″ style=”width:130px;” />

<input name=”button2″ type=”button” id=”button” onClick=”find_total_elements();” value=”Add Fields” />
<input type=”submit” name=”submit” id=”submit” value=”Create” />
</form>
<a style=”text-decoration:none; font-family:Arial, Helvetica, sans-serif; font-size:12px;” href=”ListDomainsSample.php”>[ List Domains ]</a>
</body>
</html>

Now lets see how to create a simple crud.

1. For this we have to pass the domain name as a get variable.
2. Then by query we will get the data present in the domain to a variable as array.
3. The we can format it in a table format and crud is obtained.

Code for SimpleCrud.php

<?php
/**
* PHP Version 5
*
* @category Amazon
* @package Amazon_SimpleDB
* @copyright Copyright 2008 Amazon Technologies, Inc.
* @link http://aws.amazon.com
* @license http://aws.amazon.com/apache2.0 Apache License, Version 2.0
* @version 2007-11-07
*/
/*******************************************************************************
* __ _ _ ___
* ( )( \/\/ )/ __)
* /__\ \ / \__ \
* (_)(_) \/\/ (___/
*
* Amazon Simple DB PHP5 Library
* Generated: Thu Aug 28 06:20:51 PDT 2008
*
*/

/**
* Query With Attributes Sample
*/

include_once (‘.config.inc.php’);

/************************************************************************
* Instantiate Implementation of Amazon SimpleDB
*
* AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY constants
* are defined in the .config.inc.php located in the same
* directory as this sample
***********************************************************************/
$service = new Amazon_SimpleDB_Client(‘1T477KF4HAV4SWT4T982′,
‘622gIa+NcAhJFe2ulJ3XBrd5NRIUb2OhkCTjn5uR’);

/************************************************************************
* Uncomment to try out Mock Service that simulates Amazon_SimpleDB
* responses without calling Amazon_SimpleDB service.
*
* Responses are loaded from local XML files. You can tweak XML files to
* experiment with various outputs during development
*
* XML files available under Amazon/SimpleDB/Mock tree
*
***********************************************************************/
// $service = new Amazon_SimpleDB_Mock();

/************************************************************************
* Setup request parameters and uncomment invoke to try out
* sample for Query With Attributes Action
***********************************************************************/
// @TODO: set request. Action can be passed as Amazon_SimpleDB_Model_QueryWithAttributesRequest
// object or array of parameters
require_once (‘Amazon/SimpleDB/Model/QueryWithAttributesRequest.php’);
$request = new Amazon_SimpleDB_Model_QueryWithAttributesRequest();
$domain = $_GET[‘dom_name’];
$request->setDomainName($domain);
//$request->setQueryExpression(“[‘Name’ != ”]”);
//$request->MyFunction();
invokeQueryWithAttributes($service, $request);

/**
* Query With Attributes Action Sample
* The QueryWithAttributes operation returns a set of item names and associated attributes.
* The query semantics of this operation are identical to the Query operation.
*
* @param Amazon_SimpleDB_Interface $service instance of Amazon_SimpleDB_Interface
* @param mixed $request Amazon_SimpleDB_Model_QueryWithAttributes or array of parameters
*/
function invokeQueryWithAttributes(Amazon_SimpleDB_Interface $service, $request)
{
try {
$response = $service->queryWithAttributes($request);

// echo (“Service Response\n”);
// echo (“=============================================================================\n”);

// echo(” QueryWithAttributesResponse\n”);
if ($response->isSetQueryWithAttributesResult()) {
// echo(” QueryWithAttributesResult<br />”);
$queryWithAttributesResult = $response->getQueryWithAttributesResult();
$itemList = $queryWithAttributesResult->getItem();
$dom = $_GET[‘dom_name’];
?><title>CRUD Using the Amazon SimpleDb————- Test Done by Sreeraj</title>
<h2 style=”color:#FF0000; font-family:Arial, Helvetica, sans-serif;”>Sample Data</h2>
<div align=”left” style=”margin-bottom:10px;”>
<a style=”text-decoration:none; font-family:Arial, Helvetica, sans-serif; font-size:12px;” href=”PutAttributesSample.php?dom_name=<?php echo $dom;?>”>[ Add New Record ]</a> <a style=”text-decoration:none; font-family:Arial, Helvetica, sans-serif; font-size:12px;” href=”SimpledbManage.php”>[ Manage Domains ]</a>
</div>
<table border=”1″ style=”border-collapse:collapse; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;” cellpadding=”5″ align=”left”>
<th colspan=”6″>Sample data</th>
<tr>
<th>Id</th>
<th>Name</th>
<th>Age</th>
<th colspan=”3″>Actions</th>
</tr>
<?php foreach ($itemList as $item) {?>
<?php //print “<pre>”;
//print_r($item);
// echo(” Item\n”);?>
<tr>
<td>
<?php if ($item->isSetName())
{
// echo(” Name\n”);
echo($item->getName());
}?>
</td>
<td>
<?php $attributeList = $item->getAttribute();
foreach ($attributeList as $attribute) {
//print “<pre>”;
//print_r($attribute);
//echo(” Attribute\n”);

if ($attribute->isSetName())
{
// echo(” Name\n”);
//echo(” ” . $attribute->getName() . “\n”);
}
if ($attribute->isSetValue() && $attribute->getName() == ‘Name’)
{
//echo(” Value\n”);
echo($attribute->getValue());
$name = $attribute->getValue();
}
}?>
</td>
<td>
<?php $attributeList = $item->getAttribute();
foreach ($attributeList as $attribute) {
//print “<pre>”;
//print_r($attribute);
//echo(” Attribute\n”);

if ($attribute->isSetName())
{
// echo(” Name\n”);
//echo(” ” . $attribute->getName() . “\n”);
}
if ($attribute->isSetValue() && $attribute->getName() == ‘Age’)
{
//echo(” Value\n”);
echo(” ” . $attribute->getValue());
}
}?>
</td>
<td><a style=”text-decoration:none; font-family:Arial, Helvetica, sans-serif; font-size:12px;” href=”GetAttributesSample.php?dom_name=<?php echo $dom;?>&ItemID=<?php echo $item->getName();?>”>[ View ]</a></td>
<td><a style=”text-decoration:none; font-family:Arial, Helvetica, sans-serif; font-size:12px;” href=”EditPage.php?dom_name=<?php echo $dom;?>&ItemID=<?php echo $item->getName();?>”>[ Edit ]</a></td>
<td><a style=”text-decoration:none; font-family:Arial, Helvetica, sans-serif; font-size:12px;” href=”DeleteAttributesSample.php?dom_name=<?php echo $dom;?>&ItemID=<?php echo $item->getName();?>” onClick=”return confirm(‘Do You want to delete  <?php echo $name;?>?’);”>[ Delete ]</a></td>
<?php }?>
</tr>
</table>

<?php if ($queryWithAttributesResult->isSetNextToken())
{
//echo(” NextToken\n”);
//echo(” ” . $queryWithAttributesResult->getNextToken() . “\n”);
}
}
if ($response->isSetResponseMetadata()) {
// echo(” ResponseMetadata\n”);
$responseMetadata = $response->getResponseMetadata();
if ($responseMetadata->isSetRequestId())
{
//echo(” RequestId\n”);
//echo(” ” . $responseMetadata->getRequestId() . “\n”);
}
if ($responseMetadata->isSetBoxUsage())
{
// echo(” BoxUsage\n”);
// echo(” ” . $responseMetadata->getBoxUsage() . “\n”);
}
}

} catch (Amazon_SimpleDB_Exception $ex) {
echo(“Caught Exception: ” . $ex->getMessage() . “\n”);
echo(“Response Status Code: ” . $ex->getStatusCode() . “\n”);
echo(“Error Code: ” . $ex->getErrorCode() . “\n”);
echo(“Error Type: ” . $ex->getErrorType() . “\n”);
echo(“Request ID: ” . $ex->getRequestId() . “\n”);
echo(“XML: ” . $ex->getXML() . “\n”);
}
}

Now lets see how to add a new value to the domain

1. For this we have to pass the domain name as a get variable.
2. Then by the PutAttributes class we can insert the data into the domain.
3. Here we can make a form and the data that has to be inserted will be obtained from the post value.
4. When we submit a new record gets inserted into the domain.

Code for PutAttributesSample.php

<?php
/**
* PHP Version 5
*
* @category Amazon
* @package Amazon_SimpleDB
* @copyright Copyright 2008 Amazon Technologies, Inc.
* @link http://aws.amazon.com
* @license http://aws.amazon.com/apache2.0 Apache License, Version 2.0
* @version 2007-11-07
*/
/*******************************************************************************
* __ _ _ ___
* ( )( \/\/ )/ __)
* /__\ \ / \__ \
* (_)(_) \/\/ (___/
*
* Amazon Simple DB PHP5 Library
* Generated: Thu Aug 28 06:20:51 PDT 2008
*
*/

/**
* Put Attributes Sample
*/

include_once (‘.config.inc.php’);

/************************************************************************
* Instantiate Implementation of Amazon SimpleDB
*
* AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY constants
* are defined in the .config.inc.php located in the same
* directory as this sample
***********************************************************************/
$service = new Amazon_SimpleDB_Client(‘1T477KF4HAV4SWT4T982′,
‘622gIa+NcAhJFe2ulJ3XBrd5NRIUb2OhkCTjn5uR’);

/************************************************************************
* Uncomment to try out Mock Service that simulates Amazon_SimpleDB
* responses without calling Amazon_SimpleDB service.
*
* Responses are loaded from local XML files. You can tweak XML files to
* experiment with various outputs during development
*
* XML files available under Amazon/SimpleDB/Mock tree
*
***********************************************************************/
// $service = new Amazon_SimpleDB_Mock();

/************************************************************************
* Setup request parameters and uncomment invoke to try out
* sample for Put Attributes Action
***********************************************************************/
// @TODO: set request. Action can be passed as Amazon_SimpleDB_Model_PutAttributesRequest
// object or array of parameters
require_once (‘Amazon/SimpleDB/Model/PutAttributesRequest.php’);
require_once (‘Amazon/SimpleDB/Model/ReplaceableAttribute.php’);
$domainName = $_GET[‘dom_name’];
/*———————————————————————
| This Section is edited by Sreeraj So as to test the Amazon SimpleDb |
| |
———————————————————————–*/
if(isset($_POST) && !empty($_POST))
{
$id = rand(0,1000);
$name = $_POST[‘test_name’];
$age = $_POST[‘test_age’];
/************************************************************************
* Items are rows in the table where the Itemname represents the Id of that record
* Domain is the table
* Load Data:
* Name = Sreeraj
* Age = 22
***********************************************************************/
$itemName = ‘ID_’.$id;// This is the id of the one row
$attribute1 = new Amazon_SimpleDB_Model_ReplaceableAttribute();
$attribute1->withName(‘Name’)->withValue($name);
$attribute2 = new Amazon_SimpleDB_Model_ReplaceableAttribute();
$attribute2->withName(‘Age’)->withValue($age);
$attributeList = array($attribute1, $attribute2);
$request = new Amazon_SimpleDB_Model_PutAttributesRequest();
$request->withDomainName($domainName)->withItemName($itemName)->setAttribute
($attributeList);

invokePutAttributes($service, $request);

}

/**
* Put Attributes Action Sample
* The PutAttributes operation creates or replaces attributes within an item. You specify new attributes
* using a combination of the Attribute.X.Name and Attribute.X.Value parameters. You specify
* the first attribute by the parameters Attribute.0.Name and Attribute.0.Value, the second
* attribute by the parameters Attribute.1.Name and Attribute.1.Value, and so on.
* Attributes are uniquely identified within an item by their name/value combination. For example, a single
* item can have the attributes { “first_name”, “first_value” } and { “first_name”,
* second_value” }. However, it cannot have two attribute instances where both the Attribute.X.Name and
* Attribute.X.Value are the same.
* Optionally, the requestor can supply the Replace parameter for each individual value. Setting this value
* to true will cause the new attribute value to replace the existing attribute value(s). For example, if an
* item has the attributes { ‘a’, ‘1’ }, { ‘b’, ‘2’} and { ‘b’, ‘3’ } and the requestor does a
* PutAttributes of { ‘b’, ‘4’ } with the Replace parameter set to true, the final attributes of the
* item will be { ‘a’, ‘1’ } and { ‘b’, ‘4’ }, replacing the previous values of the ‘b’ attribute
* with the new value.
*
* @param Amazon_SimpleDB_Interface $service instance of Amazon_SimpleDB_Interface
* @param mixed $request Amazon_SimpleDB_Model_PutAttributes or array of parameters
*/
function invokePutAttributes(Amazon_SimpleDB_Interface $service, $request)
{
try {
$response = $service->putAttributes($request);
$domainName = $_GET[‘dom_name’];
header(“Location: SimpleCrud.php?dom_name=$domainName”);

} catch (Amazon_SimpleDB_Exception $ex) {?>
<input type=”button” value=”Reload Page” onClick=”window.location.reload()”>
<?php
echo(“Caught Exception: ” . $ex->getMessage() . “\n”);
echo(“Response Status Code: ” . $ex->getStatusCode() . “\n”);
echo(“Error Code: ” . $ex->getErrorCode() . “\n”);
echo(“Error Type: ” . $ex->getErrorType() . “\n”);
echo(“Request ID: ” . $ex->getRequestId() . “\n”);
echo(“XML: ” . $ex->getXML() . “\n”);
}
}
?>
<html>
<head>
<title>Insert Values into the database—— Amazon Simple DB Test by Sreeraj</title>
</head>
<body>
<h2 style=”color:#FF0000; font-family:Arial, Helvetica, sans-serif;”>Add new Record</h2>
<form method=”post”>
<span style=”font-family:Arial, Helvetica, sans-serif; font-size:14px; color:#006600;”>Name:</span><input type=”text” name=”test_name” id=”test_name” />
<span style=”font-family:Arial, Helvetica, sans-serif; font-size:14px; color:#006600;”>Age:</span><input type=”text” name=”test_age” id=”test_age” /><br />
<input type=”submit” name=”submit” value=”Submit” style=”margin-top:10px;” />
</form>
<a style=”text-decoration:none; font-family:Arial, Helvetica, sans-serif; font-size:12px;” href=”SimpleCrud.php?dom_name=<?php echo $domainName;?>”>[ C R U D ]</a>
</body>
</html>

Now lets see how to edit a value in the domain

1. For this we have to pass the domain name and ID as a get variables.
2. With the ID and the domain we can change the value in the database.

Code for EditPage.php

<?php
/**
* PHP Version 5
*
* @category Amazon
* @package Amazon_SimpleDB
* @copyright Copyright 2008 Amazon Technologies, Inc.
* @link http://aws.amazon.com
* @license http://aws.amazon.com/apache2.0 Apache License, Version 2.0
* @version 2007-11-07
*/
/*******************************************************************************
* __ _ _ ___
* ( )( \/\/ )/ __)
* /__\ \ / \__ \
* (_)(_) \/\/ (___/
*
* Amazon Simple DB PHP5 Library
* Generated: Thu Aug 28 06:20:51 PDT 2008
*
*/

/**
* Get Attributes Sample
*/

include_once (‘.config.inc.php’);

/************************************************************************
* Instantiate Implementation of Amazon SimpleDB
*
* AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY constants
* are defined in the .config.inc.php located in the same
* directory as this sample
***********************************************************************/
$service = new Amazon_SimpleDB_Client(‘1T477KF4HAV4SWT4T982′,
‘622gIa+NcAhJFe2ulJ3XBrd5NRIUb2OhkCTjn5uR’);

/************************************************************************
* Uncomment to try out Mock Service that simulates Amazon_SimpleDB
* responses without calling Amazon_SimpleDB service.
*
* Responses are loaded from local XML files. You can tweak XML files to
* experiment with various outputs during development
*
* XML files available under Amazon/SimpleDB/Mock tree
*
***********************************************************************/
// $service = new Amazon_SimpleDB_Mock();

/************************************************************************
* Setup request parameters and uncomment invoke to try out
* sample for Get Attributes Action
***********************************************************************/
// @TODO: set request. Action can be passed as Amazon_SimpleDB_Model_GetAttributesRequest
// object or array of parameters
require_once (‘Amazon/SimpleDB/Model/GetAttributesRequest.php’);
$request = new Amazon_SimpleDB_Model_GetAttributesRequest();
// Edited By Sreeraj 29/11/08
// print_r($_GET);
$domain = $_GET[‘dom_name’];
$Item = $_GET[‘ItemID’];
$request->setDomainName($domain);
$request->setItemName($Item);
invokeGetAttributes($service, $request);

/**
* Get Attributes Action Sample
* Returns all of the attributes associated with the item. Optionally, the attributes returned can be limited to
* the specified AttributeName parameter.
* If the item does not exist on the replica that was accessed for this operation, an empty attribute is
* returned. The system does not return an error as it cannot guarantee the item does not exist on other
* replicas.
*
* @param Amazon_SimpleDB_Interface $service instance of Amazon_SimpleDB_Interface
* @param mixed $request Amazon_SimpleDB_Model_GetAttributes or array of parameters
*/
function invokeGetAttributes(Amazon_SimpleDB_Interface $service, $request)
{
try {

$response = $service->getAttributes($request);

// echo (“Service Response\n”);
// echo (“=============================================================================\n”);

// echo(” GetAttributesResponse\n”);
if ($response->isSetGetAttributesResult()) {
//echo(” GetAttributesResult<br />”);
$getAttributesResult = $response->getGetAttributesResult();
$attributeList = $getAttributesResult->getAttribute();
$domain = $_GET[‘dom_name’];
$Item = $_GET[‘ItemID’];
?><title>Edit Page</title>
<h2 style=”color:#FF0000; font-family:Arial, Helvetica, sans-serif;”>Edit Page</h2>
<form action=”EditAttributes.php?dom_name=<?php echo $domain;?>&Item=<?php echo $Item;?>” method=”post”>
<table border=”1″ style=”border-collapse:collapse; margin-bottom:20px;” cellpadding=”5″>
<?php foreach ($attributeList as $attribute) {?>

<tr>
<td>
<?php if ($attribute->isSetName())
{?>
<input type=”text” name=”name[]” id=”name” value=”<?php echo($attribute->getName());?>” />
<?php }?>
</td>
<td>
<?php if ($attribute->isSetValue())
{?>
<input type=”text” name=”value[]” id=”value” value=”<?php echo($attribute->getValue());?>” />
<?php }?>
</td>
</tr>
<?php }?>
</table>
<input type=”submit” name=”submit” value=”Update” />
</form>
<?php }
if ($response->isSetResponseMetadata()) {
// echo(” ResponseMetadata\n”);
$responseMetadata = $response->getResponseMetadata();
if ($responseMetadata->isSetRequestId())
{
// echo(” RequestId\n”);
// echo(” ” . $responseMetadata->getRequestId() . “\n”);
}
if ($responseMetadata->isSetBoxUsage())
{
// echo(” BoxUsage\n”);
// echo(” ” . $responseMetadata->getBoxUsage() . “\n”);
}
}

} catch (Amazon_SimpleDB_Exception $ex) {
echo(“Caught Exception: ” . $ex->getMessage() . “\n”);
echo(“Response Status Code: ” . $ex->getStatusCode() . “\n”);
echo(“Error Code: ” . $ex->getErrorCode() . “\n”);
echo(“Error Type: ” . $ex->getErrorType() . “\n”);
echo(“Request ID: ” . $ex->getRequestId() . “\n”);
echo(“XML: ” . $ex->getXML() . “\n”);
}
}
?>
<input type=”button” value=”Back to Previous Page” onClick=”javascript: history.go(-1)”>