Replacing an Attribute

In the previous section, all Year values were deleted from the Item_03. This section provides examples of how to replace the value of an attribute for an item.

The following sample code snippets demonstrate writing the value Medium to the Size attribute of Item_03, overwriting all existing values.

Java

To run the sample

  1. Open a clean copy of PutAttributesSample.java.

  2. Remove any comment marks from the invokePutAttributes(service, request); line and add the following lines after // @TODO: set request parameters here:

    String domainName = "MyStore";
    String itemName = "Item_03";
    ReplaceableAttribute attribute = new ReplaceableAttribute("Size", "Medium", true);
    
    PutAttributes request = (new PutAttributes()).withDomainName(domainName).withItemName(itemName).withAttribute(attribute);
    
  3. Compile and run the sample.

    Amazon SimpleDB writes the value Medium to the Size attribute of Item_03, overwriting all existing values.

To verify whether the attribute is updated, see Getting the Attributes of an Item.

C#

To run the sample

  1. Open AmazonSimpleDBSamples.cs.

  2. Comment out the code you added in the previous section.

  3. Add the following to the Put Attributes Action section:

    ReplaceableAttribute replaceableAttribute = new ReplaceableAttribute().WithName("Size").WithValue("Medium").WithReplace(true);
    PutAttributes replaceAction = new PutAttributes().WithDomainName("MyStore").WithItemName("Item_03").WithAttribute(replaceableAttribute);
    
    PutAttributesSample.InvokePutAttributes(service, replaceAction);
    
  4. Run the sample.

    Amazon SimpleDB writes the value Medium to the Size attribute of Item_03, overwriting all existing values.

To verify whether the attribute is updated, see Getting the Attributes of an Item.

Perl

To run the sample

  1. Open a clean copy of PutAttributesSample.pl.

  2. Remove any comment marks from the invokePutAttributes($service, $request); line and add the following lines after the // @TODO: set request line:

    my $request = Amazon::SimpleDB::Model::PutAttributes->new({
    ItemName => "Item_03",
    DomainName=> "MyStore",
    Attribute => [
    {
    Name => "Size",
    Value => "Medium",
    Replace => 1
    }
    ],
    });
     
  3. Run the sample.

    Amazon SimpleDB writes the value Medium to the Size attribute of Item_03, overwriting all existing values.

To verify whether the attribute is updated, see Getting the Attributes of an Item.

PHP

To run the sample

  1. Open a clean copy of PutAttributesSample.php.

  2. Remove any comment marks from the invokePutAttributes($service, $request); line and add the following lines after the // @TODO: set request line:

    require_once ('Amazon/SimpleDB/Model/ReplaceableAttribute.php');
    
    $attribute = new Amazon_SimpleDB_Model_ReplaceableAttribute();
    $attribute->withName('Size')->withValue('Medium')->withReplace(true);
    
    $request = new Amazon_SimpleDB_Model_PutAttributes();
    $request->withDomainName('MyStore')->withItemName('Item_03')->withAttribute($attribute);
    
  3. Run the sample.

    Amazon SimpleDB writes the value Medium to the Size attribute of Item_03, overwriting all existing values.

To verify whether the attribute is updated, see Getting the Attributes of an Item.

VB.NET

To run the sample

  1. Open AmazonSimpleDBSamples.vb.

  2. Comment out the code you added in the previous section.

  3. Add the following to the Put Attributes Action section:

    Dim replaceableAttribute As New ReplaceableAttribute
    replaceableAttribute.WithName("Size").WithValue("Medium").WithReplace(True)
    
    Dim replaceAttributeAction As New PutAttributes()
    replaceAttributeAction.WithDomainName("MyStore").WithItemName("Item_03").WithAttribute(replaceableAttribute)
    
    PutAttributesSample.InvokePutAttributes(service, replaceAttributeAction)
    
  4. Run the sample.

    Amazon SimpleDB writes the value Medium to the Size attribute of Item_03, overwriting all existing values.

To verify whether the attribute is updated, see Getting the Attributes of an Item.

Scratchpad

To run the sample

  1. Open the scratchpad application with a web browser.

  2. Select PutAttributes from the Explore API list box.

  3. Enter MyStore in the Domain Name field.

  4. Enter Item_03 in the Item Name field.

  5. Enter Size in the Name field.

  6. Enter Medium in the Value field.

  7. Enter true in the Replace field.

  8. Select from the following:

    • To invoke the request, click Invoke Request.

      Amazon SimpleDB writes the value Medium to the Size attribute of Item_03, overwriting all existing values.

    • To view the signed URL, click Display Signed URL. Then, copy and paste the signed URL into a browser.

      Amazon SimpleDB writes the value Medium to the Size attribute of Item_03, overwriting all existing values.

    • To view the string to sign, click Display String to Sign.