Search code examples
amazon-web-servicesaws-serverlessaws-samaws-event-bridge

Aws EventBridge Rule pattern not forming correctly with AWS SAM


I was trying to create an AWS state machine(step functions) using AWS SAM which is triggered by S3 event. Following is my AWS SAM yml snippet.

 SampleStateMachine:
    Type: AWS::Serverless::StateMachine
    Properties:
      Name: sample-state-machine
      DefinitionUri: state-machines/my-definition.asl.json
      Events:
        S3PutEvent:
          Type: EventBridgeRule
          Properties:
            Pattern:
              source:
                - "aws.s3"
              detail:
                eventSource:
                  - s3.amazonaws.com
                eventName:
                  - PutObject
                requestParameters:
                  bucketName:
                    - !Ref MyBucketName

On deploying this application, it's successfully creating the rule with the pattern that I've specified in the sam yml template. (but with a slight change in the order of JSON key-value pairs)

{
    "source": [
      "aws.s3"
    ],
    "detail": {
      "eventSource": [
        "s3.amazonaws.com"
      ],
      "requestParameters": {
        "bucketName": [
          "my-bucket"
        ]
      },
      "eventName": [
        "PutObject"
      ]
    }
  } 

Unfortunately, this rule is not capturing any event from the event bus. so I've tried like changing the JSON Key-Value pair in the following order,

{ 
  "source": [ "aws.s3"
        ],
        "detail": {
          "eventSource": [
            "s3.amazonaws.com"
          ],
          "eventName": [
            "PutObject"
          ],
          "requestParameters": {
            "bucketName": [
              "my-bucket"
            ]
          }
        }
      }

and it started receiving events and working fine.

So my question is,

  1. Is this order really matters for AWS eventbridge rule pattern?
  2. If so, how we can preserve this order while AWS sam execution(YML to JSON)?

Thanks


Solution

  • Order should not matter. If you can reproduce the issue, you should file a bug report with AWS support to get the service to fix it.