Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inputing parameters into Cloudwatch Event Rule Input parameter in Cloudformation

I'm creating a Cloudwatch Event Rule that is supposed to trigger a lambda if the Step Function enters a failure or time out state. The cloud watch event rule will pass parameters to the lambda which will send out a custom SNS email. I'm trying to pass the values for the input parameters into the Cloudwatch Event Rule from parameters I have setup in my Cloudformation template. I can't get Cloudformation to pull the parameter values out put them into the Cloudwatch Event Rule Input parameter. CF takes the literal values I'm giving it in JSON and putting that into the Cloudwatch Event rule. I'm using a YAML template with a JSON parameter file. Posting the code below.

FailureEvent:
Type: AWS::Events::Rule
DependsOn:
  - StateMachine
Properties:
  Description: !Ref FailureRuleDescription
  Name: !Ref FailureRuleName
  EventPattern:
    detail-type:
      - "Step Functions Execution Status Change"
    detail:
      status:
        - "FAILED"
        - "TIMED_OUT"
      stateMachineArn: [!Ref StateMachine]
  Targets:
    - Arn:
        'Fn::Join': ["", ['arn:aws:lambda:', !Ref 'AWS::Region', ':', !Ref 'AWS::AccountId', ':function:', !Ref FailureLambda]]
      Id: !Ref FailureLambda
      Input: '{"failed_service": "!Ref StateMachineName","sns_arn": {"Fn::Join":[":",["arn: aws: sns",{"Ref": "AWS: : Region"},{"Ref": "AWS::AccountId"},{"Ref": "SNSTopic"}]]}}'
like image 313
k2so Avatar asked Oct 18 '25 22:10

k2so


1 Answers

You can use Sub:

Input: !Sub '{"failed_service": "${StateMachineName}","sns_arn": "arn:aws:sns:${AWS::Region}:${AWS::AccountId}:${SNSTopic}"}'
like image 105
Marcin Avatar answered Oct 21 '25 12:10

Marcin