diff --git a/Libraries/src/Amazon.Lambda.CloudWatchEvents/TranscribeEvents/TranscribeJobStateChange.cs b/Libraries/src/Amazon.Lambda.CloudWatchEvents/TranscribeEvents/TranscribeJobStateChange.cs new file mode 100644 index 000000000..76e61d555 --- /dev/null +++ b/Libraries/src/Amazon.Lambda.CloudWatchEvents/TranscribeEvents/TranscribeJobStateChange.cs @@ -0,0 +1,24 @@ +namespace Amazon.Lambda.CloudWatchEvents.TranscribeEvents +{ + /// + /// This class represents the details of a Transcribe Job State Change sent via EventBridge. + /// For more see - https://docs.aws.amazon.com/transcribe/latest/dg/monitoring-events.html + /// + public class TranscribeJobStateChange + { + /// + /// The transcription job name. + /// + public string TranscriptionJobName { get; set; } + + /// + /// The transcription job status. + /// + public string TranscriptionJobStatus { get; set; } + + /// + /// If the TranscriptionJobStatus is FAILED, this field contains information about the failure. + /// + public string FailureReason { get; set; } + } +} diff --git a/Libraries/src/Amazon.Lambda.CloudWatchEvents/TranscribeEvents/TranscribeJobStateChangeEvent.cs b/Libraries/src/Amazon.Lambda.CloudWatchEvents/TranscribeEvents/TranscribeJobStateChangeEvent.cs new file mode 100644 index 000000000..a3f843953 --- /dev/null +++ b/Libraries/src/Amazon.Lambda.CloudWatchEvents/TranscribeEvents/TranscribeJobStateChangeEvent.cs @@ -0,0 +1,7 @@ +namespace Amazon.Lambda.CloudWatchEvents.TranscribeEvents +{ + /// + /// This class represents a Transcribe Job State Change sent via EventBridge. + /// + public class TranscribeJobStateChangeEvent : CloudWatchEvent{ } +} diff --git a/Libraries/test/EventsTests.Shared/EventTests.cs b/Libraries/test/EventsTests.Shared/EventTests.cs index dbb1fe222..4f7d5e8ab 100644 --- a/Libraries/test/EventsTests.Shared/EventTests.cs +++ b/Libraries/test/EventsTests.Shared/EventTests.cs @@ -6,6 +6,7 @@ namespace Amazon.Lambda.Tests using Amazon.Lambda.CloudWatchEvents.BatchEvents; using Amazon.Lambda.CloudWatchEvents.ECSEvents; using Amazon.Lambda.CloudWatchEvents.ScheduledEvents; + using Amazon.Lambda.CloudWatchEvents.TranscribeEvents; using Amazon.Lambda.CloudWatchLogsEvents; using Amazon.Lambda.CognitoEvents; using Amazon.Lambda.ConfigEvents; @@ -3103,6 +3104,50 @@ public void CloudWatchEventsS3ObjectRestore(Type serializerType) } } + [Theory] + [InlineData(typeof(JsonSerializer))] +#if NETCOREAPP3_1_OR_GREATER + [InlineData(typeof(Amazon.Lambda.Serialization.SystemTextJson.LambdaJsonSerializer))] + [InlineData(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))] +#endif + public void CloudWatchTranscribeJobStateChangeCompleted(Type serializerType) + { + var serializer = Activator.CreateInstance(serializerType) as ILambdaSerializer; + using (var fileStream = LoadJsonTestFile("cloudwatchevents-transcribejobstatechangecompleted.json")) + { + var request = serializer.Deserialize(fileStream); + Assert.Equal("1de9a55a-39aa-d889-84eb-22d245492319", request.Id); + + var detail = request.Detail; + Assert.NotNull(detail); + Assert.Equal("51a3dfef-87fa-423a-8d3b-690ca9cae1f4", detail.TranscriptionJobName); + Assert.Equal("COMPLETED", detail.TranscriptionJobStatus); + Assert.Null(detail.FailureReason); + } + } + + [Theory] + [InlineData(typeof(JsonSerializer))] +#if NETCOREAPP3_1_OR_GREATER + [InlineData(typeof(Amazon.Lambda.Serialization.SystemTextJson.LambdaJsonSerializer))] + [InlineData(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))] +#endif + public void CloudWatchTranscribeJobStateChangeFailed(Type serializerType) + { + var serializer = Activator.CreateInstance(serializerType) as ILambdaSerializer; + using (var fileStream = LoadJsonTestFile("cloudwatchevents-transcribejobstatechangefailed.json")) + { + var request = serializer.Deserialize(fileStream); + Assert.Equal("5505f4fc-979b-0304-3570-8fa0e3c09525", request.Id); + + var detail = request.Detail; + Assert.NotNull(detail); + Assert.Equal("d43d0b58-2129-46ba-b2e2-b53ec9d1b210", detail.TranscriptionJobName); + Assert.Equal("FAILED", detail.TranscriptionJobStatus); + Assert.Equal("The media format that you specified doesn't match the detected media format. Check the media format and try your request again.", detail.FailureReason); + } + } + class ClassUsingPascalCase { public int SomeValue { get; set; } diff --git a/Libraries/test/EventsTests.Shared/cloudwatchevents-transcribejobstatechangecompleted.json b/Libraries/test/EventsTests.Shared/cloudwatchevents-transcribejobstatechangecompleted.json new file mode 100644 index 000000000..3014d6e53 --- /dev/null +++ b/Libraries/test/EventsTests.Shared/cloudwatchevents-transcribejobstatechangecompleted.json @@ -0,0 +1,14 @@ +{ + "version": "0", + "id": "1de9a55a-39aa-d889-84eb-22d245492319", + "detail-type": "Transcribe Job State Change", + "source": "aws.transcribe", + "account": "694977046108", + "time": "2023-02-24T15:46:21Z", + "region": "us-east-1", + "resources": [], + "detail": { + "TranscriptionJobName": "51a3dfef-87fa-423a-8d3b-690ca9cae1f4", + "TranscriptionJobStatus": "COMPLETED" + } +} \ No newline at end of file diff --git a/Libraries/test/EventsTests.Shared/cloudwatchevents-transcribejobstatechangefailed.json b/Libraries/test/EventsTests.Shared/cloudwatchevents-transcribejobstatechangefailed.json new file mode 100644 index 000000000..1d5ab8c5d --- /dev/null +++ b/Libraries/test/EventsTests.Shared/cloudwatchevents-transcribejobstatechangefailed.json @@ -0,0 +1,15 @@ +{ + "version": "0", + "id": "5505f4fc-979b-0304-3570-8fa0e3c09525", + "detail-type": "Transcribe Job State Change", + "source": "aws.transcribe", + "account": "694977046108", + "time": "2023-02-24T15:42:10Z", + "region": "us-east-1", + "resources": [], + "detail": { + "TranscriptionJobName": "d43d0b58-2129-46ba-b2e2-b53ec9d1b210", + "TranscriptionJobStatus": "FAILED", + "FailureReason": "The media format that you specified doesn't match the detected media format. Check the media format and try your request again." + } +} \ No newline at end of file