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

Ecs events #327

Merged
merged 11 commits into from
Feb 7, 2019
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
7 changes: 7 additions & 0 deletions Libraries/Libraries.sln
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PowerShellTests", "test\Pow
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PowerShellScriptsAsFunctions", "test\TestPowerShellFunctions\PowerShellScriptsAsFunctions\PowerShellScriptsAsFunctions.csproj", "{0AD1E5D6-AC23-47C1-97BF-227007021B6F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Amazon.Lambda.CloudWatchEvents", "src\Amazon.Lambda.CloudWatchEvents\Amazon.Lambda.CloudWatchEvents.csproj", "{AD96AA48-2E1A-4BBB-9329-E1E484172FE3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -203,6 +205,10 @@ Global
{0AD1E5D6-AC23-47C1-97BF-227007021B6F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0AD1E5D6-AC23-47C1-97BF-227007021B6F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0AD1E5D6-AC23-47C1-97BF-227007021B6F}.Release|Any CPU.Build.0 = Release|Any CPU
{AD96AA48-2E1A-4BBB-9329-E1E484172FE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AD96AA48-2E1A-4BBB-9329-E1E484172FE3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AD96AA48-2E1A-4BBB-9329-E1E484172FE3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AD96AA48-2E1A-4BBB-9329-E1E484172FE3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -240,6 +246,7 @@ Global
{ADEC039D-0C34-4DA7-802B-6204FFE3F1F5} = {1DE4EE60-45BA-4EF7-BE00-B9EB861E4C69}
{997B1047-4361-4E6D-9850-F130EC188141} = {1DE4EE60-45BA-4EF7-BE00-B9EB861E4C69}
{0AD1E5D6-AC23-47C1-97BF-227007021B6F} = {ADEC039D-0C34-4DA7-802B-6204FFE3F1F5}
{AD96AA48-2E1A-4BBB-9329-E1E484172FE3} = {AAB54E74-20B1-42ED-BC3D-CE9F7BC7FD12}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {503678A4-B8D1-4486-8915-405A3E9CF0EB}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="..\..\..\buildtools\common.props" />

<PropertyGroup>
<TargetFramework>netstandard1.3</TargetFramework>
<NetStandardImplicitPackageVersion>1.6.0</NetStandardImplicitPackageVersion>
<Description>Amazon Lambda .NET Core support - CloudWatchEvents package.</Description>
<AssemblyTitle>Amazon.Lambda.CloudWatchEvents</AssemblyTitle>
<VersionPrefix>1.0.0</VersionPrefix>
<AssemblyName>Amazon.Lambda.CloudWatchEvents</AssemblyName>
<PackageId>Amazon.Lambda.CloudWatchEvents</PackageId>
<PackageTags>AWS;Amazon;Lambda</PackageTags>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Runtime" Version="4.1.0" />
</ItemGroup>

</Project>
77 changes: 77 additions & 0 deletions Libraries/src/Amazon.Lambda.CloudWatchEvents/CloudWatchEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
namespace Amazon.Lambda.CloudWatchEvents
{
using System;
using System.Collections.Generic;

/// <summary>
/// AWS CloudWatch event
/// The contents of the detail top-level field are different depending on which service generated the event and what the event is.
/// The combination of the source and detail-type fields serves to identify the fields and values found in the detail field.
/// Complete list of events that inherit this interface: https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/EventTypes.html
/// https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/CloudWatchEventsandEventPatterns.html
/// https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/EventTypes.html
/// </summary>
public class CloudWatchEvent<T>
{
/// <summary>
/// By default, this is set to 0 (zero) in all events.
/// </summary>
public string Version { get; set; }

/// <summary>
/// The 12-digit number identifying an AWS account.
/// </summary>
public string Account { get; set; }

/// <summary>
/// Identifies the AWS region where the event originated.
/// </summary>
public string Region { get; set; }

/// <summary>
/// A JSON object, whose content is at the discretion of the service originating the event.
/// The detail content in the example above is very simple, just two fields.
/// AWS API call events have detail objects with around 50 fields nested several levels deep.
/// </summary>
public T Detail { get; set; }

/// <summary>
/// Identifies, in combination with the source field, the fields and values that appear in the detail field.
/// For example, ScheduledEvent will be null
/// For example, ECSEvent could be "ECS Container Instance State Change" or "ECS Task State Change"
/// </summary>
public string DetailType { get; set; }

/// <summary>
/// Identifies the service that sourced the event.
/// All events sourced from within AWS begin with "aws."
/// Customer-generated events can have any value here, as long as it doesn't begin with "aws."
/// We recommend the use of Java package-name style reverse domain-name strings.
/// For example, ScheduledEvent will be "aws.events"
/// For example, ECSEvent will be "aws.ecs"
/// </summary>
public string Source { get; set; }

/// <summary>
/// The event timestamp, which can be specified by the service originating the event.
/// If the event spans a time interval, the service might choose to report the start time,
/// so this value can be noticeably before the time the event is actually received.
/// </summary>
public DateTime Time { get; set; }

/// <summary>
/// A unique value is generated for every event.
/// This can be helpful in tracing events as they move through rules to targets, and are processed.
/// </summary>
public string Id { get; set; }

/// <summary>
/// This JSON array contains ARNs that identify resources that are involved in the event.
/// Inclusion of these ARNs is at the discretion of the service.
/// For example, Amazon EC2 instance state-changes include Amazon EC2 instance ARNs, Auto Scaling events
/// include ARNs for both instances and Auto Scaling groups, but API calls with AWS CloudTrail do not
/// include resource ARNs.
/// </summary>
public List<string> Resources { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Collections.Generic;

namespace Amazon.Lambda.CloudWatchEvents.ECSEvents
{
/// <summary>
/// An object representing a container instance or task attachment.
/// https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_Attachment.html
/// </summary>
public class Attachment
{
/// <summary>
/// Details of the attachment. For elastic network interfaces, this includes the
/// network interface ID, the MAC address, the subnet ID, and the private IPv4 address.
/// </summary>
public List<KeyValuePair<string, string>> Details { get; set; }

/// <summary>
/// The unique identifier for the attachment.
/// </summary>
public string Id { get; set; }

/// <summary>
/// The status of the attachment. Valid values are PRECREATED, CREATED, ATTACHING,
/// ATTACHED, DETACHING, DETACHED, and DELETED.
/// </summary>
public string Status { get; set; }

/// <summary>
/// The type of the attachment, such as ElasticNetworkInterface.
/// </summary>
public string Type { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Amazon.Lambda.CloudWatchEvents.ECSEvents
{
/// <summary>
/// https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ContainerInstance.html
/// </summary>
public class Attribute
{
/// <summary>
/// The attributes set for the container instance, either by the Amazon ECS container agent at instance
/// registration or manually with the PutAttributes operation.
/// </summary>
public string Name { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Amazon.Lambda.CloudWatchEvents.ECSEvents
{
/// <summary>
/// A Docker container that is part of a task.
/// https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_Container.html
/// </summary>
public class Container
{
/// <summary>
/// The Amazon Resource Name (ARN) of the container.
/// </summary>
public string ContainerArn { get; set; }

/// <summary>
/// The exit code returned from the container.
/// </summary>
public int ExitCode { get; set; }

/// <summary>
/// The last known status of the container.
/// </summary>
public string LastStatus { get; set; }

/// <summary>
/// The name of the container.
/// </summary>
public string Name { get; set; }

/// <summary>
/// The ARN of the task.
/// </summary>
public string TaskArn { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
using System;
using System.Collections.Generic;

namespace Amazon.Lambda.CloudWatchEvents.ECSEvents
{
/// <summary>
/// An EC2 instance that is running the Amazon ECS agent and has been registered with a cluster.
/// https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ContainerInstance.html
/// </summary>
public class ContainerInstance
{
/// <summary>
/// This parameter returns true if the agent is connected to Amazon ECS.
/// Registered instances with an agent that may be unhealthy or stopped return false. Instances without
/// a connected agent can't accept placement requests.
/// </summary>
public bool AgentConnected { get; set; }

/// <summary>
/// The status of the most recent agent update. If an update has never been requested, this value is NULL.
/// </summary>
public string AgentUpdateStatus { get; set; }

/// <summary>
/// The elastic network interfaces associated with the container instance.
/// </summary>
public List<Attachment> Attachments { get; set; }

/// <summary>
/// The attributes set for the container instance, either by the Amazon ECS container agent at instance
/// registration or manually with the PutAttributes operation.
/// </summary>
public List<Attribute> Attributes { get; set; }

/// <summary>
/// The Amazon Resource Name (ARN) of the container instance.
/// The ARN contains the arn:aws:ecs namespace, followed by the region of the container instance,
/// the AWS account ID of the container instance owner, the container-instance namespace,
/// and then the container instance ID.
/// </summary>
public string ContainerInstanceArn { get; set; }

/// <summary>
/// The EC2 instance ID of the container instance.
/// </summary>
public string Ec2InstanceId { get; set; }

/// <summary>
/// The number of tasks on the container instance that are in the PENDING status.
/// </summary>
public int PendingTasksCount { get; set; }

/// <summary>
/// The Unix time stamp for when the container instance was registered.
/// </summary>
public DateTime RegisteredAt { get; set; }

/// <summary>
/// For CPU and memory resource types, this parameter describes the amount of each resource that was available
/// on the container instance when the container agent registered it with Amazon ECS; this value represents
/// the total amount of CPU and memory that can be allocated on this container instance to tasks.
/// For port resource types, this parameter describes the ports that were reserved by the Amazon ECS container
/// agent when it registered the container instance with Amazon ECS.
/// </summary>
public List<Resource> RegisteredResources { get; set; }

/// <summary>
/// For CPU and memory resource types, this parameter describes the remaining CPU and memory that has not
/// already been allocated to tasks and is therefore available for new tasks.
/// For port resource types, this parameter describes the ports that were reserved by the Amazon ECS
/// container agent (at instance registration time) and any task containers that have reserved port mappings
/// on the host (with the host or bridge network mode).
/// Any port that is not specified here is available for new tasks.
/// </summary>
public List<Resource> RemainingResources { get; set; }

/// <summary>
/// The number of tasks on the container instance that are in the RUNNING status.
/// </summary>
public int RunningTasksCount { get; set; }

/// <summary>
/// The status of the container instance.
/// The valid values are ACTIVE, INACTIVE, or DRAINING. ACTIVE indicates that the container instance
/// can accept tasks.
/// DRAINING indicates that new tasks are not placed on the container instance and any service tasks
/// running on the container instance are removed if possible.
/// </summary>
public string Status { get; set; }

/// <summary>
/// The version counter for the container instance.
/// Every time a container instance experiences a change that triggers a CloudWatch event,
/// the version counter is incremented. If you are replicating your Amazon ECS container instance
/// state with CloudWatch Events, you can compare the version of a container instance reported by
/// the Amazon ECS APIs with the version reported in CloudWatch Events for the container instance
/// (inside the detail object) to verify that the version in your event stream is current.
/// </summary>
public long Version { get; set; }

/// <summary>
/// The version information for the Amazon ECS container agent and Docker daemon running on the container instance.
/// </summary>
public VersionInfo VersionInfo { get; set; }

// NOTE: The following properties are not present in the ContainerInstance object documentation but have
// been added here for convenience.

/// <summary>
/// The Amazon Resource Name (ARN) of the cluster that hosts the service.
/// </summary>
public string ClusterArn { get; set; }

/// <summary>
/// The Unix time stamp for when the service was last updated.
/// </summary>
public DateTime UpdatedAt { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Amazon.Lambda.CloudWatchEvents.ECSEvents
{
/// <summary>
/// The overrides that should be sent to a container.
/// https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ContainerOverride.html
/// </summary>
public class ContainerOverride
{
/// <summary>
/// The command to send to the container that overrides the default command from
/// the Docker image or the task definition. You must also specify a container name.
/// </summary>
public List<string> Command { get; set; }

/// <summary>
/// The number of cpu units reserved for the container, instead of the default value
/// from the task definition. You must also specify a container name.
/// </summary>
public int Cpu { get; set; }

/// <summary>
/// The environment variables to send to the container. You can add new environment variables,
/// which are added to the container at launch, or you can override the existing environment
/// variables from the Docker image or the task definition. You must also specify a container name.
/// </summary>
public List<KeyValuePair<string, string>> Environment { get; set; }

/// <summary>
/// The hard limit (in MiB) of memory to present to the container, instead of the default value
/// from the task definition. If your container attempts to exceed the memory specified here,
/// the container is killed. You must also specify a container name.
/// </summary>
public int Memory { get; set; }

/// <summary>
/// The soft limit (in MiB) of memory to reserve for the container, instead of the default value
/// from the task definition. You must also specify a container name.
/// </summary>
public int MemoryReservation { get; set; }

/// <summary>
/// The name of the container that receives the override.
/// This parameter is required if any override is specified.
/// </summary>
public string Name { get; set; }
}
}
Loading