ambakshi
9/10/2014 - 5:49 AM

Accessing sdb from the awscli

Accessing sdb from the awscli

$ aws configure set preview.sdb true
$ aws sdb create-domain skv
$ aws sdb put-attributes --domain-name skv --item-name ami_idx --attributes Name=app-mwios-asg,Value=1
$ aws sdb put-attributes --domain-name skv --item-name ami_idx --attributes Name=app-ccand-asg,Value=5

$ aws sdb get-attributes --domain-name skv --item-name ami_idx --attribute-names app-mwios-asg
{
"Attributes": [
    {
        "Name": "app-mwios-asg",
        "Value": "1"
    }
]
}

$ aws sdb get-attributes --domain-name skv --item-name ami_idx
{
"Attributes": [
    {
        "Name": "app-mwios-asg",
        "Value": "1"
    },
    {
        "Name": "app-ccand-asg",
        "Value": "5"
    }
]
}

# Atomically increment a number via CAS (compare and swap)
$ VAL=$(aws sdb get-attributes --domain-name skv --item-name ami_idx --attribute-names app-mwios-asg --query 'Attributes[*].Value' --output text)
$ NEWVAL=$(( $VAL + 1 ))
$ aws sdb put-attributes --domain-name skv --item-name ami_idx --attributes Name=app-mwios-asg,Value=$NEWVAL --expected Name=app-mwios-asg,Value=$VAL,Exists=true