/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { StartPersonTrackingResponse response = new StartPersonTrackingResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("JobId", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.JobId = unmarshaller.Unmarshall(context); continue; } } return(response); }
public async Task <int> FunctionHandler(FileInfo fileInfo, ILambdaContext context) { StartPersonTrackingRequest request = new StartPersonTrackingRequest { Video = new Video { S3Object = new S3Object { Bucket = fileInfo.Bucket, Name = fileInfo.Key } }, NotificationChannel = new NotificationChannel { RoleArn = "arn:aws:iam::518495728486:role/hackathon-rek-role", SNSTopicArn = "arn:aws:sns:us-east-1:518495728486:AmazonRekognition-hackathon-2018" }, }; StartPersonTrackingResponse response = await rekClient.StartPersonTrackingAsync(request).ConfigureAwait(false); return(await ProcessVideoMessages(context, response)); }
private async Task <int> ProcessVideoMessages(ILambdaContext context, StartPersonTrackingResponse response) { int validLength; do { ReceiveMessageResponse messageResponse = await sqsClient.ReceiveMessageAsync(new ReceiveMessageRequest { QueueUrl = QUrl, MaxNumberOfMessages = 10, WaitTimeSeconds = 15 }).ConfigureAwait(false); if (!messageResponse.Messages.Any()) { continue; } Message message = messageResponse.Messages.SingleOrDefault(x => x.Body.Contains(response.JobId)); if (message == null) { context.Logger.LogLine("job received is not of interest"); messageResponse.Messages.ForEach(async msg => await sqsClient.DeleteMessageAsync(new DeleteMessageRequest { QueueUrl = QUrl, ReceiptHandle = msg.ReceiptHandle })); } else { validLength = await ProcessInterestedMessage(context, response, message).ConfigureAwait(false); break; } } while (true); return(validLength); }
private async Task <int> ProcessInterestedMessage(ILambdaContext context, StartPersonTrackingResponse response, Message message) { int validLength = 0; if (message.Body.Contains("SUCCEEDED")) { context.Logger.LogLine( $"job with jobId {response.JobId} found and succeeded, continuing to process remaining messages"); validLength = await this.ProcessLabels(context, response.JobId).ConfigureAwait(false); } else { context.Logger.LogLine($"job with jobId {response.JobId} found and failed, please check cloud watch logs for more details"); } await sqsClient.DeleteMessageAsync(new DeleteMessageRequest { QueueUrl = QUrl, ReceiptHandle = message.ReceiptHandle }).ConfigureAwait(false); return(validLength); }