Show / Hide Table of Contents

Class EventTarget

Provides a CloudWatch Event Target resource.

Example Usage

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
public MyStack()
{
    var console = new Aws.CloudWatch.EventRule("console", new Aws.CloudWatch.EventRuleArgs
    {
        Description = "Capture all EC2 scaling events",
        EventPattern = @"{
""source"": [
""aws.autoscaling""
],
""detail-type"": [
""EC2 Instance Launch Successful"",
""EC2 Instance Terminate Successful"",
""EC2 Instance Launch Unsuccessful"",
""EC2 Instance Terminate Unsuccessful""
]
}

",
    });
    var testStream = new Aws.Kinesis.Stream("testStream", new Aws.Kinesis.StreamArgs
    {
        ShardCount = 1,
    });
    var yada = new Aws.CloudWatch.EventTarget("yada", new Aws.CloudWatch.EventTargetArgs
    {
        Arn = testStream.Arn,
        Rule = console.Name,
        RunCommandTargets = 
        {
            new Aws.CloudWatch.Inputs.EventTargetRunCommandTargetArgs
            {
                Key = "tag:Name",
                Values = 
                {
                    "FooBar",
                },
            },
            new Aws.CloudWatch.Inputs.EventTargetRunCommandTargetArgs
            {
                Key = "InstanceIds",
                Values = 
                {
                    "i-162058cd308bffec2",
                },
            },
        },
    });
}

}

Example SSM Document Usage

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
public MyStack()
{
    var ssmLifecycleTrust = Output.Create(Aws.Iam.GetPolicyDocument.InvokeAsync(new Aws.Iam.GetPolicyDocumentArgs
    {
        Statements = 
        {
            new Aws.Iam.Inputs.GetPolicyDocumentStatementArgs
            {
                Actions = 
                {
                    "sts:AssumeRole",
                },
                Principals = 
                {
                    new Aws.Iam.Inputs.GetPolicyDocumentStatementPrincipalArgs
                    {
                        Identifiers = 
                        {
                            "events.amazonaws.com",
                        },
                        Type = "Service",
                    },
                },
            },
        },
    }));
    var stopInstance = new Aws.Ssm.Document("stopInstance", new Aws.Ssm.DocumentArgs
    {
        Content = @"  {
""schemaVersion"": ""1.2"",
""description"": ""Stop an instance"",
""parameters"": {

},
""runtimeConfig"": {
  ""aws:runShellScript"": {
    ""properties"": [
      {
        ""id"": ""0.aws:runShellScript"",
        ""runCommand"": [""halt""]
      }
    ]
  }
}
}

",
        DocumentType = "Command",
    });
    var ssmLifecyclePolicyDocument = stopInstance.Arn.Apply(arn => Aws.Iam.GetPolicyDocument.InvokeAsync(new Aws.Iam.GetPolicyDocumentArgs
    {
        Statements = 
        {
            new Aws.Iam.Inputs.GetPolicyDocumentStatementArgs
            {
                Actions = 
                {
                    "ssm:SendCommand",
                },
                Condition = 
                {

                    {
                        { "test", "StringEquals" },
                        { "values", 
                        {
                            "*",
                        } },
                        { "variable", "ec2:ResourceTag/Terminate" },
                    },
                },
                Effect = "Allow",
                Resources = 
                {
                    "arn:aws:ec2:eu-west-1:1234567890:instance/*",
                },
            },
            new Aws.Iam.Inputs.GetPolicyDocumentStatementArgs
            {
                Actions = 
                {
                    "ssm:SendCommand",
                },
                Effect = "Allow",
                Resources = 
                {
                    arn,
                },
            },
        },
    }));
    var ssmLifecycleRole = new Aws.Iam.Role("ssmLifecycleRole", new Aws.Iam.RoleArgs
    {
        AssumeRolePolicy = ssmLifecycleTrust.Apply(ssmLifecycleTrust => ssmLifecycleTrust.Json),
    });
    var ssmLifecyclePolicy = new Aws.Iam.Policy("ssmLifecyclePolicy", new Aws.Iam.PolicyArgs
    {
        Policy = ssmLifecyclePolicyDocument.Apply(ssmLifecyclePolicyDocument => ssmLifecyclePolicyDocument.Json),
    });
    var stopInstancesEventRule = new Aws.CloudWatch.EventRule("stopInstancesEventRule", new Aws.CloudWatch.EventRuleArgs
    {
        Description = "Stop instances nightly",
        ScheduleExpression = "cron(0 0 * * ? *)",
    });
    var stopInstancesEventTarget = new Aws.CloudWatch.EventTarget("stopInstancesEventTarget", new Aws.CloudWatch.EventTargetArgs
    {
        Arn = stopInstance.Arn,
        RoleArn = ssmLifecycleRole.Arn,
        Rule = stopInstancesEventRule.Name,
        RunCommandTargets = 
        {
            new Aws.CloudWatch.Inputs.EventTargetRunCommandTargetArgs
            {
                Key = "tag:Terminate",
                Values = 
                {
                    "midnight",
                },
            },
        },
    });
}

}

Example RunCommand Usage

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
public MyStack()
{
    var stopInstancesEventRule = new Aws.CloudWatch.EventRule("stopInstancesEventRule", new Aws.CloudWatch.EventRuleArgs
    {
        Description = "Stop instances nightly",
        ScheduleExpression = "cron(0 0 * * ? *)",
    });
    var stopInstancesEventTarget = new Aws.CloudWatch.EventTarget("stopInstancesEventTarget", new Aws.CloudWatch.EventTargetArgs
    {
        Arn = $"arn:aws:ssm:{@var.Aws_region}::document/AWS-RunShellScript",
        Input = "{\"commands\":[\"halt\"]}",
        RoleArn = aws_iam_role.Ssm_lifecycle.Arn,
        Rule = stopInstancesEventRule.Name,
        RunCommandTargets = 
        {
            new Aws.CloudWatch.Inputs.EventTargetRunCommandTargetArgs
            {
                Key = "tag:Terminate",
                Values = 
                {
                    "midnight",
                },
            },
        },
    });
}

}
Inheritance
System.Object
Resource
CustomResource
EventTarget
Inherited Members
CustomResource.Id
Resource.GetResourceType()
Resource.GetResourceName()
Resource.Urn
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Pulumi.Aws.CloudWatch
Assembly: Pulumi.Aws.dll
Syntax
public class EventTarget : CustomResource

Constructors

View Source

EventTarget(String, EventTargetArgs, CustomResourceOptions)

Create a EventTarget resource with the given unique name, arguments, and options.

Declaration
public EventTarget(string name, EventTargetArgs args, CustomResourceOptions options = null)
Parameters
Type Name Description
System.String name

The unique name of the resource

EventTargetArgs args

The arguments used to populate this resource's properties

CustomResourceOptions options

A bag of options that control this resource's behavior

Properties

View Source

Arn

The Amazon Resource Name (ARN) associated of the target.

Declaration
public Output<string> Arn { get; }
Property Value
Type Description
Output<System.String>
View Source

BatchTarget

Parameters used when you are using the rule to invoke an Amazon Batch Job. Documented below. A maximum of 1 are allowed.

Declaration
public Output<EventTargetBatchTarget> BatchTarget { get; }
Property Value
Type Description
Output<EventTargetBatchTarget>
View Source

EcsTarget

Parameters used when you are using the rule to invoke Amazon ECS Task. Documented below. A maximum of 1 are allowed.

Declaration
public Output<EventTargetEcsTarget> EcsTarget { get; }
Property Value
Type Description
Output<EventTargetEcsTarget>
View Source

Input

Valid JSON text passed to the target.

Declaration
public Output<string> Input { get; }
Property Value
Type Description
Output<System.String>
View Source

InputPath

The value of the JSONPath that is used for extracting part of the matched event when passing it to the target.

Declaration
public Output<string> InputPath { get; }
Property Value
Type Description
Output<System.String>
View Source

InputTransformer

Parameters used when you are providing a custom input to a target based on certain event data.

Declaration
public Output<EventTargetInputTransformer> InputTransformer { get; }
Property Value
Type Description
Output<EventTargetInputTransformer>
View Source

KinesisTarget

Parameters used when you are using the rule to invoke an Amazon Kinesis Stream. Documented below. A maximum of 1 are allowed.

Declaration
public Output<EventTargetKinesisTarget> KinesisTarget { get; }
Property Value
Type Description
Output<EventTargetKinesisTarget>
View Source

RoleArn

The Amazon Resource Name (ARN) of the IAM role to be used for this target when the rule is triggered. Required if ecs_target is used.

Declaration
public Output<string> RoleArn { get; }
Property Value
Type Description
Output<System.String>
View Source

Rule

The name of the rule you want to add targets to.

Declaration
public Output<string> Rule { get; }
Property Value
Type Description
Output<System.String>
View Source

RunCommandTargets

Parameters used when you are using the rule to invoke Amazon EC2 Run Command. Documented below. A maximum of 5 are allowed.

Declaration
public Output<ImmutableArray<EventTargetRunCommandTarget>> RunCommandTargets { get; }
Property Value
Type Description
Output<System.Collections.Immutable.ImmutableArray<EventTargetRunCommandTarget>>
View Source

SqsTarget

Parameters used when you are using the rule to invoke an Amazon SQS Queue. Documented below. A maximum of 1 are allowed.

Declaration
public Output<EventTargetSqsTarget> SqsTarget { get; }
Property Value
Type Description
Output<EventTargetSqsTarget>
View Source

TargetId

The unique target assignment ID. If missing, will generate a random, unique id.

Declaration
public Output<string> TargetId { get; }
Property Value
Type Description
Output<System.String>

Methods

View Source

Get(String, Input<String>, EventTargetState, CustomResourceOptions)

Get an existing EventTarget resource's state with the given name, ID, and optional extra properties used to qualify the lookup.

Declaration
public static EventTarget Get(string name, Input<string> id, EventTargetState state = null, CustomResourceOptions options = null)
Parameters
Type Name Description
System.String name

The unique name of the resulting resource.

Input<System.String> id

The unique provider ID of the resource to lookup.

EventTargetState state

Any extra arguments used during the lookup.

CustomResourceOptions options

A bag of options that control this resource's behavior

Returns
Type Description
EventTarget
  • View Source
Back to top Copyright 2016-2020, Pulumi Corporation.