public void Create(int port = 8000, string?environmentVariableName = "DYNAMODB_LOCAL_LATEST_COMMON_PATH", bool force = false)
        {
            if (Process == null || force)
            {
                Dispose();

                this._port = port;

                Process = DynamoDbLocalWrapper.CreateInMemoryDbProcess(_port, environmentVariableName);
                Process.Start();

                DynamoDbClient = DynamoDbLocalWrapper.CreateClient(_port);
            }
        }
Exemplo n.º 2
0
        public async Task CreateTable_And_PutOneItem_In_TheTable_Using_DynamoDBClient()
        {
            Exception exception = null;

            using var dynamoDbProcess = DynamoDbLocalWrapper.CreateInMemoryDbProcess(8001, "DYNAMODB_LOCAL_LATEST_COMMON_PATH");

            try
            {
                dynamoDbProcess.Start();

                using var dynamoDbClient = DynamoDbLocalWrapper.CreateClient(8001);

                var createTableResponse = await dynamoDbClient.CreateTableAsync(new CreateTableRequest
                {
                    TableName            = TableName,
                    AttributeDefinitions = new List <AttributeDefinition>
                    {
                        new AttributeDefinition
                        {
                            AttributeName = "Id",
                            AttributeType = "S"
                        },
                        new AttributeDefinition
                        {
                            AttributeName = "CreatedDate",
                            AttributeType = "S"
                        }
                    },
                    KeySchema = new List <KeySchemaElement>
                    {
                        new KeySchemaElement
                        {
                            AttributeName = "Id",
                            KeyType       = "HASH"
                        },
                        new KeySchemaElement
                        {
                            AttributeName = "CreatedDate",
                            KeyType       = "RANGE"
                        }
                    },
                    ProvisionedThroughput = new ProvisionedThroughput
                    {
                        ReadCapacityUnits  = 10,
                        WriteCapacityUnits = 5
                    }
                });

                Assert.Equal(HttpStatusCode.OK, createTableResponse.HttpStatusCode);

                var putItemResponse = await dynamoDbClient.PutItemAsync(new PutItemRequest
                {
                    TableName = TableName,
                    Item      = GetTestItem()
                });

                Assert.Equal(HttpStatusCode.OK, putItemResponse.HttpStatusCode);

                var scanResponse = await dynamoDbClient.ScanAsync(new ScanRequest
                {
                    TableName = TableName
                });

                Assert.Equal(HttpStatusCode.OK, scanResponse.HttpStatusCode);
            } catch (Exception ex) {
                exception = ex;
            }

            dynamoDbProcess.Kill(true);

            if (exception != null)
            {
                throw exception;
            }
        }