AWS Code Sample


Program.cs demonstrates how to

/** * Copyright 2010-2019, Inc. or its affiliates. All Rights Reserved. * * This file is licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. A copy of * the License is located at * * * * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ using System; using System.Collections.Generic; using System.Linq; using System.Text; using Amazon; using Amazon.DynamoDBv2; using Amazon.DynamoDBv2.Model; using Amazon.DynamoDBv2.DocumentModel; namespace DynamoDB_intro { class Program { static void Main(string[] args) { // Get a Table object for the table that you created in Step 1 Table table = GetTableObject("Movies"); if (table == null) { PauseForDebugWindow(); return; } try { Document document = table.GetItem(2015, "The Big New Movie"); if (document != null) Console.WriteLine("\nGetItem succeeded: \n" + document.ToJsonPretty()); else Console.WriteLine("\nGetItem succeeded, but the item was not found"); } catch (Exception e) { Console.WriteLine(e.Message); } } public static Table GetTableObject(string tableName) { // First, set up a DynamoDB client for DynamoDB Local AmazonDynamoDBConfig ddbConfig = new AmazonDynamoDBConfig(); ddbConfig.ServiceURL = "http://localhost:8000"; AmazonDynamoDBClient client; try { client = new AmazonDynamoDBClient(ddbConfig); } catch (Exception ex) { Console.WriteLine("\n Error: failed to create a DynamoDB client; " + ex.Message); return (null); } // Now, create a Table object for the specified table Table table = null; try { table = Table.LoadTable(client, tableName); } catch (Exception ex) { Console.WriteLine("\n Error: failed to load the 'Movies' table; " + ex.Message); return (null); } return (table); } public static void PauseForDebugWindow() { // Keep the console open if in Debug mode... Console.Write("\n\n ...Press any key to continue"); Console.ReadKey(); Console.WriteLine(); } } }

Sample Details

Service: dynamodb

Last tested:

Author: AWS

Type: full-example

On this page: