# EventField

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.

Implements: [IResolvable](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html)

- Source: [`aws-events/lib/input.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-events/lib/input.ts#L330)

## Example

TypeScript:

```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:

```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:

```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());
```

C# / .NET:

```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}" }
    })
}));
```

Golang:

```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

- `account`: string (static) — Extract the account from the event.

- `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.

- `detailType`: string (static) — Extract the detail type from the event.

- `displayHint`: string — Human readable display hint about the event pattern.

- `eventId`: string (static) — Extract the event ID from the event.

- `path`: string — the path to a field in the event pattern.

- `region`: string (static) — Extract the region from the event.

- `source`: string (static) — Extract the source from the event.

- `time`: string (static) — Extract the time from the event.

## Methods

- `fromPath(path: string): string` (static) — Extract a custom JSON path from the event.

- `resolve(_ctx: IResolveContext): any` — Produce the Token's value at resolution time.

- `toJSON(): string` — Convert the path to the field in the event pattern to JSON.

- `toString(): string` — Return a string representation of this resolvable object.

  Returns a reversible string representation.
