This Developer Guide contains .NET code snippets and ready-to-run programs. You can find these code samples in the following sections:
The Amazon DynamoDB Getting Started Guide contains additional .NET sample programs.
You can get started quickly by using the AWS SDK for .NET with the Toolkit for Visual Studio.
To Run the .NET Code Samples (using Visual Studio)
Download and install Microsoft Visual Studio.
Download and install the Toolkit for Visual Studio.
Start Visual Studio and choose File, New, and then Project.
In New Project, choose AWS Empty Project, and then choose OK.
In AWS Access Credentials, choose Use existing profile, choose your credentials profile from the list, and then choose OK.
If this is your first time using Toolkit for Visual Studio, choose Use a new profile to set up your AWS credentials.
In your Visual Studio project, choose the tab for your program's source code (
Program.cs). Copy the code sample from the documentation page you are reading into the Visual Studio editor, replacing any other code that you see in the editor.
If you see error messages of the form
The type or namespace name...could not be found, you need to install the AWS SDK assembly for DynamoDB as follows:
In Solution Explorer, open the context (right-click) menu for your project, and then choose Manage NuGet Packages.
In NuGet Package Manager, choose Browse.
In the search box, type
AWSSDK.DynamoDBv2and wait for the search to complete.
Choose AWSSDK.DynamoDBv2, and then choose Install.
When the installation is complete, choose the Program.cs tab to return to your program.
To run the code, choose the Start button in the Visual Studio toolbar.
The AWS SDK for .NET provides thread-safe clients for working with DynamoDB. As a best practice, your applications should create one client and reuse the client between threads.
For more information, go to AWS SDK for .NET.
The code samples in this Developer Guide are intended for use with the latest version of the AWS SDK for .NET.
.NET: Setting Your AWS Credentials
The AWS SDK for .NET requires that you provide AWS credentials to your application at runtime. The code samples in this Developer Guide assume that you are using the SDK Store to manage your AWS credentials file, as described in Using the SDK Store in the AWS SDK for .NET Developer Guide.
The Toolkit for Visual Studio supports multiple sets of credentials from any number of accounts. Each
set is referred to as a profile. Visual Studio adds entries to
App.config file so that your application can find the AWS
credentials at runtime.
The following example shows the default
App.config file that is
generated when you create a new project using Toolkit for Visual Studio:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="AWSProfileName" value="default"/> <add key="AWSRegion" value="us-west-2" /> </appSettings> </configuration>
At runtime, the program uses the
default set of AWS credentials,
as specified by the
AWSProfileName entry. The AWS credentials
themselves are kept in the SDK Store, in encrypted form. The Toolkit for Visual Studio provides a
graphical user interface for managing your credentials, all from within Visual
Studio. For more information, see Specifying Credentials in the
AWS Toolkit for Visual Studio User Guide.
By default, the code samples access DynamoDB in the US West (Oregon)
region. You can change the region by modifying the
in the App.config file. You can set
AWSRegion to any AWS Region
where Amazon DynamoDB is available. For a complete list, see AWS Regions and Endpoints in the
Amazon Web Services General Reference.
.NET: Setting the AWS Region and Endpoint
By default, the code samples access DynamoDB in the US West (Oregon) region.
You can change the region by modifying the
AWSRegion entry in the
App.config file. Alternatively, you can change the region by
The following code snippet instantiates a new
client is modified so that the code runs against DynamoDB in a different region.
AmazonDynamoDBConfig clientConfig = new AmazonDynamoDBConfig(); // This client will access the US East 1 region. clientConfig.RegionEndpoint = RegionEndpoint.USEast1; AmazonDynamoDBClient client = new AmazonDynamoDBClient(clientConfig);
For a complete list of regions, see AWS Regions and Endpoints in the Amazon Web Services General Reference.
If you want to run the code samples using DynamoDB locally on your computer, you need to set the endpoint:
AmazonDynamoDBConfig clientConfig = new AmazonDynamoDBConfig(); // Set the endpoint URL clientConfig.ServiceURL = "http://localhost:8000"; AmazonDynamoDBClient client = new AmazonDynamoDBClient(clientConfig);