Score:0

AWS Eventbridge - How to return Input Transformer variables when passing to SNS?

mk flag

I'm setting up a SNS topic for custom EventBridge patterns for compliance purposes. To eliminate a lot of the JSON into something more human readable, I am using the following Input Transformer configuration with an event grabbed straight from CloudTrail:

Input Path:

{
  "event": "$.eventName",
  "source": "$.eventSource",
  "time": "$.eventTime",
  "user": "$.userIdentity.arn"
}

Template:

"<time>"
"<source>: <event>"

"User: <user>"

Test Event (with redacted data):

{
    "eventVersion": "1.08",
    "userIdentity": {
        "type": "AssumedRole",
        "principalId": "*******",
        "arn": "********",
        "accountId": "*********",
        "accessKeyId": "*********",
        "sessionContext": {
            "sessionIssuer": {
                "type": "Role",
                "principalId": "**********",
                "arn": "***********",
                "accountId": "*******",
                "userName": "*********"
            },
            "webIdFederationData": {},
            "attributes": {
                "creationDate": "2022-12-07T19:41:29Z",
                "mfaAuthenticated": "false"
            }
        }
    },
    "eventTime": "2022-12-07T20:10:32Z",
    "eventSource": "cloudfront.amazonaws.com",
    "eventName": "TagResource",
    "awsRegion": "us-east-1",
    "sourceIPAddress": "AWS Internal",
    "userAgent": "AWS Internal",
    "requestParameters": {
        "resource": "arn:aws:cloudfront::**********:distribution/***********",
        "tags": {
            "items": [
                {
                    "key": "test",
                    "value": "tag"
                }
            ]
        }
    },
    "responseElements": null,
    "requestID": "93fb1331-9634-4d49-9a91-61dd9313d5b6",
    "eventID": "a518b49a-e9d4-47af-9f36-bcd9d854bf1a",
    "readOnly": false,
    "eventType": "AwsApiCall",
    "apiVersion": "2020_05_31",
    "managementEvent": true,
    "recipientAccountId": "********",
    "eventCategory": "Management",
    "sessionCredentialFromConsole": "true"
}

When using the Generate Output function in the Input Transformer, the output shows correctly as:

2022-12-07T20:10:32Z"
"cloudfront.amazonaws.com: TagResource"

"User: arn:aws:sts::**********:assumed-role/*******/*****

However when received via SNS Email, the variables return blank, as in:

""
": "

"User: "

I'm unsure what I'm missing here. I have tried various white spacing differences, up to un-prettyfying all the JSON as described in a tangentially similar question here, and trying to return only a single variable with a pure JSON template, with no luck so far.

And just in case its relevant, I'm using the AWS API Call via CloudTrail Event Source with the following event pattern (which works perfectly for triggering the SNS topic):

{
  "source": ["aws.cloudfront"],
  "detail-type": ["AWS API Call via CloudTrail"],
  "detail": {
    "eventSource": ["cloudfront.amazonaws.com"],
    "eventName": ["TagResource", "UntagResource"]
  }
}

Thank you oh great and powerful StackExchange for your help. Long time lurker, first time poster, glad to contribute to the corpus.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.