/// <summary> /// A simple function that takes a string and returns both the upper and lower case version of the string. /// </summary> /// <param name="input"></param> /// <param name="context"></param> /// <returns></returns> public async Task FunctionHandler(S3Event evnt, ILambdaContext context) { string bucket = evnt.Records[0].S3.Bucket.Name; string key = evnt.Records[0].S3.Object.Key; Console.WriteLine(bucket); Console.WriteLine(key); string objectId = key.Substring(key.LastIndexOf("/") + 1); Console.WriteLine(objectId); var options = await new GraphQLHttpClientOptions() .ConfigureAppSync( GraphQLEndpoint, appSyncClient.Config ); _graphQlClient = new GraphQLHttpClient(options, new SystemTextJsonSerializer()); var sfnInput = new SfnExecutionInput() { objectId = objectId, Bucket = bucket, SourceKey = key }; var startWorkflowMutation = new GraphQLRequest { Query = @" mutation StartSfnExecution( $input: StartSfnExecutionInput! ) { startSfnExecution(input: $input) { executionArn startDate } }", OperationName = "StartSfnExecution", Variables = new { input = new { input = JsonSerializer.Serialize(sfnInput), stateMachineArn = StateMachineArn }, } }; var workflowMutationResponse = await _graphQlClient.SendMutationAsync <StartWorkflowResult>(startWorkflowMutation); Console.WriteLine(JsonSerializer.Serialize(workflowMutationResponse.Data.startSfnExecution)); var updatePhotoRequest = new GraphQLRequest { Query = @" mutation UpdatePhotoMutation( $input: UpdatePhotoInput! $condition: ModelPhotoConditionInput ) { updatePhoto(input: $input, condition: $condition) { id albumId owner uploadTime bucket sfnExecutionArn processingStatus } }", OperationName = "UpdatePhotoMutation", Variables = new { input = new { id = objectId, sfnExecutionArn = workflowMutationResponse.Data.startSfnExecution.executionArn, processingStatus = "RUNNING" } } }; var photoUpdateMutationResponse = await _graphQlClient.SendMutationAsync <UpdatePhotoResponse>(updatePhotoRequest); Console.WriteLine(JsonSerializer.Serialize(photoUpdateMutationResponse.Data)); }
/// <summary> /// A simple function that takes a string and returns both the upper and lower case version of the string. /// </summary> /// <param name="input"></param> /// <param name="context"></param> /// <returns></returns> public async Task FunctionHandler(InputEvent input, ILambdaContext context) { string graphQlEndpoint = System.Environment.GetEnvironmentVariable(GRAPHQL_ENDPOINT); var options = await new GraphQLHttpClientOptions() .ConfigureAppSync( graphQlEndpoint, appSyncClient.Config ); _graphQlClient = new GraphQLHttpClient(options, new SystemTextJsonSerializer()); const string UPDATE_PHOTO = @" mutation UpdatePhotoMutation( $input: UpdatePhotoInput! $condition: ModelPhotoConditionInput ) { updatePhoto(input: $input, condition: $condition) { id fullsize { key width height } thumbnail { key width height } format exifMake exitModel objectDetected processingStatus geoLocation { latitude { d m s direction } longtitude { d m s direction } } } }"; var thumbnail = JsonSerializer.Deserialize <Thumbnail>(JsonSerializer.Serialize(input.ParallelResults[1])); List <Label> labels = JsonSerializer.Deserialize <List <Label> >(JsonSerializer.Serialize(input.ParallelResults[0])); var updatePhotoMutation = new GraphQLRequest { Query = UPDATE_PHOTO, OperationName = "UpdatePhotoMutation", Variables = new { input = new { id = input.ObjectId, processingStatus = "SUCCEEDED", fullsize = new { key = input.SourceKey, width = input.ExtractedMetadata?.Dimensions?.Width, height = input.ExtractedMetadata?.Dimensions?.Height, }, format = input.ExtractedMetadata?.Format, exifMake = input.ExtractedMetadata?.ExifMake, exitModel = input.ExtractedMetadata?.ExifModel, thumbnail = new { key = thumbnail?.s3key, width = thumbnail?.width, height = thumbnail?.height, }, objectDetected = labels.Select(l => l.Name).ToArray(), geoLocation = input.ExtractedMetadata?.Geo } } }; var photoUpdateMutationResponse = await _graphQlClient.SendMutationAsync <object>(updatePhotoMutation); Console.WriteLine(JsonSerializer.Serialize(photoUpdateMutationResponse)); }