private static void ConfigureDbContext(IServiceCollection services) { //Dynamo DB var tableName = Environment.GetEnvironmentVariable("AUDIT_TABLE_NAME"); LambdaLogger.Log($"Dynamo table name {tableName}"); var dynamoConfig = new AmazonDynamoDBConfig { RegionEndpoint = RegionEndpoint.EUWest2 }; var dynamoDbClient = new DynamoDBClient(dynamoConfig); // Set the endpoint URL var env = Environment.GetEnvironmentVariable("ENV"); if (env.ToUpper(CultureInfo.CurrentCulture) == "local") { dynamoConfig.ServiceURL = "http://localhost:8000"; } else { dynamoConfig.RegionEndpoint = RegionEndpoint.EUWest2; } LambdaLogger.Log(string.Format("ServiceURL-{0}, Region-{1}, Table-{2}", dynamoDbClient.Client.Config.DetermineServiceURL(), dynamoDbClient.Client.Config.RegionEndpoint, tableName)); services.AddTransient <IDynamoDBHandler>(sp => new DynamoDBHandler(tableName, dynamoDbClient)); }
public async Task CreateChangeTableForApp(Guid appId) { await DynamoDBClient.CreateTableAsync( GetChangeTableName(appId), new List <KeySchemaElement>() { new KeySchemaElement() { KeyType = KeyType.HASH, AttributeName = nameof(Change.Group), }, new KeySchemaElement() { KeyType = KeyType.RANGE, AttributeName = nameof(Change.Tidemark), } }, new List <AttributeDefinition>() { new AttributeDefinition() { AttributeName = nameof(Change.Group), AttributeType = ScalarAttributeType.S, }, new AttributeDefinition() { AttributeName = nameof(Change.Tidemark), AttributeType = ScalarAttributeType.N, } }, new ProvisionedThroughput() { ReadCapacityUnits = 1, WriteCapacityUnits = 1 }); }
public void PutItem3() { var cliente = new DynamoDBClient(); Parallel.For(0, 1000, new ParallelOptions() { MaxDegreeOfParallelism = 4 }, (i) => { var attributes = new Dictionary <string, Amazon.DynamoDBv2.Model.AttributeValue>(); attributes.Add("ID Tabla", new AttributeValue() { S = Guid.NewGuid().ToString() }); attributes.Add("Nombre", new AttributeValue() { S = "Pedro" + i }); attributes.Add("Apellido", new AttributeValue() { S = "Perez" + i }); attributes.Add("FechaNacimiento", new AttributeValue() { S = DateTime.Now.ToString() }); attributes.Add("Sueldo", new AttributeValue() { N = (10023444.230 / (i + 1)).ToString(CultureInfo.InvariantCulture) }); var p = cliente.PutItem("TestTable", attributes); }); }
public void PutItem() { var cliente = new DynamoDBClient(); var attributes = new Dictionary <string, Amazon.DynamoDBv2.Model.AttributeValue>(); attributes.Add("ID Tabla", new AttributeValue() { S = Guid.NewGuid().ToString() }); attributes.Add("Nombre", new AttributeValue() { S = "Pedro" }); attributes.Add("Apellido", new AttributeValue() { S = "Perez" }); attributes.Add("FechaNacimiento", new AttributeValue() { S = DateTime.Now.ToLongDateString() }); attributes.Add("Sueldo", new AttributeValue() { N = "10023444.230" }); var p = cliente.PutItem("TestTable", attributes); }
public void PutItem2() { var cliente = new DynamoDBClient(); for (int i = 0; i < 1000; i++) { var attributes = new Dictionary <string, Amazon.DynamoDBv2.Model.AttributeValue>(); attributes.Add("ID Tabla", new AttributeValue() { S = Guid.NewGuid().ToString() }); attributes.Add("Nombre", new AttributeValue() { S = "Pedro" + i }); attributes.Add("Apellido", new AttributeValue() { S = "Perez" + i }); attributes.Add("FechaNacimiento", new AttributeValue() { S = DateTime.Now.ToString() }); attributes.Add("Sueldo", new AttributeValue() { N = (10023444.230 / (i + 1)).ToString(CultureInfo.InvariantCulture) }); var p = cliente.PutItem("TestTable", attributes); } }
private void AddDataToDynamoDb(APIDataUserFlowDbEntity apiData) { Dictionary <string, AttributeValue> attributes = new Dictionary <string, AttributeValue>(); attributes["apiName"] = new AttributeValue { S = apiData.ApiName }; attributes["environment"] = new AttributeValue { S = apiData.Environment }; attributes["awsAccount"] = new AttributeValue { S = apiData.AwsAccount }; attributes["allowedGroups"] = new AttributeValue { SS = new List <string>(apiData.AllowedGroups) }; PutItemRequest request = new PutItemRequest { TableName = "APIAuthenticatorData", Item = attributes }; DynamoDBClient.PutItemAsync(request).GetAwaiter().GetResult(); }
public static void Configure(this IServiceCollection services) { //Comino Database var cominoConnectionString = Environment.GetEnvironmentVariable("COMINO_DB_CONN_STR"); services.AddTransient <IDbConnection>(sp => new SqlConnection(cominoConnectionString)); //Dynamo DB var tableName = Environment.GetEnvironmentVariable("LETTERS_TABLE_NAME"); LambdaLogger.Log($"Dynamo table name {tableName}"); var dynamoConfig = new AmazonDynamoDBConfig { RegionEndpoint = RegionEndpoint.EUWest2 }; var dynamoDbClient = new DynamoDBClient(dynamoConfig); services.AddTransient <IDynamoDBHandler>(sp => new DynamoDBHandler(tableName, dynamoDbClient)); //GovNotify Client var govNotifyApiKey = Environment.GetEnvironmentVariable("GOV_NOTIFY_API_KEY"); services.AddTransient <INotificationClient>(sp => new NotificationClient(govNotifyApiKey)); //SQS services.AddTransient <IAmazonSQS>(sp => new AmazonSQSClient(RegionEndpoint.EUWest2)); //S3 services.AddSingleton <IAmazonS3>(sp => new AmazonS3Client(RegionEndpoint.EUWest2)); //Gateways services.AddScoped <IS3Gateway, S3Gateway>(); services.AddScoped <ICominoGateway, CominoGateway>(); services.AddHttpClient <IW2DocumentsGateway, W2DocumentsGateway>(); services.AddScoped <ISqsGateway, SqsGateway>(); services.AddScoped <ILocalDatabaseGateway, LocalDatabaseGateway>(); services.AddScoped <IDbLogger, LocalDatabaseGateway>(); services.AddScoped <IGovNotifyGateway, GovNotifyGateway>(); //UseCases services.AddScoped <IAuthorizeApi, AuthorizeApi>(); services.AddScoped <IGetDocumentsIds, GetDocumentsIds>(); services.AddScoped <IPushIdsToSqs, PushIdsToSqs>(); services.AddScoped <ISaveRecordsToLocalDatabase, SaveRecordsToLocalDatabase>(); services.AddScoped <IProcessEvents, ProcessEvents>(); services.AddScoped <IGetHtmlDocument, GetHtmlDocument>(); services.AddScoped <IConvertHtmlToPdf, ConvertHtmlToPdf>(); services.AddScoped <IGetParser, ParserLookup>(); services.AddScoped <IConvertHtmlToPdf, ConvertHtmlToPdf>(); services.AddScoped <IFetchAndQueueDocumentIds, FetchAndQueueDocumentIds>(); services.AddScoped <IGetDetailsOfDocumentForProcessing, GetDetailsOfDocumentForProcessing>(); services.AddScoped <IParseHtmlToPdf, HtmlToPdfConversionGateway>(); services.AddScoped <IGetAllDocuments, GetAllDocuments>(); services.AddScoped <IApproveDocument, ApproveDocument>(); services.AddScoped <IGeneratePdfInS3Url, GeneratePdfInS3Url>(); services.AddScoped <IGetSingleDocumentInfo, GetSingleDocumentInfo>(); services.AddScoped <IQueryDocumentsAndSendToNotify, QueryDocumentsAndSendToNotify>(); services.AddScoped <ICheckSendStatusOfLetters, CheckSendStatusOfLetters>(); services.AddScoped <ICancelDocument, CancelDocument>(); }
public async Task DeleteChangeTableForApp(Guid appId) { await DynamoDBClient.DeleteTableAsync(GetChangeTableName(appId)); }
public void UpdateProvisionedThroughput() { var cliente = new DynamoDBClient(); var u = cliente.UpdateProvisionedThroughput("TestTable", 2, 2); }
public void DescribeTable() { var cliente = new DynamoDBClient(); var t = cliente.DescribeTable("TestTable"); }
public void ListTables() { var cliente = new DynamoDBClient(); var l = cliente.ListTables(); }
public void DynamoDbSetUp() { var config = new AmazonDynamoDBConfig { RegionEndpoint = RegionEndpoint.EUWest2, ServiceURL = "http://localhost:8000", //tell SDK to use local database }; DynamoDBClient dynamoDBClient = new DynamoDBClient(config); var request = new ListTablesRequest(); var listTablesResponse = dynamoDBClient.Client.ListTablesAsync(request).Result; if (!listTablesResponse.TableNames.Contains(tableName)) { var createTableRequest = new CreateTableRequest { AttributeDefinitions = new List <AttributeDefinition>() { new AttributeDefinition { AttributeName = "InitialTimestamp", AttributeType = "S" }, new AttributeDefinition { AttributeName = "Status", AttributeType = "S" } }, KeySchema = new List <KeySchemaElement> { new KeySchemaElement { AttributeName = "InitialTimestamp", KeyType = "HASH" } }, ProvisionedThroughput = new ProvisionedThroughput { ReadCapacityUnits = 20, WriteCapacityUnits = 10 }, GlobalSecondaryIndexes = new List <GlobalSecondaryIndex> { new GlobalSecondaryIndex { Projection = new Projection { ProjectionType = ProjectionType.ALL }, IndexName = "Status", KeySchema = new List <KeySchemaElement> { new KeySchemaElement { AttributeName = "Status", KeyType = "HASH" } }, ProvisionedThroughput = new ProvisionedThroughput { ReadCapacityUnits = 5, WriteCapacityUnits = 1, }, } }, TableName = tableName }; var response = dynamoDBClient.Client.CreateTableAsync(createTableRequest).Result; } DatabaseClient = new DynamoDBHandler(tableName, dynamoDBClient); }