/// <summary> /// Get item using Amazon Dynamo Accelerator (DAX), to use this function, you have to install the lambda at the /// same VPC as DAX, then you could access to the Lambda using EC2 instance /// </summary> /// <param name="contractId"></param> /// <returns></returns> public Dictionary <string, AttributeValue> GetDAX(string contractId) { DaxClientConfig config = new DaxClientConfig("assetcluster.ofc1zu.clustercfg.dax.usw2.cache.amazonaws.com", 8111); ClusterDaxClient client = new ClusterDaxClient(config); GetItemRequest request = new GetItemRequest() { TableName = AssetTableName, Key = new Dictionary <string, AttributeValue>() { { "ContractId", new AttributeValue() { S = contractId } } } }; var result = client.GetItemAsync(request); result.Wait(); if (result.IsCompletedSuccessfully) { return(result.Result.Item); } throw new Exception("Error reading asset table", result.Exception); }
public static async Task Main(string[] args) { string endpointUri = args[0]; Console.WriteLine($"Using DAX client - endpointUri={endpointUri}"); var clientConfig = new DaxClientConfig(endpointUri) { AwsCredentials = FallbackCredentialsFactory.GetCredentials() }; var client = new ClusterDaxClient(clientConfig); var tableName = "TryDaxTable"; var pk = 1; var sk = 10; var iterations = 5; var startTime = System.DateTime.Now; for (var i = 0; i < iterations; i++) { for (var ipk = 1; ipk <= pk; ipk++) { for (var isk = 1; isk <= sk; isk++) { var request = new GetItemRequest() { TableName = tableName, Key = new Dictionary <string, AttributeValue>() { { "pk", new AttributeValue { N = ipk.ToString() } }, { "sk", new AttributeValue { N = isk.ToString() } } } }; var response = await client.GetItemAsync(request); Console.WriteLine($"GetItem succeeded for pk: {ipk},sk: {isk}"); } } } var endTime = DateTime.Now; TimeSpan timeSpan = endTime - startTime; Console.WriteLine($"Total time: {timeSpan.TotalMilliseconds} milliseconds"); Console.WriteLine("Hit <enter> to continue..."); Console.ReadLine(); }
public static async Task Main(string[] args) { string endpointUri = args[0]; Console.WriteLine($"Using DAX client - endpointUri={endpointUri}"); var clientConfig = new DaxClientConfig(endpointUri) { AwsCredentials = FallbackCredentialsFactory.GetCredentials() }; var client = new ClusterDaxClient(clientConfig); var tableName = "TryDaxTable"; var pk = 5; var sk1 = 2; var sk2 = 9; var iterations = 5; var startTime = DateTime.Now; for (var i = 0; i < iterations; i++) { var request = new QueryRequest() { TableName = tableName, KeyConditionExpression = "pk = :pkval and sk between :skval1 and :skval2", ExpressionAttributeValues = new Dictionary <string, AttributeValue>() { { ":pkval", new AttributeValue { N = pk.ToString() } }, { ":skval1", new AttributeValue { N = sk1.ToString() } }, { ":skval2", new AttributeValue { N = sk2.ToString() } } } }; var response = await client.QueryAsync(request); Console.WriteLine($"{i}: Query succeeded"); } var endTime = DateTime.Now; TimeSpan timeSpan = endTime - startTime; Console.WriteLine($"Total time: {timeSpan.TotalMilliseconds} milliseconds"); Console.WriteLine("Hit <enter> to continue..."); Console.ReadLine(); }
static void Main(string[] args) { String hostName = args[0].Split(':')[0]; int port = Int32.Parse(args[0].Split(':')[1]); Console.WriteLine("Using DAX client - hostname=" + hostName + ", port=" + port); var clientConfig = new DaxClientConfig(hostName, port) { AwsCredentials = FallbackCredentialsFactory.GetCredentials() }; var client = new ClusterDaxClient(clientConfig); var tableName = "TryDaxTable"; var pk = 1; var sk = 10; var iterations = 5; var startTime = DateTime.Now; for (var i = 0; i < iterations; i++) { for (var ipk = 1; ipk <= pk; ipk++) { for (var isk = 1; isk <= sk; isk++) { var request = new GetItemRequest() { TableName = tableName, Key = new Dictionary <string, AttributeValue>() { { "pk", new AttributeValue { N = ipk.ToString() } }, { "sk", new AttributeValue { N = isk.ToString() } } } }; var response = client.GetItemAsync(request).Result; Console.WriteLine("GetItem succeeded for pk: " + ipk + ", sk: " + isk); } } } var endTime = DateTime.Now; TimeSpan timeSpan = endTime - startTime; Console.WriteLine("Total time: " + (int)timeSpan.TotalMilliseconds + " milliseconds"); Console.WriteLine("Hit <enter> to continue..."); Console.ReadLine(); }
static void Main(string[] args) { String hostName = args[0].Split(':')[0]; int port = Int32.Parse(args[0].Split(':')[1]); Console.WriteLine("Using DAX client - hostname=" + hostName + ", port=" + port); var clientConfig = new DaxClientConfig(hostName, port) { AwsCredentials = FallbackCredentialsFactory.GetCredentials() }; var client = new ClusterDaxClient(clientConfig); var tableName = "TryDaxTable"; var pk = 5; var sk1 = 2; var sk2 = 9; var iterations = 5; var startTime = DateTime.Now; for (var i = 0; i < iterations; i++) { var request = new QueryRequest() { TableName = tableName, KeyConditionExpression = "pk = :pkval and sk between :skval1 and :skval2", ExpressionAttributeValues = new Dictionary <string, AttributeValue>() { { ":pkval", new AttributeValue { N = pk.ToString() } }, { ":skval1", new AttributeValue { N = sk1.ToString() } }, { ":skval2", new AttributeValue { N = sk2.ToString() } } } }; var response = client.QueryAsync(request).Result; Console.WriteLine(i + ": Query succeeded"); } var endTime = DateTime.Now; TimeSpan timeSpan = endTime - startTime; Console.WriteLine("Total time: " + (int)timeSpan.TotalMilliseconds + " milliseconds"); Console.WriteLine("Hit <enter> to continue..."); Console.ReadLine(); }
static void Main(string[] args) { String hostName = args[0].Split(':')[0]; int port = Int32.Parse(args[0].Split(':')[1]); Console.WriteLine("Using DAX client - hostname=" + hostName + ", port=" + port); var clientConfig = new DaxClientConfig(hostName, port) { AwsCredentials = FallbackCredentialsFactory.GetCredentials( }; var client = new ClusterDaxClient(clientConfig); var tableName = "TryDaxTable"; var iterations = 5; var startTime = DateTime.Now; for (var i = 0; i < iterations; i++) { var request = new ScanRequest() { TableName = tableName }; var response = client.ScanAsync(request).Result; Console.WriteLine(i + ": Scan succeeded"); } var endTime = DateTime.Now; TimeSpan timeSpan = endTime - startTime; Console.WriteLine("Total time: " + (int)timeSpan.TotalMilliseconds + " milliseconds"); Console.WriteLine("Hit <enter> to continue..."); Console.ReadLine(); } }
public static async Task Main(string[] args) { string endpointUri = args[0]; Console.WriteLine($"Using DAX client - endpointUri={endpointUri}"); var clientConfig = new DaxClientConfig(endpointUri) { AwsCredentials = FallbackCredentialsFactory.GetCredentials() }; var client = new ClusterDaxClient(clientConfig); var tableName = "TryDaxTable"; var iterations = 5; var startTime = DateTime.Now; for (var i = 0; i < iterations; i++) { var request = new ScanRequest() { TableName = tableName }; var response = await client.ScanAsync(request); Console.WriteLine($"{i}: Scan succeeded"); } var endTime = DateTime.Now; TimeSpan timeSpan = endTime - startTime; Console.WriteLine($"Total time: {timeSpan.TotalMilliseconds} milliseconds"); Console.WriteLine("Hit <enter> to continue..."); Console.ReadLine(); }