Show / Hide Table of Contents

Class RuleTargetInput

The input to send to the event target.

Inheritance
object
RuleTargetInput
LogGroupTargetInput
Namespace: Amazon.CDK.AWS.Events
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public abstract class RuleTargetInput : DeputyBase
Syntax (vb)
Public MustInherit Class RuleTargetInput Inherits DeputyBase
Remarks

This class abstracts over the three different ways CloudFormation lets you shape a target's input, so you do not have to choose between them yourself:

    You pick a factory method based on the shape you want the target to receive, and whether you reference EventField determines which of the above is synthesized. For example, fromObject({ foo: 'bar' }) produces a literal Input, while fromObject({ id: EventField.fromPath('$.detail.instance-id') }) produces an InputTransformer with the path lifted into InputPathsMap.

    ExampleMetadata: infused

    Examples
    Rule rule;
                 Topic topic;
    
    
                 // Without EventField this is a literal `Input`:
                 //   {"source":"my-app"}
                 rule.AddTarget(new SnsTopic(topic, new SnsTopicProps {
                     Message = RuleTargetInput.FromObject(new Dictionary<string, string> { { "source", "my-app" } })
                 }));
    
                 // Referencing the event inserts those fields from each matched event.
                 rule.AddTarget(new SnsTopic(topic, new SnsTopicProps {
                     Message = RuleTargetInput.FromObject(new Dictionary<string, string> {
                         { "instance", EventField.FromPath("$.detail.instance-id") },
                         { "state", EventField.FromPath("$.detail.state") }
                     })
                 }));

    Synopsis

    Constructors

    RuleTargetInput()

    The input to send to the event target.

    Methods

    Bind(IRuleRef)

    Return the input properties for this input object.

    FromEventPath(string)

    Take the event target input from a path in the event JSON.

    FromMultilineText(string)

    Pass text to the event target, splitting on newlines.

    FromObject(object)

    Pass a JSON object to the event target.

    FromText(string)

    Pass text to the event target.

    Constructors

    RuleTargetInput()

    The input to send to the event target.

    protected RuleTargetInput()
    Remarks

    This class abstracts over the three different ways CloudFormation lets you shape a target's input, so you do not have to choose between them yourself:

      You pick a factory method based on the shape you want the target to receive, and whether you reference EventField determines which of the above is synthesized. For example, fromObject({ foo: 'bar' }) produces a literal Input, while fromObject({ id: EventField.fromPath('$.detail.instance-id') }) produces an InputTransformer with the path lifted into InputPathsMap.

      ExampleMetadata: infused

      Examples
      Rule rule;
                   Topic topic;
      
      
                   // Without EventField this is a literal `Input`:
                   //   {"source":"my-app"}
                   rule.AddTarget(new SnsTopic(topic, new SnsTopicProps {
                       Message = RuleTargetInput.FromObject(new Dictionary<string, string> { { "source", "my-app" } })
                   }));
      
                   // Referencing the event inserts those fields from each matched event.
                   rule.AddTarget(new SnsTopic(topic, new SnsTopicProps {
                       Message = RuleTargetInput.FromObject(new Dictionary<string, string> {
                           { "instance", EventField.FromPath("$.detail.instance-id") },
                           { "state", EventField.FromPath("$.detail.state") }
                       })
                   }));

      Methods

      Bind(IRuleRef)

      Return the input properties for this input object.

      public abstract IRuleTargetInputProperties Bind(IRuleRef rule)
      Parameters
      rule IRuleRef
      Returns

      IRuleTargetInputProperties

      Remarks

      This class abstracts over the three different ways CloudFormation lets you shape a target's input, so you do not have to choose between them yourself:

        You pick a factory method based on the shape you want the target to receive, and whether you reference EventField determines which of the above is synthesized. For example, fromObject({ foo: 'bar' }) produces a literal Input, while fromObject({ id: EventField.fromPath('$.detail.instance-id') }) produces an InputTransformer with the path lifted into InputPathsMap.

        ExampleMetadata: infused

        FromEventPath(string)

        Take the event target input from a path in the event JSON.

        public static RuleTargetInput FromEventPath(string path)
        Parameters
        path string
        Returns

        RuleTargetInput

        Remarks

        This emits CloudFormation's InputPath directly, so the target receives only the selected fragment of the event. Use this when you want to forward part of the event unchanged; use fromObject() when you need to reshape it.

        FromMultilineText(string)

        Pass text to the event target, splitting on newlines.

        public static RuleTargetInput FromMultilineText(string text)
        Parameters
        text string
        Returns

        RuleTargetInput

        Remarks

        This is only useful when passing to a target that does not take a single argument.

        May contain strings returned by EventField.from() to substitute in parts of the matched event.

        As with fromText, each line is JSON-encoded, so every line is wrapped in double quotes in the synthesized template. Whether those quotes are visible to the recipient depends on the target service.

        FromObject(object)

        Pass a JSON object to the event target.

        public static RuleTargetInput FromObject(object obj)
        Parameters
        obj object
        Returns

        RuleTargetInput

        RuleTargetInput

        Remarks

        May contain strings returned by EventField.from() to substitute in parts of the matched event.

        Examples
        Rule rule;
                    Topic topic;
        
        
                    // Without EventField this is a literal `Input`:
                    //   {"source":"my-app"}
                    rule.AddTarget(new SnsTopic(topic, new SnsTopicProps {
                        Message = RuleTargetInput.FromObject(new Dictionary<string, string> { { "source", "my-app" } })
                    }));
        
                    // Referencing the event inserts those fields from each matched event.
                    rule.AddTarget(new SnsTopic(topic, new SnsTopicProps {
                        Message = RuleTargetInput.FromObject(new Dictionary<string, string> {
                            { "instance", EventField.FromPath("$.detail.instance-id") },
                            { "state", EventField.FromPath("$.detail.state") }
                        })
                    }));

        FromText(string)

        Pass text to the event target.

        public static RuleTargetInput FromText(string text)
        Parameters
        text string
        Returns

        RuleTargetInput

        Remarks

        May contain strings returned by EventField.from() to substitute in parts of the matched event.

        The Rule Target input value will be a single string: the string you pass here. Do not use this method to pass a complex value like a JSON object to a Rule Target. Use RuleTargetInput.fromObject() instead.

        The target Input field must be valid JSON, so the text is JSON-encoded when the template is synthesized. As a result a plain string is wrapped in double quotes: fromText('something') renders as Input: '"something"'. The quotes are part of the required JSON encoding, not an extra value added by CDK, and cannot be removed.

        Whether those quotes are visible to the recipient depends on the target service. Some targets deliver the JSON-encoded value as-is, so the recipient sees the surrounding quotes (for example, an SNS topic delivering to an email subscriber shows "something"). To send a structured payload, use RuleTargetInput.fromObject() instead.

        Back to top Generated by DocFX