I have an AWS lambda (to be fired by a cloudwatch event) which should be pulling 248 records from one API and inserting 248 records into Dynamo DB. It successfully pulls 248 records, but the Dynamo table only contains 4 records once the execution finishes, with no errors.
This is the work horse code from the lambda:
public async Task<APIGatewayProxyResponse> Get(APIGatewayProxyRequest request, ILambdaContext context)
{
try
{
var count = await LoadAutocomplete(Data);
context.Logger.LogLine($"{count} items processed into table '{EnvironmentHelper.DynamoTableName}'");
...
return response;
}
catch (Exception ex)
{
...
}
}
private async Task<int> LoadAutocomplete(IList<MatItem> data)
{
var count = 0;
var client = new AmazonDynamoDBClient();
var table = Amazon.DynamoDBv2.DocumentModel.Table.LoadTable(client, EnvironmentHelper.DynamoTableName);
foreach (var item in data)
{
var doc = new Amazon.DynamoDBv2.DocumentModel.Document();
doc.Add("LANGUAGE", item.LANGUAGE);
doc.Add("MAT_DESC", item.MAT_DESC);
doc.Add("SALES_ORG", item.SALES_ORG);
doc.Add("COUNTRY", item.COUNTRY);
doc.Add("SPECIFICATION", item.SPECIFICATION);
doc.Add("MATERIAL", item.MATERIAL);
doc.Add("TEMPLATE_ID", item.TEMPLATE_ID);
await table.PutItemAsync(doc);
count++;
System.Threading.Thread.Sleep(100);
}
return count;
}
And this is the output of the LogLine
statement:
248 items processed into table 'my-data'
Here is the tf used to create the table:
# create the table
resource "aws_dynamodb_table" "prospectmaterials_table" {
name = "my-table"
hash_key = "MATERIAL"
billing_mode = "PROVISIONED"
read_capacity = 5
write_capacity = 5
attribute {
name = "MATERIAL"
type = "S"
}
}