SNS event in Lambda with filterPolicy not working

I have two separate CloudFormation configurations.
One creates the SNS resource and I want to use it in my second configuration as events in Lambda with filterPolicy on MessageAttributes.

I have referred this link to configure my Lambda.

Everything works but the filtering of the message is not working. Lambda is invoked for every messages.

Here is my code snippet

    name: WorkerForMsgCode063
    handler: main
    runtime: go1.x
      - sns:
          arn: <topic ARN from other cloudformation stack>
              - 063

I checked that above serverless config creates the lambda with SNS trigger but when I see the SNS Topic (created by other stack) in AWS console it doesn’t show any subscription.


The subscription for lambda is created but the filterPolicy is still not working. I also checked generated cloud formation template. It also doesn’t have FilterPolicy block in subscription.

Result of that I have put a if condition in my subscribed lambda to check for specific msgCode and process it only when that condition is true.