AWS Code Sample

The AWS Documentation website is getting a new look!
Try it now and let us know what you think. Switch to the new look >>

You can return to the original look by selecting English in the language selector above.


/** * 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.IO; using System.Text; using Amazon; using Amazon.DynamoDBv2; using Amazon.DynamoDBv2.Model; using Amazon.DynamoDBv2.DocumentModel; namespace DynamoDB_intro { class Program { public static void Main(string[] args) { // 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); PauseForDebugWindow(); return; } // Build a 'CreateTableRequest' for the new table CreateTableRequest createRequest = new CreateTableRequest { TableName = "Movies", AttributeDefinitions = new List<AttributeDefinition>() { new AttributeDefinition { AttributeName = "year", AttributeType = "N" }, new AttributeDefinition { AttributeName = "title", AttributeType = "S" } }, KeySchema = new List<KeySchemaElement>() { new KeySchemaElement { AttributeName = "year", KeyType = "HASH" }, new KeySchemaElement { AttributeName = "title", KeyType = "RANGE" } }, }; // Provisioned-throughput settings are required even though // the local test version of DynamoDB ignores them createRequest.ProvisionedThroughput = new ProvisionedThroughput(1, 1); // Using the DynamoDB client, make a synchronous CreateTable request CreateTableResponse createResponse; try { createResponse = client.CreateTable(createRequest); } catch (Exception ex) { Console.WriteLine("\n Error: failed to create the new table; " + ex.Message); PauseForDebugWindow(); return; } // Report the status of the new table... Console.WriteLine("\n\n Created the \"Movies\" table successfully!\n Status of the new table: '{0}'", createResponse.TableDescription.TableStatus); } 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: