RuleTargetInput
- class aws_cdk.aws_events.RuleTargetInput
Bases:
objectThe input to send to the event target.
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:
Input- a literal value, emitted when the input does not reference the event.InputPath- a single JSONPath into the event, emitted byfromEventPath().InputTransformer- anInputPathsMapplus anInputTemplate, emitted automatically when the input references parts of the event viaEventField.
You pick a factory method based on the shape you want the target to receive, and whether you reference
EventFielddetermines which of the above is synthesized. For example,fromObject({ foo: 'bar' })produces a literalInput, whilefromObject({ id: EventField.fromPath('$.detail.instance-id') })produces anInputTransformerwith the path lifted intoInputPathsMap.- ExampleMetadata:
infused
Example:
# rule: events.Rule # topic: sns.Topic # Without EventField this is a literal `Input`: # {"source":"my-app"} rule.add_target(targets.SnsTopic(topic, message=events.RuleTargetInput.from_object({"source": "my-app"}) )) # Referencing the event inserts those fields from each matched event. rule.add_target(targets.SnsTopic(topic, message=events.RuleTargetInput.from_object({ "instance": events.EventField.from_path("$.detail.instance-id"), "state": events.EventField.from_path("$.detail.state") }) ))
Methods
- abstractmethod bind(rule)
Return the input properties for this input object.
- Parameters:
rule (
IRuleRef)- Return type:
Static Methods
- classmethod from_event_path(path)
Take the event target input from a path in the event JSON.
This emits CloudFormation’s
InputPathdirectly, so the target receives only the selected fragment of the event. Use this when you want to forward part of the event unchanged; usefromObject()when you need to reshape it.- Parameters:
path (
str)- Return type:
- classmethod from_multiline_text(text)
Pass text to the event target, splitting on newlines.
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.- Parameters:
text (
str)- Return type:
- classmethod from_object(obj)
Pass a JSON object to the event target.
May contain strings returned by
EventField.from()to substitute in parts of the matched event.- Parameters:
obj (
Any)- Return type:
- Returns:
RuleTargetInput
Example:
# rule: events.Rule # topic: sns.Topic # Without EventField this is a literal `Input`: # {"source":"my-app"} rule.add_target(targets.SnsTopic(topic, message=events.RuleTargetInput.from_object({"source": "my-app"}) )) # Referencing the event inserts those fields from each matched event. rule.add_target(targets.SnsTopic(topic, message=events.RuleTargetInput.from_object({ "instance": events.EventField.from_path("$.detail.instance-id"), "state": events.EventField.from_path("$.detail.state") }) ))
- classmethod from_text(text)
Pass text to the event target.
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
Inputfield 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 asInput: '"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, useRuleTargetInput.fromObject()instead.- Parameters:
text (
str)- Return type: