Skip to content

Instantly share code, notes, and snippets.

@rahulpnath
Created May 9, 2021 19:46
Show Gist options
  • Save rahulpnath/3a2b175a78f3007490b0541b307b0ac5 to your computer and use it in GitHub Desktop.
Save rahulpnath/3a2b175a78f3007490b0541b307b0ac5 to your computer and use it in GitHub Desktop.
Connect to Local instance of DynamoDB
using System;
using System.Threading.Tasks;
using Amazon.DynamoDBv2;
using Amazon.DynamoDBv2.DataModel;
using Amazon.Runtime;
using ConsoleTables.Core;
namespace dynamodb_local_sample
{
class Program
{
static async Task Main(string[] args)
{
Console.WriteLine("Hello World!");
var creds = new BasicAWSCredentials("fakeMyAccessKeyId", "fakeSecretAccessKe");
var config = new AmazonDynamoDBConfig()
{
ServiceURL = "http://localhost:8002",
AuthenticationRegion = "ap-southeast-2",
};
var client = new AmazonDynamoDBClient(creds, config);
var context = new DynamoDBContext(client);
var newData = new WeatherForecast() {City = "Brisbane", Date = DateTime.Now.ToString()};
// await context.SaveAsync(newData);
var data = await context.ScanAsync<WeatherForecast>(null).GetRemainingAsync();
ConsoleTable.From(data).Write();
Console.Read();
}
}
public class WeatherForecast
{
public string City { get; set; }
public string Date { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment