How to add the input for aws_event.RuleTargetInput.from_object function

159 views Asked by At

I have event from event bus rule. Below is an example without adding input transformer.

{
    "input":{
        'version': '0',
        'id': '12345',
        'detail-type': 'abcd',
        'source': 'aws',
        'region': 'us-east-1',
        'detail': {
            'account_id': 123456,
            'customer': 'some customer'
        }
    },
 "inputDetails"{
      "truncated":False
   }

The event will be sent to a lambda function of a state machine. I use the following code to define the input transformer (only need the customer_name, not a constant value) for the state machine but I can't figure it out the right way to do it.

targets=lambda: [aws_events_targets.SfnStateMachine(
    machine=my_state_machine.get(),
    input=aws_events.RuleTargetInput.from_object(
       {"customer": "$.input.detail.customer"}           
    ),
)],
1

There are 1 answers

0
Jason LiLy On

Here is the result I figured out.

targets=lambda: [aws_events_targets.SfnStateMachine(
    machine=my_state_machine.get(),
    input=aws_events.RuleTargetInput.from_object(
       {
        "customer":aws_events.EventField.from_path(
                   "$.detail.customer"
           )
       }           
    ),
)],