From 43b1f523adeb54dda31a21da3d898f7651a7578f Mon Sep 17 00:00:00 2001 From: Linneeeeeeee Date: Wed, 29 May 2024 23:14:37 +0000 Subject: [PATCH] Dev --- aws_iam_policy_document.tf | 48 + aws_iam_role.tf | 15 + aws_iam_role_policy.tf | 5 + aws_sfn_state_machine.tf | 18 + state_machine/RekognitionDetectText.json | 1193 ++++++++++++++++++++++ 5 files changed, 1279 insertions(+) create mode 100644 state_machine/RekognitionDetectText.json diff --git a/aws_iam_policy_document.tf b/aws_iam_policy_document.tf index 02fafce..4233591 100644 --- a/aws_iam_policy_document.tf +++ b/aws_iam_policy_document.tf @@ -50,6 +50,19 @@ data "aws_iam_policy_document" "assume_role_sfn_state_machine_rekognition_detect } } +data "aws_iam_policy_document" "assume_role_sfn_state_machine_rekognition_detect_text" { + statement { + actions = [ + "sts:AssumeRole" + ] + effect = "Allow" + principals { + identifiers = ["states.amazonaws.com"] + type = "Service" + } + } +} + data "aws_iam_policy_document" "sfn_state_machine_rekognition_detect_faces" { statement { actions = [ @@ -189,3 +202,38 @@ data "aws_iam_policy_document" "sfn_state_machine_rekognition_detect_protective_ ] } } + +data "aws_iam_policy_document" "sfn_state_machine_rekognition_detect_text" { + statement { + actions = [ + "s3:GetObject", + "s3:GetObjectAttributes", + "s3:GetObjectVersion" + ] + effect = "Allow" + resources = [ + "${aws_s3_bucket.main.arn}/${aws_s3_object.images.key}*" + ] + } + + statement { + actions = [ + "s3:GetBucketVersioning", + "s3:ListBucket" + ] + effect = "Allow" + resources = [ + "${aws_s3_bucket.main.arn}" + ] + } + + statement { + actions = [ + "rekognition:DetectText" + ] + effect = "Allow" + resources = [ + "*" + ] + } +} diff --git a/aws_iam_role.tf b/aws_iam_role.tf index 0619995..dd1c796 100644 --- a/aws_iam_role.tf +++ b/aws_iam_role.tf @@ -57,3 +57,18 @@ resource "aws_iam_role" "sfn_state_machine_rekognition_detect_protective_equipme workspace = terraform.workspace } } + +resource "aws_iam_role" "sfn_state_machine_rekognition_detect_text" { + assume_role_policy = data.aws_iam_policy_document.assume_role_sfn_state_machine_rekognition_detect_text.json + name = "sfn-state-machine-rekognition-detect-text" + path = "/${local.organization}/" + tags = { + caller_identity_account_arn = data.aws_caller_identity.main.arn + caller_identity_account_id = data.aws_caller_identity.main.account_id + caller_identity_user_id = data.aws_caller_identity.main.user_id + canonical_user_id = data.aws_canonical_user_id.main.id + organization = local.organization + region = data.aws_region.main.name + workspace = terraform.workspace + } +} diff --git a/aws_iam_role_policy.tf b/aws_iam_role_policy.tf index 5ea2f39..eb0adba 100644 --- a/aws_iam_role_policy.tf +++ b/aws_iam_role_policy.tf @@ -17,3 +17,8 @@ resource "aws_iam_role_policy" "sfn_state_machine_rekognition_detect_protective_ policy = data.aws_iam_policy_document.sfn_state_machine_rekognition_detect_protective_equipment.json role = aws_iam_role.sfn_state_machine_rekognition_detect_protective_equipment.id } + +resource "aws_iam_role_policy" "sfn_state_machine_rekognition_detect_text" { + policy = data.aws_iam_policy_document.sfn_state_machine_rekognition_detect_text.json + role = aws_iam_role.sfn_state_machine_rekognition_detect_text.id +} diff --git a/aws_sfn_state_machine.tf b/aws_sfn_state_machine.tf index 87266a6..9bb3a96 100644 --- a/aws_sfn_state_machine.tf +++ b/aws_sfn_state_machine.tf @@ -69,3 +69,21 @@ resource "aws_sfn_state_machine" "rekognition_detect_protective_equipment" { workspace = terraform.workspace } } + +resource "aws_sfn_state_machine" "rekognition_detect_text" { + definition = templatefile("./state_machine/RekognitionDetectText.json", {}) + name = "rekognition-detect-text" + role_arn = aws_iam_role.sfn_state_machine_rekognition_detect_text.arn + tags = { + bucket = aws_s3_bucket.main.bucket + bucket_key = aws_s3_object.images.key + caller_identity_account_arn = data.aws_caller_identity.main.arn + caller_identity_account_id = data.aws_caller_identity.main.account_id + caller_identity_user_id = data.aws_caller_identity.main.user_id + canonical_user_id = data.aws_canonical_user_id.main.id + organization = local.organization + rekognition = "DetectText" + region = data.aws_region.main.name + workspace = terraform.workspace + } +} diff --git a/state_machine/RekognitionDetectText.json b/state_machine/RekognitionDetectText.json new file mode 100644 index 0000000..4133176 --- /dev/null +++ b/state_machine/RekognitionDetectText.json @@ -0,0 +1,1193 @@ +{ + "StartAt": "ParallelCheckInput", + "States": { + "ParallelCheckInput": { + "Type": "Parallel", + "Branches": [ + { + "StartAt": "CheckInputRekognition", + "States": { + "CheckInputRekognition": { + "Type": "Choice", + "Choices": [ + { + "And": [ + { + "Variable": "$.Rekognition", + "IsPresent": true + }, + { + "Not": { + "Variable": "$.Rekognition", + "IsNull": true + } + } + ], + "Next": "CheckInputDetectText" + } + ], + "Default": "DefaultInputRekognition" + }, + "DefaultInputRekognition": { + "Type": "Pass", + "Parameters": { + "Rekognition": {} + }, + "Next": "CheckInputDetectText" + }, + "CheckInputDetectText": { + "Type": "Choice", + "Choices": [ + { + "And": [ + { + "Variable": "$.DetectText", + "IsPresent": true + }, + { + "Not": { + "Variable": "$.DetectText", + "IsNull": true + } + } + ], + "Next": "ParallelCheckInputDetectText" + } + ], + "InputPath": "$.Rekognition", + "Default": "DefaultInputDetectText" + }, + "DefaultInputDetectText": { + "Type": "Pass", + "Parameters": { + "DetectText": {} + }, + "Next": "ParallelCheckInputDetectText" + }, + "ParallelCheckInputDetectText": { + "Type": "Parallel", + "End": true, + "Branches": [ + { + "StartAt": "CheckInputRegionsOfInterest", + "States": { + "CheckInputRegionsOfInterest": { + "Type": "Choice", + "Choices": [ + { + "And": [ + { + "Variable": "$.RegionsOfInterest", + "IsPresent": true + }, + { + "Not": { + "Variable": "$.RegionsOfInterest", + "IsNull": true + } + } + ], + "Next": "MapInputRegionsOfInterest" + } + ], + "Default": "DefaultInputRegionsOfInterest" + }, + "MapInputRegionsOfInterest": { + "Type": "Map", + "ItemProcessor": { + "ProcessorConfig": { + "Mode": "INLINE" + }, + "StartAt": "ParallelCheckInputRegionOfInterest", + "States": { + "ParallelCheckInputRegionOfInterest": { + "Type": "Parallel", + "End": true, + "Branches": [ + { + "StartAt": "CheckInputRegionOfInterestBoundingBox", + "States": { + "CheckInputRegionOfInterestBoundingBox": { + "Type": "Choice", + "Choices": [ + { + "And": [ + { + "Variable": "$.BoundingBox", + "IsPresent": true + }, + { + "Not": { + "Variable": "$.BoundingBox", + "IsNull": true + } + } + ], + "Next": "ParallelCheckInputRegionOfInterestBoundingBox" + } + ], + "Default": "DefaultInputRegionOfInterestBoundingBox" + }, + "ParallelCheckInputRegionOfInterestBoundingBox": { + "Type": "Parallel", + "End": true, + "Branches": [ + { + "StartAt": "CheckInputRegionOfInterestBoundingBoxHeight", + "States": { + "CheckInputRegionOfInterestBoundingBoxHeight": { + "Type": "Choice", + "Choices": [ + { + "And": [ + { + "Variable": "$.Height", + "IsPresent": true + }, + { + "Variable": "$.Height", + "IsNumeric": true + } + ], + "Next": "PassInputRegionOfInterestBoundingBoxHeight" + } + ], + "Default": "FailCheckInputRegionOfInterestBoundingBoxHeight" + }, + "PassInputRegionOfInterestBoundingBoxHeight": { + "Type": "Pass", + "End": true, + "InputPath": "$.Height" + }, + "FailCheckInputRegionOfInterestBoundingBoxHeight": { + "Type": "Fail" + } + } + }, + { + "StartAt": "CheckInputRegionOfInterestBoundingBoxLeft", + "States": { + "CheckInputRegionOfInterestBoundingBoxLeft": { + "Type": "Choice", + "Choices": [ + { + "And": [ + { + "Variable": "$.Left", + "IsPresent": true + }, + { + "Variable": "$.Left", + "IsNumeric": true + } + ], + "Next": "PassInputRegionOfInterestBoundingBoxLeft" + } + ], + "Default": "FailCheckInputRegionOfInterestBoundingBoxLeft" + }, + "PassInputRegionOfInterestBoundingBoxLeft": { + "Type": "Pass", + "End": true + }, + "FailCheckInputRegionOfInterestBoundingBoxLeft": { + "Type": "Fail" + } + } + }, + { + "StartAt": "CheckInputRegionOfInterestBoundingBoxTop", + "States": { + "CheckInputRegionOfInterestBoundingBoxTop": { + "Type": "Choice", + "Choices": [ + { + "And": [ + { + "Variable": "$.Top", + "IsPresent": true + }, + { + "Variable": "$.Top", + "IsNumeric": true + } + ], + "Next": "PassInputRegionOfInterestBoundingBoxTop" + } + ], + "Default": "FailCheckInputRegionOfInterestBoundingBoxTop" + }, + "PassInputRegionOfInterestBoundingBoxTop": { + "Type": "Pass", + "End": true, + "InputPath": "$.Top" + }, + "FailCheckInputRegionOfInterestBoundingBoxTop": { + "Type": "Fail" + } + } + }, + { + "StartAt": "CheckInputRegionOfInterestBoundingBoxWidth", + "States": { + "CheckInputRegionOfInterestBoundingBoxWidth": { + "Type": "Choice", + "Choices": [ + { + "And": [ + { + "Variable": "$.Width", + "IsPresent": true + }, + { + "Variable": "$.Width", + "IsNumeric": true + } + ], + "Next": "PassInputRegionOfInterestBoundingBoxWidth" + } + ], + "Default": "FailCheckInputRegionOfInterestBoundingBoxWidth" + }, + "PassInputRegionOfInterestBoundingBoxWidth": { + "Type": "Pass", + "End": true + }, + "FailCheckInputRegionOfInterestBoundingBoxWidth": { + "Type": "Fail" + } + } + } + ], + "ResultSelector": { + "Height.$": "$[0]", + "Left.$": "$[1]", + "Top.$": "$[2]", + "Width.$": "$[3]" + }, + "InputPath": "$.BoundingBox" + }, + "DefaultInputRegionOfInterestBoundingBox": { + "Type": "Pass", + "End": true, + "Parameters": { + "BoundingBox": null + }, + "OutputPath": "$.BoundingBox" + } + } + }, + { + "StartAt": "CheckInputRegionOfInterestPolygon", + "States": { + "CheckInputRegionOfInterestPolygon": { + "Type": "Choice", + "Choices": [ + { + "And": [ + { + "Variable": "$.Polygon", + "IsPresent": true + }, + { + "Not": { + "Variable": "$.Polygon", + "IsNull": true + } + } + ], + "Next": "MapInputRegionOfInterestPolygon" + } + ], + "Default": "DefaultInputRegionOfInterestPolygon" + }, + "MapInputRegionOfInterestPolygon": { + "Type": "Map", + "ItemProcessor": { + "ProcessorConfig": { + "Mode": "INLINE" + }, + "StartAt": "ParallelCheckInputRegionOfInterestPolygon", + "States": { + "ParallelCheckInputRegionOfInterestPolygon": { + "Type": "Parallel", + "End": true, + "Branches": [ + { + "StartAt": "CheckInputRegionOfInterestPolygonX", + "States": { + "CheckInputRegionOfInterestPolygonX": { + "Type": "Choice", + "Choices": [ + { + "And": [ + { + "Variable": "$.X", + "IsPresent": true + }, + { + "Variable": "$.X", + "IsNumeric": true + } + ], + "Next": "PassInputRegionOfInterestPolygonX" + } + ], + "Default": "FailCheckInputRegionOfInterestPolygonX" + }, + "PassInputRegionOfInterestPolygonX": { + "Type": "Pass", + "End": true, + "InputPath": "$.X" + }, + "FailCheckInputRegionOfInterestPolygonX": { + "Type": "Fail" + } + } + }, + { + "StartAt": "CheckInputRegionOfInterestPolygonY", + "States": { + "CheckInputRegionOfInterestPolygonY": { + "Type": "Choice", + "Choices": [ + { + "And": [ + { + "Variable": "$.Y", + "IsPresent": true + }, + { + "Variable": "$.Y", + "IsNumeric": true + } + ], + "Next": "PassInputRegionOfInterestPolygonY" + } + ], + "Default": "FailCheckInputRegionOfInterestPolygonY" + }, + "PassInputRegionOfInterestPolygonY": { + "Type": "Pass", + "End": true, + "InputPath": "$.Y" + }, + "FailCheckInputRegionOfInterestPolygonY": { + "Type": "Fail" + } + } + } + ], + "ResultSelector": { + "X.$": "$[0]", + "Y.$": "$[1]" + } + } + } + }, + "End": true, + "ItemsPath": "$.Polygon" + }, + "DefaultInputRegionOfInterestPolygon": { + "Type": "Pass", + "Parameters": { + "Polygon": [] + }, + "Next": "MapInputRegionOfInterestPolygon" + } + } + } + ], + "ResultSelector": { + "BoundingBox.$": "$[0]", + "Polygon.$": "$[1]" + } + } + } + }, + "End": true, + "ItemsPath": "$.RegionsOfInterest" + }, + "DefaultInputRegionsOfInterest": { + "Type": "Pass", + "Parameters": { + "RegionsOfInterest": [] + }, + "Next": "MapInputRegionsOfInterest" + } + } + }, + { + "StartAt": "CheckInputWordFilter", + "States": { + "CheckInputWordFilter": { + "Type": "Choice", + "Choices": [ + { + "And": [ + { + "Variable": "$.WordFilter", + "IsPresent": true + }, + { + "Not": { + "Variable": "$.WordFilter", + "IsNull": true + } + } + ], + "Next": "ParallelCheckInputWordFilter" + } + ], + "Default": "DefaultInputWordFilter" + }, + "ParallelCheckInputWordFilter": { + "Type": "Parallel", + "End": true, + "Branches": [ + { + "StartAt": "CheckInputWordFilterMinBoundingBoxHeight", + "States": { + "CheckInputWordFilterMinBoundingBoxHeight": { + "Type": "Choice", + "Choices": [ + { + "And": [ + { + "Variable": "$.MinBoundingBoxHeight", + "IsPresent": true + }, + { + "Variable": "$.MinBoundingBoxHeight", + "IsNumeric": true + } + ], + "Next": "PassInputWordFilterMinBoundingBoxHeight" + } + ], + "Default": "FailCheckInputWordFilterMinBoundingBoxHeight" + }, + "PassInputWordFilterMinBoundingBoxHeight": { + "Type": "Pass", + "End": true, + "InputPath": "$.MinBoundingBoxHeight" + }, + "FailCheckInputWordFilterMinBoundingBoxHeight": { + "Type": "Fail" + } + } + }, + { + "StartAt": "CheckInputWordFilterMinBoundingBoxWidth", + "States": { + "CheckInputWordFilterMinBoundingBoxWidth": { + "Type": "Choice", + "Choices": [ + { + "And": [ + { + "Variable": "$.MinBoundingBoxWidth", + "IsPresent": true + }, + { + "Not": { + "Variable": "$.MinBoundingBoxWidth", + "IsNull": true + } + } + ], + "Next": "PassInputWordFilterMinBoundingBoxWidth" + } + ], + "Default": "FailCheckInputWordFilterMinBoundingBoxWidth" + }, + "PassInputWordFilterMinBoundingBoxWidth": { + "Type": "Pass", + "End": true, + "InputPath": "$.MinBoundingBoxWidth" + }, + "FailCheckInputWordFilterMinBoundingBoxWidth": { + "Type": "Fail" + } + } + }, + { + "StartAt": "CheckInputWordFilterMinConfidence", + "States": { + "CheckInputWordFilterMinConfidence": { + "Type": "Choice", + "Choices": [ + { + "Variable": "$.MinConfidence", + "IsPresent": true, + "Next": "PassInputWordFilterMinConfidence" + } + ], + "Default": "FailCheckInputWordFilterMinConfidence" + }, + "PassInputWordFilterMinConfidence": { + "Type": "Pass", + "End": true, + "InputPath": "$.MinConfidence" + }, + "FailCheckInputWordFilterMinConfidence": { + "Type": "Fail" + } + } + } + ], + "ResultSelector": { + "MinBoundingBoxHeight.$": "$[0]", + "MinBoundingBoxWidth.$": "$[1]", + "MinConfidence.$": "$[2]" + }, + "InputPath": "$.WordFilter" + }, + "DefaultInputWordFilter": { + "Type": "Pass", + "End": true, + "Parameters": { + "WordFilter": null + }, + "OutputPath": "$.WordFilter" + } + } + } + ], + "ResultSelector": { + "DetectText": { + "RegionsOfInterest.$": "$[0]", + "WordFilter.$": "$[1]" + } + }, + "InputPath": "$.DetectText" + } + } + }, + { + "StartAt": "CheckInputS3", + "States": { + "CheckInputS3": { + "Type": "Choice", + "Choices": [ + { + "Variable": "$.S3", + "IsPresent": true, + "Next": "ParallelCheckInputS3" + } + ], + "Default": "FailCheckS3Input" + }, + "ParallelCheckInputS3": { + "Type": "Parallel", + "Branches": [ + { + "StartAt": "CheckInputBucket", + "States": { + "CheckInputBucket": { + "Type": "Choice", + "Choices": [ + { + "Variable": "$.Bucket", + "IsPresent": true, + "Next": "CheckInputBucketName" + } + ], + "Default": "FailCheckInputBucket" + }, + "CheckInputBucketName": { + "Type": "Choice", + "Choices": [ + { + "And": [ + { + "Variable": "$.Name", + "IsPresent": true + }, + { + "Variable": "$.Name", + "IsString": true + } + ], + "Next": "HeadBucket" + } + ], + "Default": "FailCheckInputBucketName", + "InputPath": "$.Bucket" + }, + "HeadBucket": { + "Type": "Task", + "Parameters": { + "Bucket.$": "$.Name" + }, + "Resource": "arn:aws:states:::aws-sdk:s3:headBucket", + "Catch": [ + { + "ErrorEquals": [ + "States.TaskFailed" + ], + "Next": "FailHeadBucket" + } + ], + "ResultPath": "$.Output", + "Next": "PassHeadBucket" + }, + "PassHeadBucket": { + "Type": "Pass", + "End": true, + "Parameters": { + "AccessPointAlias.$": "$.Output.AccessPointAlias", + "Name.$": "$.Name", + "Region.$": "$.Output.BucketRegion" + } + }, + "FailHeadBucket": { + "Type": "Fail" + }, + "FailCheckInputBucketName": { + "Type": "Fail" + }, + "FailCheckInputBucket": { + "Type": "Fail" + } + } + }, + { + "StartAt": "CheckInputObject", + "States": { + "CheckInputObject": { + "Type": "Choice", + "Choices": [ + { + "Variable": "$.Object", + "IsPresent": true, + "Next": "CheckInputKey" + } + ], + "Default": "FailCheckInputObject" + }, + "CheckInputKey": { + "Type": "Choice", + "Choices": [ + { + "And": [ + { + "Variable": "$.Key", + "IsPresent": true + }, + { + "Variable": "$.Key", + "IsString": true + } + ], + "Next": "PassInputKey" + } + ], + "Default": "FailCheckInputKey", + "InputPath": "$.Object" + }, + "PassInputKey": { + "Type": "Pass", + "End": true + }, + "FailCheckInputKey": { + "Type": "Fail" + }, + "FailCheckInputObject": { + "Type": "Fail" + } + } + } + ], + "InputPath": "$.S3", + "ResultSelector": { + "Bucket.$": "$[0]", + "Object.$": "$[1]" + }, + "Next": "HeadObject" + }, + "HeadObject": { + "Type": "Task", + "Parameters": { + "Bucket.$": "$.Bucket.Name", + "Key.$": "$.Object.Key" + }, + "Resource": "arn:aws:states:::aws-sdk:s3:headObject", + "ResultPath": "$.Output", + "Catch": [ + { + "ErrorEquals": [ + "States.TaskFailed" + ], + "Next": "FailHeadObject" + } + ], + "Next": "PassHeadObject" + }, + "PassHeadObject": { + "Type": "Pass", + "Parameters": { + "Bucket.$": "$.Bucket", + "Object.$": "States.JsonMerge($.Object, $.Output, false)" + }, + "Next": "GetObjectAttributes" + }, + "GetObjectAttributes": { + "Type": "Task", + "Parameters": { + "Bucket.$": "$.Bucket.Name", + "Key.$": "$.Object.Key", + "ObjectAttributes": [ + "Checksum", + "ETag", + "ObjectParts", + "ObjectSize", + "StorageClass" + ] + }, + "Resource": "arn:aws:states:::aws-sdk:s3:getObjectAttributes", + "ResultPath": "$.Output", + "Catch": [ + { + "ErrorEquals": [ + "States.TaskFailed" + ], + "Next": "FailGetObjectAttributes" + } + ], + "Next": "PassGetObjectAttributes" + }, + "PassGetObjectAttributes": { + "Type": "Pass", + "End": true, + "Parameters": { + "Bucket.$": "$.Bucket", + "Object.$": "States.JsonMerge($.Object, $.Output, false)" + } + }, + "FailGetObjectAttributes": { + "Type": "Fail" + }, + "FailHeadObject": { + "Type": "Fail" + }, + "FailCheckS3Input": { + "Type": "Fail" + } + } + } + ], + "Next": "DetectText", + "ResultSelector": { + "Rekognition.$": "$[0]", + "S3.$": "$[1]" + } + }, + "DetectText": { + "Type": "Task", + "Parameters": { + "Image": { + "S3Object": { + "Bucket.$": "$.S3.Bucket.Name", + "Name.$": "$.S3.Object.Key" + } + } + }, + "Resource": "arn:aws:states:::aws-sdk:rekognition:detectText", + "Next": "ParallelCheckOutputDetectText", + "Catch": [ + { + "ErrorEquals": [ + "States.TaskFailed" + ], + "Next": "FailDetectText" + } + ], + "ResultPath": "$.Output" + }, + "ParallelCheckOutputDetectText": { + "Type": "Parallel", + "Branches": [ + { + "StartAt": "CheckOutputOrientationCorrection", + "States": { + "CheckOutputOrientationCorrection": { + "Type": "Choice", + "Choices": [ + { + "Variable": "$.OrientationCorrection", + "IsPresent": true, + "Next": "PassOrientationCorrection" + } + ], + "Default": "DefaultOutputOrientationCorrection", + "InputPath": "$.Output" + }, + "PassOrientationCorrection": { + "Type": "Pass", + "End": true, + "InputPath": "$.OrientationCorrection" + }, + "DefaultOutputOrientationCorrection": { + "Type": "Pass", + "Parameters": { + "OrientationCorrection": null + }, + "Next": "PassOrientationCorrection" + } + } + }, + { + "StartAt": "CheckOutputTextDetections", + "States": { + "CheckOutputTextDetections": { + "Type": "Choice", + "Choices": [ + { + "Variable": "$.TextDetections", + "IsPresent": true, + "Next": "MapOutputTextDetections" + } + ], + "Default": "DefaultOutputTextDetections", + "InputPath": "$.Output" + }, + "DefaultOutputTextDetections": { + "Type": "Pass", + "Parameters": { + "TextDetections": null + }, + "OutputPath": "$.TextDetections", + "End": true + }, + "MapOutputTextDetections": { + "Type": "Map", + "ItemProcessor": { + "ProcessorConfig": { + "Mode": "INLINE" + }, + "StartAt": "ParallelCheckOutputTextDetection", + "States": { + "ParallelCheckOutputTextDetection": { + "Type": "Parallel", + "End": true, + "Branches": [ + { + "StartAt": "CheckOutputTextDetectionConfidence", + "States": { + "CheckOutputTextDetectionConfidence": { + "Type": "Choice", + "Choices": [ + { + "Variable": "$.Confidence", + "IsPresent": true, + "Next": "PassOutputTextDetectionConfidence" + } + ], + "Default": "DefaultOutputTextDetectionConfidence" + }, + "PassOutputTextDetectionConfidence": { + "Type": "Pass", + "End": true, + "InputPath": "$.Confidence" + }, + "DefaultOutputTextDetectionConfidence": { + "Type": "Pass", + "End": true, + "Parameters": { + "Confidence": null + }, + "OutputPath": "$.Confidence" + } + } + }, + { + "StartAt": "CheckOutputTextDetectionDetectedText", + "States": { + "CheckOutputTextDetectionDetectedText": { + "Type": "Choice", + "Choices": [ + { + "Variable": "$.DetectedText", + "IsPresent": true, + "Next": "PassOutputTextDetectionDetectedText" + } + ], + "Default": "DefaultOutputTextDetectionDetectedText" + }, + "PassOutputTextDetectionDetectedText": { + "Type": "Pass", + "End": true, + "InputPath": "$.DetectedText" + }, + "DefaultOutputTextDetectionDetectedText": { + "Type": "Pass", + "End": true, + "Parameters": { + "DetectedText": null + }, + "OutputPath": "$.DetectedText" + } + } + }, + { + "StartAt": "CheckOutputTextDetectionGeometry", + "States": { + "CheckOutputTextDetectionGeometry": { + "Type": "Choice", + "Choices": [ + { + "Variable": "$.Geometry", + "IsPresent": true, + "Next": "ParallelCheckOutputTextDetectionGeometry" + } + ], + "Default": "DefaultOutputTextDetectionGeometry" + }, + "ParallelCheckOutputTextDetectionGeometry": { + "Type": "Parallel", + "End": true, + "Branches": [ + { + "StartAt": "CheckOutputTextDetectionGeometryBoundingBox", + "States": { + "CheckOutputTextDetectionGeometryBoundingBox": { + "Type": "Choice", + "Choices": [ + { + "Variable": "$.BoundingBox", + "IsPresent": true, + "Next": "PassOutputTextDetectionGeometryBoundingBox" + } + ], + "Default": "DefaultOutputTextDetectionGeometryBoundingBox" + }, + "PassOutputTextDetectionGeometryBoundingBox": { + "Type": "Pass", + "End": true, + "InputPath": "$.BoundingBox" + }, + "DefaultOutputTextDetectionGeometryBoundingBox": { + "Type": "Pass", + "End": true, + "Parameters": { + "BoundingBox": null + }, + "OutputPath": "$.BoundingBox" + } + } + }, + { + "StartAt": "CheckOutputTextDetectionGeometryPolygon", + "States": { + "CheckOutputTextDetectionGeometryPolygon": { + "Type": "Choice", + "Choices": [ + { + "Variable": "$.Polygon", + "IsPresent": true, + "Next": "PassOutputTextDetectionGeometryPolygon" + } + ], + "Default": "DefaultOutputTextDetectionGeometryPolygon" + }, + "PassOutputTextDetectionGeometryPolygon": { + "Type": "Pass", + "End": true, + "InputPath": "$.Polygon" + }, + "DefaultOutputTextDetectionGeometryPolygon": { + "Type": "Pass", + "End": true, + "Parameters": { + "Polygon": null + }, + "OutputPath": "$.Polygon" + } + } + } + ], + "InputPath": "$.Geometry", + "ResultSelector": { + "BoundingBox.$": "$[0]", + "Polygon.$": "$[1]" + } + }, + "DefaultOutputTextDetectionGeometry": { + "Type": "Pass", + "End": true, + "Parameters": { + "Geometry": null + }, + "OutputPath": "$.Geometry" + } + } + }, + { + "StartAt": "CheckOutputTextDetectionId", + "States": { + "CheckOutputTextDetectionId": { + "Type": "Choice", + "Choices": [ + { + "Variable": "$.Id", + "IsPresent": true, + "Next": "PassOutputTextDetectionId" + } + ], + "Default": "DefaultOutputTextDetectionId" + }, + "PassOutputTextDetectionId": { + "Type": "Pass", + "End": true, + "InputPath": "$.Id" + }, + "DefaultOutputTextDetectionId": { + "Type": "Pass", + "End": true, + "Parameters": { + "Id": null + }, + "OutputPath": "$.Id" + } + } + }, + { + "StartAt": "CheckOutputTextDetectionParentId", + "States": { + "CheckOutputTextDetectionParentId": { + "Type": "Choice", + "Choices": [ + { + "Variable": "$.ParentId", + "IsPresent": true, + "Next": "PassOutputTextDetectionParentId" + } + ], + "Default": "DefaultOutputTextDetectionParentId" + }, + "PassOutputTextDetectionParentId": { + "Type": "Pass", + "End": true, + "InputPath": "$.ParentId" + }, + "DefaultOutputTextDetectionParentId": { + "Type": "Pass", + "End": true, + "Parameters": { + "ParentId": null + }, + "OutputPath": "$.ParentId" + } + } + }, + { + "StartAt": "CheckOutputTextDetectionType", + "States": { + "CheckOutputTextDetectionType": { + "Type": "Choice", + "Choices": [ + { + "Variable": "$.Type", + "IsPresent": true, + "Next": "PassOutputTextDetectionType" + } + ], + "Default": "DefaultOutputTextDetectionType" + }, + "PassOutputTextDetectionType": { + "Type": "Pass", + "End": true, + "InputPath": "$.Type" + }, + "DefaultOutputTextDetectionType": { + "Type": "Pass", + "End": true, + "Parameters": { + "Type": null + }, + "OutputPath": "$.Type" + } + } + } + ], + "ResultSelector": { + "Confidence.$": "$[0]", + "DetectedText.$": "$[1]", + "Geometry.$": "$[2]", + "Id.$": "$[3]", + "ParentId.$": "$[4]", + "Type.$": "$[5]" + } + } + } + }, + "ItemsPath": "$.TextDetections", + "End": true + } + } + }, + { + "StartAt": "CheckOutputTextModelVersion", + "States": { + "CheckOutputTextModelVersion": { + "Type": "Choice", + "Choices": [ + { + "Variable": "$.TextModelVersion", + "IsPresent": true, + "Next": "PassOutputTextModelVersion" + } + ], + "Default": "DefaultOutputTextModelVersion", + "InputPath": "$.Output" + }, + "DefaultOutputTextModelVersion": { + "Type": "Pass", + "Parameters": { + "TextModelVersion": null + }, + "OutputPath": "$.TextModelVersion", + "End": true + }, + "PassOutputTextModelVersion": { + "Type": "Pass", + "InputPath": "$.TextModelVersion", + "End": true + } + } + } + ], + "ResultSelector": { + "OrientationCorrection.$": "$[0]", + "TextDetections.$": "$[1]", + "TextModelVersion.$": "$[2]" + }, + "ResultPath": "$.Output", + "Next": "StateMachineOutput" + }, + "StateMachineOutput": { + "Type": "Pass", + "End": true, + "Parameters": { + "DetectText": { + "CreatedAt.$": "$$.Execution.StartTime", + "Id.$": "$.S3.Object.ETag", + "OrientationCorrection.$": "$.Output.OrientationCorrection", + "TextDetections.$": "$.Output.TextDetections", + "TextModelVersion.$": "$.Output.TextModelVersion" + }, + "Execution": { + "Id.$": "$$.Execution.Id", + "Name.$": "$$.Execution.Name", + "StartTime.$": "$$.Execution.StartTime" + }, + "S3.$": "$.S3", + "StateMachine.$": "$$.StateMachine" + } + }, + "FailDetectText": { + "Type": "Fail" + } + } +}