Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add translate eventbridge #1447

Merged
merged 3 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;

namespace Amazon.Lambda.CloudWatchEvents.TranslateEvents
{
/// <summary>
/// This class represents the details of a Translate Parallel Data State Change
// for CreateParallelData and UpdateParallelData events sent via EventBridge.
/// For more see - https://docs.aws.amazon.com/translate/latest/dg/monitoring-with-eventbridge.html
/// </summary>
public class TranslateParallelDataStateChange
{
/// <summary>
/// The CreateParallelData/UpdateParallelData operation.
/// </summary>
public string Operation { get; set; }

/// <summary>
/// The CreateParallelData/UpdateParallelData name.
/// </summary>
public string Name { get; set; }

/// <summary>
/// The CreateParallelData/UpdateParallelData status.
/// </summary>
public string Status { get; set; }

/// <summary>
/// The UpdateParallelData latest update attempt status.
/// </summary>
public string LatestUpdateAttemptStatus { get; set; }

/// <summary>
/// The UpdateParallelData latest update attempt at.
/// </summary>
public DateTime LatestUpdateAttemptAt { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Amazon.Lambda.CloudWatchEvents.TranslateEvents
{
/// <summary>
/// This class represents a Translate Parallel Data State Change sent via EventBridge.
/// </summary>
public class TranslateParallelDataStateChangeEvent : CloudWatchEvent<TranslateParallelDataStateChange>{ }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace Amazon.Lambda.CloudWatchEvents.TranslateEvents
{
/// <summary>
/// This class represents the details of a Translate Text Translation Job State Change sent via EventBridge.
/// For more see - https://docs.aws.amazon.com/translate/latest/dg/monitoring-with-eventbridge.html
/// </summary>
public class TranslateTextTranslationJobStateChange
{
/// <summary>
/// The translation job id.
/// </summary>
public string JobId { get; set; }

/// <summary>
/// The translation job status.
/// </summary>
public string JobStatus { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Amazon.Lambda.CloudWatchEvents.TranslateEvents
{
/// <summary>
/// This class represents a Translate Text Translation Job State Change sent via EventBridge.
/// </summary>
public class TranslateTextTranslationJobStateChangeEvent : CloudWatchEvent<TranslateTextTranslationJobStateChange>{ }
}
68 changes: 68 additions & 0 deletions Libraries/test/EventsTests.Shared/EventTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Amazon.Lambda.Tests
using Amazon.Lambda.CloudWatchEvents.ECSEvents;
using Amazon.Lambda.CloudWatchEvents.ScheduledEvents;
using Amazon.Lambda.CloudWatchEvents.TranscribeEvents;
using Amazon.Lambda.CloudWatchEvents.TranslateEvents;
using Amazon.Lambda.CloudWatchLogsEvents;
using Amazon.Lambda.CognitoEvents;
using Amazon.Lambda.ConfigEvents;
Expand Down Expand Up @@ -3148,6 +3149,73 @@ public void CloudWatchTranscribeJobStateChangeFailed(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 CloudWatchTranslateTextTranslationJobStateChange(Type serializerType)
{
var serializer = Activator.CreateInstance(serializerType) as ILambdaSerializer;
using (var fileStream = LoadJsonTestFile("cloudwatchevents-translatetexttranslationjobstatechange.json"))
{
var request = serializer.Deserialize<TranslateTextTranslationJobStateChangeEvent>(fileStream);
Assert.Equal("8882c5af-c9da-4a58-99e2-91fbe33b9e52", request.Id);

var detail = request.Detail;
Assert.NotNull(detail);
Assert.Equal("8ce682a1-9be8-4f2c-875c-f8ae2fe1b015", detail.JobId);
Assert.Equal("COMPLETED", detail.JobStatus);
}
}

[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 CloudWatchTranslateParallelDataStateChangeCreate(Type serializerType)
{
var serializer = Activator.CreateInstance(serializerType) as ILambdaSerializer;
using (var fileStream = LoadJsonTestFile("cloudwatchevents-translateparalleldatastatechange-create.json"))
{
var request = serializer.Deserialize<TranslateParallelDataStateChangeEvent>(fileStream);
Assert.Equal("e99030f3-a7a8-42f5-923a-684fbf9bff65", request.Id);

var detail = request.Detail;
Assert.NotNull(detail);
Assert.Equal("CreateParallelData", detail.Operation);
Assert.Equal("ExampleParallelData", detail.Name);
Assert.Equal("ACTIVE", detail.Status);
}
}

[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 CloudWatchTranslateParallelDataStateChangeUpdate(Type serializerType)
{
var serializer = Activator.CreateInstance(serializerType) as ILambdaSerializer;
using (var fileStream = LoadJsonTestFile("cloudwatchevents-translateparalleldatastatechange-update.json"))
{
var request = serializer.Deserialize<TranslateParallelDataStateChangeEvent>(fileStream);
Assert.Equal("920d9de3-fbd0-4cfb-87aa-e35b5f7cba8f", request.Id);

var detail = request.Detail;
Assert.NotNull(detail);
Assert.Equal("UpdateParallelData", detail.Operation);
Assert.Equal("ExampleParallelData2", detail.Name);
Assert.Equal("ACTIVE", detail.Status);
Assert.Equal("ACTIVE", detail.LatestUpdateAttemptStatus);
Assert.Equal(DateTime.Parse("2023-03-02T03:31:47Z").ToUniversalTime(), detail.LatestUpdateAttemptAt);

}
}
class ClassUsingPascalCase
{
public int SomeValue { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": "0",
"id": "e99030f3-a7a8-42f5-923a-684fbf9bff65",
"detail-type": "Translate Parallel Data State Change",
"source": "aws.translate",
"account": "111122223333",
"time": "2017-04-22T03:31:47Z",
"region": "us-east-1",
"resources": [
"arn:aws:translate:us-east-1:111122223333:parallel-data/ExampleParallelData"
],
"detail": {
"operation": "CreateParallelData",
"name": "ExampleParallelData",
"status": "ACTIVE"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": "0",
"id": "920d9de3-fbd0-4cfb-87aa-e35b5f7cba8f",
"detail-type": "Translate Parallel Data State Change",
"source": "aws.translate",
"account": "111122223333",
"time": "2017-04-22T03:31:47Z",
"region": "us-east-1",
"resources": [
"arn:aws:translate:us-east-1:111122223333:parallel-data/ExampleParallelData"
],
"detail": {
"operation": "UpdateParallelData",
"name": "ExampleParallelData2",
"status": "ACTIVE",
"latestUpdateAttemptStatus": "ACTIVE",
"latestUpdateAttemptAt": "2023-03-02T03:31:47Z"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"version": "0",
"id": "8882c5af-c9da-4a58-99e2-91fbe33b9e52",
"detail-type": "Translate TextTranslationJob State Change",
"source": "aws.translate",
"account": "111122223333",
"time": "2017-04-22T03:31:47Z",
"region": "us-east-1",
"resources": [],
"detail": {
"jobId": "8ce682a1-9be8-4f2c-875c-f8ae2fe1b015",
"jobStatus": "COMPLETED"
}
}