public void FunctionHandler(DynamoDBEvent dynamoEvent, ILambdaContext context) { context.Logger.LogLine($"Beginning to process {dynamoEvent.Records.Count} records..."); foreach (var record in dynamoEvent.Records) { var oldImage = Document.FromAttributeMap(record.Dynamodb.OldImage); var newImage = Document.FromAttributeMap(record.Dynamodb.NewImage); var oldState = _dynamoDbContext.FromDocument <Lightbulb>(oldImage); var newState = _dynamoDbContext.FromDocument <Lightbulb>(newImage); var changes = _changeProcessor.GetChanges(oldState, newState); if (changes.success) { PublishResponse publishResponse = _snsClient.PublishAsync(_snsArn, changes.message, "Lightbulb").Result; context.Logger.LogLine($"Sent Message '{changes.message}' with SNS MessageId: {publishResponse.MessageId}"); } else { context.Logger.LogLine("No useful changes detected"); } } context.Logger.LogLine("Stream processing complete."); }
public async Task <OpenLibraryVersion> FindLatestArchiveEntry(OpenLibraryArchiveType archiveType, CancellationToken ct) { var attributeValuesMap = new Dictionary <string, AttributeValue> { { ":kind", new AttributeValue { S = archiveType.GetKey() } }, { ":date", new AttributeValue { S = _clock.UtcNow().ToIsoDateString() } }, }; var queryReq = new QueryRequest { TableName = _openLibVersionsTable, KeyConditionExpression = "Kind = :kind AND PublishDate <= :date", ScanIndexForward = false, // False = sort by descending ExpressionAttributeValues = attributeValuesMap, Limit = 1, }; var queryResults = await _dynamoClient.QueryAsync(queryReq, ct); var theResult = queryResults.Items?.SingleOrDefault(); if (theResult is null) { return(null); } var doc = Document.FromAttributeMap(theResult); var typed = _pocoClient.FromDocument <OpenLibraryVersion>(doc); return(typed); }
async Task <IEnumerable <Member> > IDataRepository.GetMembers(string churchId, IEnumerable <string> memberIds) { var batchGet = _membersTable.CreateBatchGet(); foreach (var memberId in memberIds) { batchGet.AddKey(churchId, memberId); } await batchGet.ExecuteAsync(); return(batchGet.Results.Select(doc => _ddbContext.FromDocument <Member>(doc))); }
public object FromEntry(DynamoDBEntry entry) { var document = entry.AsDocument(); if (document == null) { return(null); } var result = new Dictionary <string, TEntity>(); document.Keys.ToList().ForEach(key => { var item = document[key].AsDocument(); var entity = _dbContext.FromDocument <TEntity>(item); result.Add(key, entity); }); return(result); }
public object FromEntry(DynamoDBEntry entry) { var document = entry.AsDocument(); return(_dbContext.FromDocument <TEntity>(document)); }