Whatever message this page gives is out now! Go check it out!
dynamoObject = getCloudService("dynamoCred", "dynamoConf")component {
this.name="MyApp"
function OnApplicationStart() {
application.DynamoProfile = {
"credentialAlias" : "Alias Name",
"vendorName" : "AWS",
"region" : "Region Name",
"secretAccessKey" : "Access Secret",
"accessKeyId" : "Access Key"
}
application.DynamoCred = {
"serviceName" = "DYNAMODB"
}
}
}dynamoObject = getCloudService(application.DynamoProfile, application.DynamoCred)<cfscript>
// define the credential and the configuration aliases in the ColdFusion Admin
dynamo=getCloudService("dynamoCred","dynamoConf")
// List all DynamoDB tales in the account
listTablesStruct = {
"Limit": 50
}
listTablesResponse =dynamo.ListTables(listTablesStruct);
writeDump(listTablesResponse)
</cfscript><cfscript>
// Using credential alias and struct for service config
dynamoConf = {
"alias":"dynamoConf",
"serviceName" : "DYNAMODB",
"clientOverrideConfig":{
"retryPolicy":{
"numRetries":4
}
},
"httpClientConfig":{
"maxConnections":50
}
}
dynamo = getCloudService("dynamoCred", dynamoConf)
// List all DynamoDB tales in the account
listTablesStruct = {
"Limit": 50
}
listTablesResponse =dynamo.ListTables(listTablesStruct);
writeDump(listTablesResponse)
</cfscript><cfscript>
// Using config alias and struct for service credentials
// dynamo credentials
dynamoCreds={
"vendorName":"AWS",
alias": "dynamoCred",
"region":"us-east-2",
"accessKeyId": "access key",
"secretAccessKey": "secret access"
}
dynamo = getCloudService(dynamoCreds, "dynamoConf")
// List all DynamoDB tales in the account
listTablesStruct = {
"Limit": 50
}
listTablesResponse =dynamo.ListTables(listTablesStruct);
writeDump(listTablesResponse)
</cfscript><cfscript>
// Using Structs for both cloud credential and config
dynamoCred={
"vendorName":"AWS",
"credentialAlias": "dynamoCred",
"region":"us-east-2",
"accessKeyId": "access key",
"secretAccessKey": "secret access key"
}
dynamoConf = {
"alias":"dynamoConf",
"serviceName" : "DYNAMODB",
"clientOverrideConfig":{
"retryPolicy":{
"numRetries":4
}
},
"httpClientConfig":{
"maxConnections":50
}
}
dynamo = getCloudService(dynamoCred, dynamoConf)
// List all DynamoDB tales in the account
listTablesStruct = {
"Limit": 50
}
listTablesResponse =dynamo.ListTables(listTablesStruct);
writeDump(listTablesResponse)
</cfscript><cfscript>
// Create an object of administrator component and call the login method
adminObj = createObject("component","cfide.adminapi.administrator")
adminObj.login("admin")
// Create an object of cloud component
cloudObj = createObject("component","cfide.adminapi.cloud")
// define credentials struct
credentialStruct={
"alias" : "CredDynamo",
"vendorName" : "AWS",
"region" : "us-east-2",
"secretAccessKey" : "secret access key",
"accessKeyId" : "access key"
}
// add credential credentialStruct
try{
cloudObj.addCredential(credentialStruct)
writeOutput("Credentials added successfully")
}
catch(any e){
writeDump(e)
}
</cfscript><cfscript>
// Create an object of administrator component and call the login method
adminObj = createObject("component","cfide.adminapi.administrator")
adminObj.login("admin")
// Create an object of cloud component
cloudObj = createObject("component","cfide.adminapi.cloud")
// define configuration struct
configStruct={
"alias":"ConfDynamo",
"serviceName":"DYNAMODB",
"clientOverrideConfig":{
"retryPolicy":{
"numRetries":4
}
},
"httpClientConfig":{
"maxConnections":50
}
}
// add config configStruct
try{
cloudObj.addServiceConfig(configStruct)
writeOutput("Configuration service added successfully")
}
catch(any e){
writeDump(e)
}
</cfscript>tableName="MusicTableForDemo"
scanStruct = {
"TableName": "#tableName#"
}<cfscript>
dynamo=getCloudService(application.awsCred, application.dynamoConf)
movieName="Movies010"
// Stage 1: create a table
tableStruct={
TableName : "#movieName#",
KeySchema:[
{ AttributeName: "year", KeyType: "HASH"},
{ AttributeName: "title", KeyType: "RANGE"}
],
AttributeDefinitions:[
{ AttributeName: "year", AttributeType: "N" },
{ AttributeName: "title", AttributeType: "S" }
],
ProvisionedThroughput:{
ReadCapacityUnits: 10,
WriteCapacityUnits: 10
}
}
dynamo.createTable(tableStruct)
sleep(3000)
// Stage 2: insert an item into the table
putItemStruct={
"TableName":"#movieName#",
"Item":{
"year": {"N": 2019},
"title": {"S": "Golden"}
},
"ReturnValues": "NONE"
}
try{
putItemResponse=dynamo.putItem(putItemStruct,{"hasType": true})
writeOutput("Item inserted successfully in the table.")
writeDump(putItemResponse)
}
catch (any e){
writeDump(e)
}
</cfscript><cfscript>
// credentials and configuration
dynamo = getCloudService(application.awsCred,application.dynamoConf)
tableName="MusicTableForDemo"
scanStruct = {
"TableName": "#tableName#"
}
scanResponse=dynamo.scan(scanStruct,{"customResponse":true})
arr=scanResponse.items
writeOutput("<b>List of songs</b>" & "")
mapFunction=function(item){
writeOutput(item.SongTitle & "<br/>")
}
arr.map(mapFunction)
</cfscript><cfscript>
// credentials and configuration
dynamo = getCloudService(application.awsCred,application.dynamoConf)
tableName="MusicTableForDemo"
scanStruct = {
"TableName": "#tableName#"
}
scanResponse=dynamo.scan(scanStruct,{"customResponse":true,"binaryFormat":true})
arr=scanResponse.items
writeOutput("<b>List of songs</b>" & "")
mapFunction=function(item){
writeOutput(item.SongTitle & "<br/>")
}
arr.map(mapFunction)
</cfscript>component accessors="true"
{
property string empName;
property numeric age;
property string dept;
}component accessors="true"
{
public function putItemCFC(dynamoObject, itemStruct, hasType, preserveCfc) {
result = dynamoObject.putItem(itemStruct, {"hasType": hasType, "preserveCFC": preserveCfc});
if(result.HttpResponse.StatusCode eq 200) {
writeOutput("Items written successfully<br />");
} else {
writeOutput("Failed to write the items<br />");
writeDump(result)
}
}
}<cfscript>
empData = new Employee({empName="James", age=26, dept="000"});
region1 = "ap-northeast-2";
// credentials and configuration
dynamo = getCloudService(application.awsCred,application.dynamoConf)
tableName = "Table_Test_CFC";
TablePartitionKey = "OrderId";
partitionKeyType = "N";
TableSortKey = "OrderName";
sortKeyType = "S";
MyCFCKey = "OrderCFC";
LocalSecondaryIndexSortKey = "OrderDateTime";
secondaryIndexSortKeyType = "S";
myComponent = createObject("Component", "helper");
try {
myComponent.deleteTable(dynamoUsWest1, tableName)
} catch (any e) {
writeDump(e)
}
try {
myComponent.createTableWithLocalIndex(dynamoUsWest1, tableName, TablePartitionKey, partitionKeyType, TableSortKey, sortKeyType, LocalSecondaryIndexSortKey, secondaryIndexSortKeyType)
sleep(20000);
} catch (any e) {
writeDump(e)
}
orderName = "MyOrder: ";
strct_putItem = {
"TableName": tableName,
"Item":{
"#TablePartitionKey#": 2,
"#TableSortKey#": "MyOrder: 2",
"CUSTOMER_KEY": "0001-23456",
"OrderStatus": "CONFIRMED",
"Year": 2012,
"#LocalSecondaryIndexSortKey#": "2020/04/21",
"#MyCFCKey#": empData
}
}
try {
result = dynamoObject.putItem(itemStruct, {"hasType": false, "preserveCFC": true});
if(result.HttpResponse.StatusCode eq 200) {
writeOutput("Items written successfully<br />");
} else {
writeOutput("Failed to write the items<br />");
writeDump(result)
}
} catch (any e) {
writeDump(e)
}
</cfscript><cfscript>
// credentials and configuration
dynamo = getCloudService(application.awsCred,application.dynamoConf)
posdateresult=DateAdd("s", 30, now())
tableName="MusicTableForDemo"
scanStruct = {
"TableName": "#tableName#"
}
scanResponse=dynamo.scan(scanStruct,{"customResponse":true, cachedWithin: "#createTimeSpan( 0, 0, 0, 30 )#"})
arr=scanResponse.items
writeOutput("<b>List of songs</b>" & "")
mapFunction=function(item){
writeOutput(item.SongTitle & "<br/>")
}
arr.map(mapFunction)
</cfscript><cfscript>
// credentials and configuration
dynamo = getCloudService(application.awsCred,application.dynamoConf)
posdateresult=DateAdd("s", 30, now())
tableName="MusicTableForDemo"
scanStruct = {
"TableName": "#tableName#"
}
scanResponse=dynamo.scan(scanStruct,{"customResponse":true,cachedAfter: posdateresult})
arr=scanResponse.items
writeOutput("<b>List of songs</b>" & "")
mapFunction=function(item){
writeOutput(item.SongTitle & "<br/>")
}
arr.map(mapFunction)
</cfscript><cfscript>
dynamo=getCloudService(application.awsCred, application.dynamoConf)
movieName="Movies010"
// Stage 1: create a table
tableStruct={
TableName : "#movieName#",
KeySchema:[
{ AttributeName: "year", KeyType: "HASH"},
{ AttributeName: "title", KeyType: "RANGE"}
],
AttributeDefinitions:[
{ AttributeName: "year", AttributeType: "N" },
{ AttributeName: "title", AttributeType: "S" }
],
ProvisionedThroughput:{
ReadCapacityUnits: 10,
WriteCapacityUnits: 10
}
}
dynamo.createTable(tableStruct)
sleep(3000)
// Stage 2: insert an item into the table
putItemStruct={
"TableName":"#movieName#",
"Item":{
"year": {"N": 2019},
"title": {"S": "Golden"}
},
"ReturnValues": "NONE"
}
try{
putItemResponse=dynamo.putItem(query = putItemStruct, options = {"hasType": true})
writeOutput("Item inserted successfully in the table.")
writeDump(putItemResponse)
}
catch (any e){
writeDump(e)
}
</cfscript>cfscript>
cred = {
"credentialAlias" : "MyCredential",
"vendorName" : "AWS",
"region" : "us-east-2",
"secretAccessKey" : "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
"accessKeyId" : "XXXXXXXXXXXXXXXXX"
}
config = {
"serviceName" = "DYNAMODB"
};
dynamo = getCloudService(cred, config);
strct = structNew("casesensitive");
strct.TableName = "College"
writedump(strct);
result = dynamo.scan(strct, {} );
writedump(result);
</cfscript>component {
function getLocalSecondaryIndex(partitionKey, sortKey, tableName) {
localSecondaryIndex = [{
"IndexName": "LocalIndex_" & tableName,
"KeySchema": [
{
"AttributeName": partitionKey,
"KeyType": "HASH"
},
{
"AttributeName": sortKey,
"KeyType": "RANGE"
}
],
"Projection": {
"ProjectionType": "KEYS_ONLY"
}
}]
return localSecondaryIndex;
}
function getGlobalSecondaryIndex(partitionKey, sortKey, tableName) {
globalSecondaryIndex = [{
"IndexName": "GlobalIndex_" & tableName,
"KeySchema": [
{
"AttributeName": partitionKey,
"KeyType": "HASH"
},
{
"AttributeName": sortKey,
"KeyType": "RANGE"
}
],
"Projection": {
"ProjectionType": "KEYS_ONLY"
},
"ProvisionedThroughput": {
"ReadCapacityUnits": 10,
"WriteCapacityUnits": 10
}
}]
return globalSecondaryIndex;
}
function getCreateTableStruct(tableName, partitionKeyName, partitionKeyType, sortKeyName, sortKeyType) {
createTable = {
"TableName": tableName,
"KeySchema": [
{
"AttributeName": partitionKeyName,
"KeyType": "HASH"
},
{
"AttributeName": sortKeyName,
"KeyType": "RANGE"
}
],
"AttributeDefinitions": [
{
"AttributeName": partitionKeyName,
"AttributeType": partitionKeyType
},
{
"AttributeName": sortKeyName,
"AttributeType": sortKeyType
}
],
"ProvisionedThroughput": {
"ReadCapacityUnits": 10,
"WriteCapacityUnits": 10
},
"StreamSpecification": {
"StreamEnabled": true,
"StreamViewType": "NEW_AND_OLD_IMAGES"
}
}
return createTable;
}
public function createTable(dynamoObject, tableName, partitionKeyName, partitionKeyType, sortKeyName, sortKeyType) {
createTable = getCreateTableStruct(tableName, partitionKeyName, partitionKeyType, sortKeyName, sortKeyType);
try {
result = dynamoObject.createTable(createTable);
if(result.HttpResponse.StatusCode eq 200) {
writeOutput("Creating the table<br />");
} else {
writeOutput("Failed to create the table<br />");
}
} catch (any e) {
writeDump(e)
}
}
public function createTableWithLocalIndex(dynamoObject, tableName, partitionKeyName, partitionKeyType, sortKeyName, sortKeyType, localSortKey, localSortKeyType) {
createTable = getCreateTableStruct(tableName, partitionKeyName, partitionKeyType, sortKeyName, sortKeyType);
localIndex = getLocalSecondaryIndex(partitionKeyName, localSortKey, tableName)
structInsert(createTable, "LocalSecondaryIndexes", localIndex);
attributeDefinitionArray = structFind(createTable, "AttributeDefinitions")
myStruct = structNew();
myStruct["AttributeName"] = localSortKey;
myStruct["AttributeType"] = localSortKeyType;
arrayAppend(attributeDefinitionArray, myStruct)
structUpdate(createTable, "AttributeDefinitions", attributeDefinitionArray);
try {
result = dynamoObject.createTable(createTable);
if(result.HttpResponse.StatusCode eq 200) {
writeOutput("Creating the table<br />");
} else {
writeOutput("Failed to create the table<br />");
}
} catch (any e) {
writeDump(e)
}
}
public function createTableWithGlobalIndex(dynamoObject, tableName, partitionKeyName, partitionKeyType, sortKeyName, sortKeyType, globalPartitionKey, globalPartitionKeyType, globalSortKey, globalSortKeyType) {
createTable = getCreateTableStruct(tableName, partitionKeyName, partitionKeyType, sortKeyName, sortKeyType);
globalIndex = getGlobalSecondaryIndex(globalPartitionKey, globalSortKey, tableName)
structInsert(createTable, "GlobalSecondaryIndexes", globalIndex);
attributeDefinitionArray = structFind(createTable, "AttributeDefinitions")
myStruct = structNew();
myStruct["AttributeName"] = globalPartitionKey;
myStruct["AttributeType"] = globalPartitionKeyType;
arrayAppend(attributeDefinitionArray, myStruct)
myStruct1 = structNew();
myStruct1["AttributeName"] = globalSortKey;
myStruct1["AttributeType"] = globalSortKeyType;
arrayAppend(attributeDefinitionArray, myStruct1)
structUpdate(createTable, "AttributeDefinitions", attributeDefinitionArray);
try {
result = dynamoObject.createTable(createTable);
if(result.HttpResponse.StatusCode eq 200) {
writeOutput("Creating the table<br />");
} else {
writeOutput("Failed to create the table<br />");
}
} catch (any e) {
writeDump(e)
}
}
public function deleteTable(dynamoObject, tableName) {
deleteTable = {
TableName: tableName
}
try {
result = dynamoObject.deleteTable(deleteTable);
if(result.HttpResponse.StatusCode eq 200) {
writeOutput("Deleting the table<br />");
}
} catch (any e) {
if(e.ExceptionDetails.ExceptionCode eq "ResourceNotFoundException") {
writeOutput("Deleting the table<br />");
} else {
writeOutput("Failed to delete the table<br />");
writeDump(e)
}
}
}
public function createGlobalTable(dynamoObject, tableName, replicaRegion1, replicaRegion2) {
createGlobalTable = {
"GlobalTableName": tableName,
"ReplicationGroup": [
{
"RegionName": replicaRegion1
},
{
"RegionName": replicaRegion2
}
]
}
public function putItem(dynamoObject, itemStruct, hasType) {
result = dynamoObject.putItem(itemStruct, {"hasType": hasType});
if(result.HttpResponse.StatusCode eq 200) {
writeOutput("Items written successfully<br />");
} else {
writeOutput("Failed to write the items<br />");
writeDump(result)
}
}
}<cfscript>
region1 = "us-west-1";
cred_west1 = {
"alias" : "alias",
"vendorName" : "AWS",
"region" : region1,
"secretAccessKey" : "secret access key",
"accessKeyId" : "access key"
}
config = {
"serviceName" = "DYNAMODB"
};
dynamoUsWest1 = getCloudService(cred_west1, config);
tableName = "Table_Cache_GetItem_1";
TablePartitionKey = "OrderId";
partitionKeyType = "N";
TableSortKey = "OrderName";
sortKeyType = "S";
LocalSecondaryIndexSortKey = "OrderDateTime";
secondaryIndexSortKeyType = "S";
myComponent = createObject("Component", "helperFunctions");
try {
myComponent.deleteTable(dynamoUsWest1, tableName)
} catch (any e) {
writeDump(e)
}
try {
myComponent.createTableWithLocalIndex(dynamoUsWest1, tableName, TablePartitionKey, partitionKeyType, TableSortKey, sortKeyType, LocalSecondaryIndexSortKey, secondaryIndexSortKeyType)
sleep(20000);
} catch (any e) {
writeDump(e)
}
orderName = "MyOrder: ";
strct_putItem = {
"TableName": tableName,
"Item":{
"#TablePartitionKey#": 2,
"#TableSortKey#": "MyOrder: ",
"CUSTOMER_KEY": "0001-23456",
"OrderStatus": "CONFIRMED",
"Year": 2012,
"#LocalSecondaryIndexSortKey#": "2020/04/21"
}
}
for(i = 1; i < 5; i++) {
structUpdate(strct_putItem.Item, "#TablePartitionKey#", i);
structUpdate(strct_putItem.Item, "#TableSortKey#", orderName & i);
myComponent.putItem(dynamoUsWest1, strct_putItem, "false")
sleep(10000)
}
strct_getItem = {
"TableName": tableName,
"Key": {
"#TablePartitionKey#": 2,
"#TableSortKey#": "MyOrder: 2"
},
"ExpressionAttributeNames": {
"##Yr": "Year"
},
"ProjectionExpression": "#TablePartitionKey#, ##Yr, OrderStatus",
"ConsistentRead": false,
"ReturnConsumedCapacity": "INDEXES"
}
try {
result = dynamoUsWest1.getItem(strct_getItem, {CustomResponse: true, cachedWithin: "#createTimeSpan( 0, 0, 0, 45 )#"});
if(
(result.ConsumedCapacity.CapacityUnits == 0.5) &&
(!structKeyExists(result.Item, "CUSTOMER_KEY")) &&
(result.Item.OrderId == 2) &&
(result.Item.Year == 2012) &&
(structKeyExists(result.ConsumedCapacity, "Table"))
) {
writeOutput("SUCCESS<br />");
} else {
writeOutput("FAIL<br />");
}
} catch (any e) {
writeDump(e);
}
strct_putItem = {
"TableName": tableName,
"Item":{
"#TablePartitionKey#": 2,
"#TableSortKey#": "MyOrder: 2",
"CUSTOMER_KEY": "0001-23456",
"OrderStatus": "CONFIRMED",
"Year": 2020,
"#LocalSecondaryIndexSortKey#": "2020/04/21"
}
}
myComponent.putItem(dynamoUsWest1, strct_putItem, "false")
sleep(10000)
try {
result = dynamoUsWest1.getItem(strct_getItem, {CustomResponse: true, cachedWithin: "#createTimeSpan( 0, 0, 0, 45 )#"});
if(
(result.ConsumedCapacity.CapacityUnits == 0.5) &&
(!structKeyExists(result.Item, "CUSTOMER_KEY")) &&
(result.Item.OrderId == 2) &&
(result.Item.Year == 2012) &&
(structKeyExists(result.ConsumedCapacity, "Table"))
) {
writeOutput("SUCCESS<br />");
} else {
writeOutput("FAIL<br />");
}
} catch (any e) {
writeDump(e);
}
sleep(36000)
try {
result = dynamoUsWest1.getItem(strct_getItem, {CustomResponse: true, cachedWithin: "#createTimeSpan( 0, 0, 0, 45 )#"});
if(
(result.ConsumedCapacity.CapacityUnits == 0.5) &&
(!structKeyExists(result.Item, "CUSTOMER_KEY")) &&
(result.Item.OrderId == 2) &&
(result.Item.Year == 2020) &&
(structKeyExists(result.ConsumedCapacity, "Table"))
) {
writeOutput("SUCCESS<br />");
} else {
writeOutput("FAIL<br />");
}
} catch (any e) {
writeDump(e);
}
try {
myComponent.deleteTable(dynamoUsWest1, tableName)
} catch (any e) {
writeDump(e)
}
</cfscript><cfscript>
cred = {
"credentialAlias" : "alias",
"vendorName" : "AWS",
"region" : "us-east-2",
"secretAccessKey" : "secret access",
"accessKeyId" : "access key"
}
config = {
"serviceName" = "DYNAMODB"
}
dynamo = getCloudService(cred, config)
createTableStruct={
TableName:"MusicForMe",
AttributeDefinitions:[
{AttributeName:"Artist",AttributeType:"S"},
{AttributeName:"SongTitle",AttributeType:"S"}
],
KeySchema:[
{AttributeName:"Artist",KeyType:"HASH"},
{AttributeName:"SongTitle",KeyType:"RANGE"}
],
ProvisionedThroughput:{
ReadCapacityUnits: 10,
WriteCapacityUnits: 10
}
}
try{
createTableResponse=dynamo.createTable(createTableStruct,{"customResponse": true})
writeOutput("Table created successfully")
writeDump(createTableResponse)
}
catch(any e){
writeDump(e)
}
</cfscript><cfscript>
cred = {
"credentialAlias" : "alias",
"vendorName" : "AWS",
"region" : "us-east-2",
"secretAccessKey" : "secret access",
"accessKeyId" : "access key"
}
config = {
"serviceName" = "DYNAMODB"
}
dynamo = getCloudService(cred, config)
// let's retrieve information about the table "MusicForMe"
if (ArrayContains(listTablesResponse.TableNames,"MusicForMe")){
describeTableStruct={
"TableName":"YearlyProductCatalog"
}
describeTableResponse=dynamo.describeTable(describeTableStruct)
writeDump(describeTableResponse)
}
else{
writeOutput("Table not found")
}
</cfscript><cfscript>
cred = {
"credentialAlias" : "alias",
"vendorName" : "AWS",
"region" : "us-east-2",
"secretAccessKey" : "secret access",
"accessKeyId" : "access key"
}
config = {
"serviceName" = "DYNAMODB"
}
dynamo = getCloudService(cred, config)
tableName="MusicForMe"
oldReadCapacityUnits=10
oldWriteCapacityUnits=10
newReadCapacityUnits=50
newWriteCapacityUnits=50
updateTableStruct={
"TableName": "#tableName#",
"ProvisionedThroughput": {
"ReadCapacityUnits": "#newReadCapacityUnits#",
"WriteCapacityUnits": "#newWriteCapacityUnits#"
}
}
try{
updateTableResponse=dynamo.updateTable(updateTableStruct)
if(
(updateTableResponse.HttpResponse.StatusCode==200) and
(updateTableResponse.TableDescription.ProvisionedThroughput.ReadCapacityUnits==oldReadCapacityUnits) and
(updateTableResponse.TableDescription.ProvisionedThroughput.WriteCapacityUnits==oldWriteCapacityUnits) and
(updateTableResponse.TableDescription.TableStatus=="UPDATING")
)
{
writeOutput("Old read and write values correct.")
}
else {
writeOutput("Old read and write values incorrect.")
}
}
catch(any e){
writeDump(e)
}
</cfscript><cfscript>
cred = {
"credentialAlias" : "alias",
"vendorName" : "AWS",
"region" : "us-east-2",
"secretAccessKey" : "secret access",
"accessKeyId" : "access key"
}
config = {
"serviceName" = "DYNAMODB"
}
dynamo = getCloudService(cred, config)
tableName="MusicForMe"
// delete the table
deleteTableStruct={
"TableName": "#tableName#"
}
try{
deleteResponse=dynamo.deleteTable(deleteTableStruct)
writeOutput("Table deleted successfully")
writeDump(deleteResponse)
}
catch (any e){
writeOutput("Unable to delete the table")
writeDump(e)
}
</cfscript><cfscript>
cred={
"credentialAlias" : "alias",
"vendorName" : "AWS",
"region" : "us-east-2",
"secretAccessKey" : "secret access",
"accessKeyId" : "access key"
}
conf={
"serviceName"="DYNAMODB"
}
dynamo=getCloudService(cred, conf)
params = {
"Limit": 50
}
result = dynamo.ListTables(params);
writeDump(result)
</cfscript><cfscript>
cred={
"credentialAlias" : "alias",
"vendorName" : "AWS",
"region" : "us-east-2",
"secretAccessKey" : "secret access",
"accessKeyId" : "access key"
}
conf={
"serviceName"="DYNAMODB"
}
dynamo=getCloudService(cred, conf)
tableName="NewProductCatalog"
// Stage 1: Create a table
createTableStruct={
"TableName": "#tableName#",
"KeySchema": [
{
"AttributeName": "id",
"KeyType": "HASH"
}
],
"AttributeDefinitions": [
{
"AttributeName": "id",
"AttributeType": "N"
}
],
"ProvisionedThroughput": {
"ReadCapacityUnits": 10,
"WriteCapacityUnits": 10
}
}
dynamo.createTable(createTableStruct)
sleep(20000)
// Stage 2: Insert an item
putItemStruct = {
"TableName": "#tableName#",
"Item":{
"id": {
"N": 250
},
"Title": {
"S": "Hamlet"
},
"Price": {
"N": "20"
}
},
"ReturnValues": "ALL_OLD"
}
try{
putItemResponse=dynamo.putItem(putItemStruct,{"hasType": true})
writeOutput("Item inserted successfully")
writeDump(putItemResponse)
}
catch (any e){
writeDump(e)
}
</cfscript><cfscript>
cred={
"credentialAlias" : "alias",
"vendorName" : "AWS",
"region" : "us-east-2",
"secretAccessKey" : "secret access",
"accessKeyId" : "access key"
}
conf={
"serviceName"="DYNAMODB"
}
dynamo=getCloudService(cred, conf)
tableName="NewProductCatalog"
// update the item that was inserted
updateItemStruct={
"TableName": "#tableName#",
"Key": {
"id": {
"N": 250
}
},
"UpdateExpression": "set Title = :val1",
"ConditionExpression": "Price = :val2",
"ExpressionAttributeValues": {
":val1": {"S": "Macbeth"},
":val2": {"N": "200"}
},
"ReturnValues": "ALL_NEW"
}
try{
result = dynamo.updateItem(updateItemStruct, {"hasType": true})
if(result.Attributes.Title.S == "Hamlet") {
writeOutput("Title changed successfully<br/>")
} else {
writeOutput("Failed to change the title<br/>")
}
}
catch (any e){
writeDump(e)
}
</cfscript><cfscript>
cred = {
"credentialAlias" : "alias",
"vendorName" : "AWS",
"region" : "us-east-2",
"secretAccessKey" : "secret access",
"accessKeyId" : "access key"
}
config = {
"serviceName" = "DYNAMODB"
}
dynamo = getCloudService(cred, config)
tableName="YearlyProductCatalog"
// items to delete
id=550
title="hamlet"
// delete the item in the table
deleteItemStruct={
"TableName":"#tableName#",
"Key":{
"id":{"N":"#id#"},
"title":{"S":"#title#"}
},
"ReturnValues": "ALL_OLD"
}
try{
deleteItemResponse=dynamo.deleteItem(deleteItemStruct,{"hasType": true})
writeOutput("Item deleted successfully")
writeDump(deleteItemResponse)
}
catch(any e){
writeDump(e)
}
</cfscript><cfscript>
cred={
"credentialAlias" : "alias",
"vendorName" : "AWS",
"region" : "us-east-2",
"secretAccessKey" : "secret access",
"accessKeyId" : "access key"
}
conf={
"serviceName"="DYNAMODB"
}
dynamo=getCloudService(cred, conf)
// create a table
tableName="MusicForAll"
createTableStruct={
TableName:"#tableName#",
AttributeDefinitions:[
{AttributeName:"Artist",AttributeType:"S"},
{AttributeName:"SongTitle",AttributeType:"S"}
],
KeySchema:[
{AttributeName:"Artist",KeyType:"HASH"},
{AttributeName:"SongTitle",KeyType:"RANGE"}
],
ProvisionedThroughput:{
ReadCapacityUnits: 10,
WriteCapacityUnits: 10
}
}
try{
createTableResponse=dynamo.createTable(createTableStruct,{"customResponse": true})
writeOutput("Table created successfully")
writeDump(createTableResponse)
}
catch(any e){
writeDump(e)
}
// insert an item to the table
putItemStruct = {
"TableName": "#tableName#",
"Item":{
"Artist":{"S":"Beatles"},
"SongTitle":{"S":"Yesterday"},
"Album":{"S":"Some album"}
},
"ReturnValues":"NONE"
}
try{
putItemResponse=dynamo.putItem(putItemStruct,{"hasType": true})
writeOutput("Item inserted successfully in the table.")
writeDump(putItemResponse)
}
catch (any e){
writeDump(e)
}
// get the item that was inserted
getItemStruct={
"TableName": "#tableName#",
"Key":{
"Artist":{"S":"Beatles"}
}
}
try{
getItemResponse=dynamo.putItem(getItemStruct)
writeOutput("Item retrieved successfully in the table.")
writeDump(putItemResponse)
}
catch (any e){
writeDump(e)
}
</cfscript><cfscript>
cred={
"credentialAlias" : "alias",
"vendorName" : "AWS",
"region" : "us-east-2",
"secretAccessKey" : "secret access",
"accessKeyId" : "access key"
}
conf={
"serviceName"="DYNAMODB"
}
dynamo=getCloudService(cred, conf)
tableName="MusicForAll"
// update the item in the table
updateItemStruct={
"TableName":"#tableName#",
"Key":{
"Artist":{"S":"Beatles"},
"SongTitle":{"S":"Yesterday"}
},
"UpdateExpression": "SET Album = :newval",
"ExpressionAttributeValues":{
":newval": {"S": "Some other title"}
},
"ReturnValues": "ALL_NEW"
}
try{
updateItemResponse=dynamo.updateItem(updateItemStruct,{"hasType":true,"customResponse":true})
writeDump(updateItemResponse)
}
catch(any e){
writeDump(e)
}
</cfscript>