Skip to content
v2.278.0

EventField Class ​

Represents a field in the event pattern.

Each EventField you reference from a RuleTargetInput becomes an entry in the target's InputPathsMap, keyed by a readable hint derived from the path, and the place you referenced it becomes a matching placeholder in the InputTemplate. Referencing the same path more than once reuses a single entry.

Because these are string tokens, they can be embedded in template literals and composed with other strings.

Example ​

ts
declare const rule: events.Rule;
declare const topic: sns.Topic;

rule.addTarget(new targets.SnsTopic(topic, {
  message: events.RuleTargetInput.fromObject({
    // Named shorthands for the standard top-level event envelope fields
    account: events.EventField.account,
    region: events.EventField.region,
    // Any other field is reachable by JSONPath
    bucket: events.EventField.fromPath('$.detail.bucket.name'),
    // Tokens compose with ordinary strings
    summary: `Event ${events.EventField.eventId} from ${events.EventField.source}`,
  }),
}));
python
# rule: events.Rule
# topic: sns.Topic


rule.add_target(targets.SnsTopic(topic,
    message=events.RuleTargetInput.from_object({
        # Named shorthands for the standard top-level event envelope fields
        "account": events.EventField.account,
        "region": events.EventField.region,
        # Any other field is reachable by JSONPath
        "bucket": events.EventField.from_path("$.detail.bucket.name"),
        # Tokens compose with ordinary strings
        "summary": f"Event {events.EventField.eventId} from {events.EventField.source}"
    })
))
java
Rule rule;
Topic topic;


rule.addTarget(SnsTopic.Builder.create(topic)
        .message(RuleTargetInput.fromObject(Map.of(
                // Named shorthands for the standard top-level event envelope fields
                "account", EventField.getAccount(),
                "region", EventField.getRegion(),
                // Any other field is reachable by JSONPath
                "bucket", EventField.fromPath("$.detail.bucket.name"),
                // Tokens compose with ordinary strings
                "summary", String.format("Event %s from %s", EventField.getEventId(), EventField.getSource()))))
        .build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
Rule rule;
Topic topic;


rule.AddTarget(new SnsTopic(topic, new SnsTopicProps {
    Message = RuleTargetInput.FromObject(new Dictionary<string, string> {
        // Named shorthands for the standard top-level event envelope fields
        { "account", EventField.Account },
        { "region", EventField.Region },
        // Any other field is reachable by JSONPath
        { "bucket", EventField.FromPath("$.detail.bucket.name") },
        // Tokens compose with ordinary strings
        { "summary", $"Event {events.EventField.eventId} from {events.EventField.source}" }
    })
}));
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var rule Rule
var topic Topic


rule.AddTarget(targets.NewSnsTopic(topic, &SnsTopicProps{
	Message: events.RuleTargetInput_FromObject(map[string]*string{
		// Named shorthands for the standard top-level event envelope fields
		"account": events.EventField_account(),
		"region": events.EventField_region(),
		// Any other field is reachable by JSONPath
		"bucket": events.EventField_fromPath(jsii.String("$.detail.bucket.name")),
		// Tokens compose with ordinary strings
		"summary": fmt.Sprintf("Event %v from %v", events.EventField_eventId(), events.EventField_source()),
	}),
}))

Properties ​

accountstringaccountstraccountStringAccountstringAccount*string static #
Extract the account from the event.
creationStackstring[]creation_stacktyping.List[str]creationStackList<String>CreationStackstring[]CreationStack*[]*string #
The creation stack of this resolvable which will be appended to errors thrown during resolution.

This may return an array with a single informational element indicating how to get this property populated, if it was skipped for performance reasons.

detailTypestringdetail_typestrdetailTypeStringDetailTypestringDetailType*string static #
Extract the detail type from the event.
displayHintstringdisplay_hintstrdisplayHintStringDisplayHintstringDisplayHint*string #
Human readable display hint about the event pattern.
eventIdstringevent_idstreventIdStringEventIdstringEventId*string static #
Extract the event ID from the event.
pathstringpathstrpathStringPathstringPath*string #
the path to a field in the event pattern.
regionstringregionstrregionStringRegionstringRegion*string static #
Extract the region from the event.
sourcestringsourcestrsourceStringSourcestringSource*string static #
Extract the source from the event.
timestringtimestrtimeStringTimestringTime*string static #
Extract the time from the event.

Methods ​

fromPath(path: string): string@staticmethod def from_path(path: str) -> strpublic static String fromPath(String path)public static string FromPath(string path)func FromPath(Path *string) *string static #
Extract a custom JSON path from the event.
resolve(_ctx: IResolveContext): anydef resolve(self, _ctx: IResolveContext) -> Anypublic Object resolve(IResolveContext _ctx)public object Resolve(IResolveContext _ctx)func Resolve(_ctx IResolveContext) interface{} #
Produce the Token's value at resolution time.
toJSON(): stringdef to_json(self, ) -> strpublic String toJSON()public string ToJSON()func ToJSON() *string #
Convert the path to the field in the event pattern to JSON.
toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string #
Return a string representation of this resolvable object.

Returns a reversible string representation.