eventbridge-transformer icon indicating copy to clipboard operation
eventbridge-transformer copied to clipboard

Use brackets for array index instead of dots.

Open chris3ware opened this issue 1 year ago • 0 comments

Hi, I recently used your tool to generate an input transformer (great tool btw). However I had trouble because the index for items in an array is wrapped in '.' as opposed to '[]'. For example, take the following event - with a 'findings' array:

{
    "version": "0",
    "id": "8e5622f9-d81c-4d81-612a-9319e7ee2506",
    "detail-type": "Security Hub Findings - Imported",
    "source": "aws.securityhub",
    "account": "123456789012",
    "time": "2019-04-11T21:52:17Z",
    "region": "us-west-2",
    "detail": {
        "findings": [
            {
                "SchemaVersion": "2018-10-08",
                "CompanyName": "AWS",
                "FirstObservedAt": "2022-08-10T10:36:01.841Z",
                "LastObservedAt": "2022-10-20T23:33:15.790Z",
                "CreatedAt": "2022-08-10T10:36:01.841Z",
                "UpdatedAt": "2022-10-20T23:33:13.854Z",
                "Severity": {
                    "Product": 40,
                    "Label": "MEDIUM",
                    "Normalized": 40,
                    "Original": "MEDIUM"
                }
            }
        ]
    }
}

The Input Path specified for the 'SchemaVersion' is specified as:

{
    "SchemaVersion": "$.detail.findings.0.SchemaVersion"
}

However, while this works in the AWS console - and produces the desired output, the output was missing from the content received via email from the SNS topic. AWS support pointed me to their documentation, which highlighted that the index should be referenced with square brackets:

{
    "SchemaVersion": "$.detail.findings[0].SchemaVersion"
}

https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-transform-target-input.html#eb-transform-input-examples

This is also defined in the JSONPath README:

https://github.com/json-path/JsonPath

chris3ware avatar Oct 24 '22 12:10 chris3ware