Skip to content
v2.275.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}`,
  }),
}));

Properties ​

accountstringaccountstraccountStringAccountstringAccount*stringstatic#
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*stringstatic#
Extract the detail type from the event.
displayHintstringdisplay_hintstrdisplayHintStringDisplayHintstringDisplayHint*string#
Human readable display hint about the event pattern.
eventIdstringevent_idstreventIdStringEventIdstringEventId*stringstatic#
Extract the event ID from the event.
pathstringpathstrpathStringPathstringPath*string#
the path to a field in the event pattern.
regionstringregionstrregionStringRegionstringRegion*stringstatic#
Extract the region from the event.
sourcestringsourcestrsourceStringSourcestringSource*stringstatic#
Extract the source from the event.
timestringtimestrtimeStringTimestringTime*stringstatic#
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) *stringstatic#
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.