Home > OS >  Use Fn::FindInMap in DashboardBody in AWS CloudFormation
Use Fn::FindInMap in DashboardBody in AWS CloudFormation

Time:09-21

I am creating an AWS CloudWatch dashboard using CloudFormation and trying to use Fn::FindInMap in the DashboardBody body. However, the value is not getting replaced successfully. Can someone please help?

Below is my code:

Mappings:
  EnvSource:
    Dev:
      "SMSFailed": sns/us-east-1/XXX/DirectPublishToPhoneNumber/Failure
Resources: 
  MonitoringDashboard: 
    Type: "AWS::CloudWatch::Dashboard"
    Properties: 
      DashboardName:
        Monitoring-Test-Dashboard
      DashboardBody:
        !Sub "{\"widgets\":[{\"height\":6,\"width\":12,\"y\":1,\"x\":12,\"type\":\"log\",\"properties\":{\"query\":\"SOURCE 'Fn::FindInMap' : [ 'ABC', 'DomainParameters', 'DomainName'] | fields @timestamp, @message, delivery.providerResponse, status\\n| filter @message like //\\n|stats count(status) as ErrorCount by delivery.providerResponse\\n| sort @timestamp asc\",\"region\":\"us-east-1\",\"title\":\"SMS Failed\",\"view\":\"table\"}}]}"

Output: enter image description here

CodePudding user response:

You can use a list form of Sub:

Resources: 
  MonitoringDashboard: 
    Type: "AWS::CloudWatch::Dashboard"
    Properties: 
      DashboardName:
        Monitoring-Test-Dashboard
      DashboardBody:
        !Sub 
           - "{\"widgets\":[{\"height\":6,\"width\":12,\"y\":1,\"x\":12,\"type\":\"log\",\"properties\":{\"query\":\"SOURCE ${FindInMap} | fields @timestamp, @message, delivery.providerResponse, status\\n| filter @message like //\\n|stats count(status) as ErrorCount by delivery.providerResponse\\n| sort @timestamp asc\",\"region\":\"us-east-1\",\"title\":\"SMS Failed\",\"view\":\"table\"}}]}"
           - DomainName: !FindInMap [ 'ABC', 'DomainParameters', 'DomainName']
  • Related