Skip to content

Commit 2caecf0

Browse files
committed
KAL-9 Add support for job state change events.
1 parent d8d77be commit 2caecf0

17 files changed

+548
-1
lines changed

Libraries/src/Amazon.Lambda.CloudWatchEvents/Amazon.Lambda.CloudWatchEvents.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,10 @@
1717
<PackageReference Include="System.Runtime" Version="4.1.0" />
1818
</ItemGroup>
1919

20+
<ItemGroup>
21+
<Reference Include="Newtonsoft.Json">
22+
<HintPath>..\..\..\..\..\Program Files\dotnet\sdk\NuGetFallbackFolder\newtonsoft.json\10.0.1\lib\netstandard1.3\Newtonsoft.Json.dll</HintPath>
23+
</Reference>
24+
</ItemGroup>
25+
2026
</Project>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Collections.Generic;
2+
3+
namespace Amazon.Lambda.CloudWatchEvents.BatchEvents
4+
{
5+
/// <summary>
6+
/// An object representing the array properties of a job.
7+
/// https://docs.aws.amazon.com/batch/latest/APIReference/API_ArrayPropertiesDetail.html
8+
/// </summary>
9+
public class ArrayPropertiesDetail
10+
{
11+
/// <summary>
12+
/// The job index within the array that is associated with this job.
13+
/// This parameter is returned for array job children.
14+
/// </summary>
15+
public int Index { get; set; }
16+
17+
/// <summary>
18+
/// The size of the array job. This parameter is returned for parent array jobs.
19+
/// </summary>
20+
public int Size { get; set; }
21+
22+
/// <summary>
23+
/// A summary of the number of array job children in each available job status.
24+
/// This parameter is returned for parent array jobs.
25+
/// </summary>
26+
public Dictionary<string, int> StatusSummary { get; set; }
27+
}
28+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
namespace Amazon.Lambda.CloudWatchEvents.BatchEvents
2+
{
3+
/// <summary>
4+
/// An object representing the details of a container that is part of a job attempt.
5+
/// https://docs.aws.amazon.com/batch/latest/APIReference/API_AttemptContainerDetail.html
6+
/// </summary>
7+
public class AttemptContainerDetail
8+
{
9+
/// <summary>
10+
/// The Amazon Resource Name (ARN) of the Amazon ECS container instance that hosts the job attempt.
11+
/// </summary>
12+
public string ContainerInstanceArn { get; set; }
13+
14+
/// <summary>
15+
/// The exit code for the job attempt. A non-zero exit code is considered a failure.
16+
/// </summary>
17+
public int ExitCode { get; set; }
18+
19+
/// <summary>
20+
/// The name of the CloudWatch Logs log stream associated with the container. The log group for
21+
/// AWS Batch jobs is /aws/batch/job. Each container attempt receives a log stream name when
22+
/// they reach the RUNNING status.
23+
/// </summary>
24+
public string LogStreamName { get; set; }
25+
26+
/// <summary>
27+
/// A short (255 max characters) human-readable string to provide additional
28+
/// details about a running or stopped container.
29+
/// </summary>
30+
public string Reason { get; set; }
31+
32+
/// <summary>
33+
/// The Amazon Resource Name (ARN) of the Amazon ECS task that is associated with the job attempt.
34+
/// Each container attempt receives a task ARN when they reach the STARTING status.
35+
/// </summary>
36+
public string TaskArn { get; set; }
37+
}
38+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
namespace Amazon.Lambda.CloudWatchEvents.BatchEvents
2+
{
3+
/// <summary>
4+
/// An object representing a job attempt.
5+
/// https://docs.aws.amazon.com/batch/latest/APIReference/API_AttemptDetail.html
6+
/// </summary>
7+
public class AttemptDetail
8+
{
9+
/// <summary>
10+
/// Details about the container in this job attempt.
11+
/// </summary>
12+
public AttemptContainerDetail Container { get; set; }
13+
14+
/// <summary>
15+
/// The Unix time stamp (in seconds and milliseconds) for when the attempt was started
16+
/// (when the attempt transitioned from the STARTING state to the RUNNING state).
17+
/// </summary>
18+
public long StartedAt { get; set; }
19+
20+
/// <summary>
21+
/// A short, human-readable string to provide additional details about the current status of the job attempt.
22+
/// </summary>
23+
public string StatusReason { get; set; }
24+
25+
/// <summary>
26+
/// The Unix time stamp (in seconds and milliseconds) for when the attempt was stopped
27+
/// (when the attempt transitioned from the RUNNING state to a terminal state, such as SUCCEEDED or FAILED).
28+
/// </summary>
29+
public long StoppedAt { get; set; }
30+
}
31+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Amazon.Lambda.CloudWatchEvents.BatchEvents
2+
{
3+
/// <summary>
4+
/// AWS Batch Event
5+
/// https://docs.aws.amazon.com/batch/latest/userguide/batch_cwe_events.html
6+
/// </summary>
7+
public class BatchJobStateChangeEvent : CloudWatchEvent<Job>
8+
{
9+
10+
}
11+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
using System.Collections.Generic;
2+
3+
namespace Amazon.Lambda.CloudWatchEvents.BatchEvents
4+
{
5+
/// <summary>
6+
/// An object representing the details of a container that is part of a job.
7+
/// https://docs.aws.amazon.com/batch/latest/APIReference/API_ContainerDetail.html
8+
/// </summary>
9+
public class ContainerDetail
10+
{
11+
/// <summary>
12+
/// The command that is passed to the container.
13+
/// </summary>
14+
public List<string> Command { get; set; }
15+
16+
/// <summary>
17+
/// The Amazon Resource Name (ARN) of the container instance on which the container is running.
18+
/// </summary>
19+
public string ContainerInstanceArn { get; set; }
20+
21+
/// <summary>
22+
/// The environment variables to pass to a container.
23+
/// Note: Environment variables must not start with AWS_BATCH; this naming convention is reserved
24+
/// for variables that are set by the AWS Batch service.
25+
/// </summary>
26+
public List<KeyValuePair<string, string>> Environment { get; set; }
27+
28+
/// <summary>
29+
/// The exit code to return upon completion.
30+
/// </summary>
31+
public int ExitCode { get; set; }
32+
33+
/// <summary>
34+
/// The image used to start the container.
35+
/// </summary>
36+
public string Image { get; set; }
37+
38+
/// <summary>
39+
/// The Amazon Resource Name (ARN) associated with the job upon execution.
40+
/// </summary>
41+
public string JobRoleArn { get; set; }
42+
43+
/// <summary>
44+
/// The name of the CloudWatch Logs log stream associated with the container.
45+
/// The log group for AWS Batch jobs is /aws/batch/job. Each container attempt receives a
46+
/// log stream name when they reach the RUNNING status.
47+
/// </summary>
48+
public string LogStreamName { get; set; }
49+
50+
/// <summary>
51+
/// The number of MiB of memory reserved for the job.
52+
/// </summary>
53+
public int Memory { get; set; }
54+
55+
/// <summary>
56+
/// The mount points for data volumes in your container.
57+
/// </summary>
58+
public List<MountPoint> MountPoints { get; set; }
59+
60+
/// <summary>
61+
/// When this parameter is true, the container is given elevated privileges on the
62+
/// host container instance (similar to the root user).
63+
/// </summary>
64+
public bool Privileged { get; set; }
65+
66+
/// <summary>
67+
/// When this parameter is true, the container is given read-only access to its root file system.
68+
/// </summary>
69+
public bool ReadonlyRootFilesystem { get; set; }
70+
71+
/// <summary>
72+
/// A short (255 max characters) human-readable string to provide additional
73+
/// details about a running or stopped container.
74+
/// </summary>
75+
public string Reason { get; set; }
76+
77+
/// <summary>
78+
/// The Amazon Resource Name (ARN) of the Amazon ECS task that is associated with the container job.
79+
/// Each container attempt receives a task ARN when they reach the STARTING status.
80+
/// </summary>
81+
public string TaskArn { get; set; }
82+
83+
/// <summary>
84+
/// A list of ulimit values to set in the container.
85+
/// </summary>
86+
public List<Ulimit> Ulimits { get; set; }
87+
88+
/// <summary>
89+
/// The user name to use inside the container.
90+
/// </summary>
91+
public string User { get; set; }
92+
93+
/// <summary>
94+
/// The number of VCPUs allocated for the job.
95+
/// </summary>
96+
public int Vcpus { get; set; }
97+
98+
/// <summary>
99+
/// A list of volumes associated with the job.
100+
/// </summary>
101+
public List<Volume> Volumes { get; set; }
102+
}
103+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace Amazon.Lambda.CloudWatchEvents.BatchEvents
2+
{
3+
/// <summary>
4+
/// The contents of the host parameter determine whether your data volume persists on the host container
5+
/// instance and where it is stored. If the host parameter is empty, then the Docker daemon assigns a host
6+
/// path for your data volume, but the data is not guaranteed to persist after the containers associated with
7+
/// it stop running.
8+
/// https://docs.aws.amazon.com/batch/latest/APIReference/API_Host.html
9+
/// </summary>
10+
public class Host
11+
{
12+
/// <summary>
13+
/// The path on the host container instance that is presented to the container. If this parameter is empty,
14+
/// then the Docker daemon has assigned a host path for you. If the host parameter contains a sourcePath file
15+
/// location, then the data volume persists at the specified location on the host container instance until you
16+
/// delete it manually. If the sourcePath value does not exist on the host container instance, the Docker
17+
/// daemon creates it. If the location does exist, the contents of the source path folder are exported.
18+
/// </summary>
19+
public string SourcePath { get; set; }
20+
}
21+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
using System.Collections.Generic;
2+
3+
namespace Amazon.Lambda.CloudWatchEvents.BatchEvents
4+
{
5+
/// <summary>
6+
/// https://docs.aws.amazon.com/batch/latest/userguide/batch_cwe_events.html
7+
/// https://docs.aws.amazon.com/batch/latest/APIReference/API_JobDetail.html
8+
/// https://docs.aws.amazon.com/batch/latest/APIReference/API_DescribeJobs.html
9+
/// </summary>
10+
public class Job
11+
{
12+
/// <summary>
13+
/// The array properties of the job, if it is an array job.
14+
/// </summary>
15+
public ArrayPropertiesDetail ArrayProperties { get; set; }
16+
17+
/// <summary>
18+
/// A list of job attempts associated with this job.
19+
/// </summary>
20+
public List<AttemptDetail> Attempts { get; set; }
21+
22+
/// <summary>
23+
/// An object representing the details of the container that is associated with the job.
24+
/// </summary>
25+
public ContainerDetail Container { get; set; }
26+
27+
/// <summary>
28+
/// The Unix time stamp (in seconds and milliseconds) for when the job was created. For non-array
29+
/// jobs and parent array jobs, this is when the job entered the SUBMITTED state
30+
/// (at the time SubmitJob was called). For array child jobs, this is when the child job was
31+
/// spawned by its parent and entered the PENDING state.
32+
/// </summary>
33+
public long CreatedAt { get; set; }
34+
35+
/// <summary>
36+
/// A list of job names or IDs on which this job depends.
37+
/// </summary>
38+
public List<JobDependency> DependsOn { get; set; }
39+
40+
/// <summary>
41+
/// The job definition that is used by this job.
42+
/// </summary>
43+
public string JobDefinition { get; set; }
44+
45+
/// <summary>
46+
/// The ID for the job.
47+
/// </summary>
48+
public string JobId { get; set; }
49+
50+
/// <summary>
51+
/// The name of the job.
52+
/// </summary>
53+
public string JobName { get; set; }
54+
55+
/// <summary>
56+
/// The Amazon Resource Name (ARN) of the job queue with which the job is associated.
57+
/// </summary>
58+
public string JobQueue { get; set; }
59+
60+
/// <summary>
61+
/// Additional parameters passed to the job that replace parameter substitution placeholders or
62+
/// override any corresponding parameter defaults from the job definition.
63+
/// </summary>
64+
public Dictionary<string, string> Parameters { get; set; }
65+
66+
/// <summary>
67+
/// The retry strategy to use for this job if an attempt fails.
68+
/// </summary>
69+
public RetryStrategy RetryStrategy { get; set; }
70+
71+
/// <summary>
72+
/// The Unix time stamp (in seconds and milliseconds) for when the job was started (when the job
73+
/// transitioned from the STARTING state to the RUNNING state).
74+
/// </summary>
75+
public long StartedAt { get; set; }
76+
77+
/// <summary>
78+
/// The current status for the job. Note: If your jobs do not progress to STARTING, see Jobs Stuck
79+
/// in RUNNABLE Status in the troubleshooting section of the AWS Batch User Guide.
80+
/// </summary>
81+
public string Status { get; set; }
82+
83+
/// <summary>
84+
/// A short, human-readable string to provide additional details about the current status of the job.
85+
/// </summary>
86+
public string StatusReason { get; set; }
87+
88+
/// <summary>
89+
/// The Unix time stamp (in seconds and milliseconds) for when the job was stopped (when the
90+
/// job transitioned from the RUNNING state to a terminal state, such as SUCCEEDED or FAILED).
91+
/// </summary>
92+
public long StoppedAt { get; set; }
93+
94+
/// <summary>
95+
/// The timeout configuration for the job.
96+
/// </summary>
97+
public JobTimeout Timeout { get; set; }
98+
}
99+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace Amazon.Lambda.CloudWatchEvents.BatchEvents
2+
{
3+
/// <summary>
4+
/// An object representing an AWS Batch job dependency.
5+
/// https://docs.aws.amazon.com/batch/latest/APIReference/API_JobDependency.html
6+
/// </summary>
7+
public class JobDependency
8+
{
9+
/// <summary>
10+
/// The job ID of the AWS Batch job associated with this dependency.
11+
/// </summary>
12+
public string JobId { get; set; }
13+
14+
/// <summary>
15+
/// The type of the job dependency.
16+
/// </summary>
17+
public string Type { get; set; }
18+
}
19+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace Amazon.Lambda.CloudWatchEvents.BatchEvents
2+
{
3+
/// <summary>
4+
/// An object representing a job timeout configuration.
5+
/// https://docs.aws.amazon.com/batch/latest/APIReference/API_JobTimeout.html
6+
/// </summary>
7+
public class JobTimeout
8+
{
9+
/// <summary>
10+
/// The time duration in seconds (measured from the job attempt's startedAt timestamp) after which
11+
/// AWS Batch terminates your jobs if they have not finished.
12+
/// </summary>
13+
public int AttemptDurationSeconds { get; set; }
14+
}
15+
}

0 commit comments

Comments
 (0)