Как создать плату cloudwatch da sh для пошаговой функции с использованием шаблонов облачной информации - PullRequest
0 голосов
/ 11 марта 2020

Я пытаюсь создать плату наблюдения за облаками и sh для функции шага конечного автомата, используя шаблон формирования облака. Ошибка создания стека из-за ошибки «Поле DashboardBody должно быть действительным JSON объектом». Любая идея, как я могу передать имя группы журналов, взятой из раздела параметров шаблона?

ниже мой шаблон формирования облака:

AWSTemplateFormatVersion: 2010-09-09
Description: >-
  CloudFormation template to  create a dashboard for  state functions
Parameters:
  DashboardName:
    Description: Name of the dashboard to create
    Type: String
    Default: Test-board
  LambdaFunction:
    Description: The Lambda function name.
    Type: String
    Default: test-lambda

  StepFunction:
    Description: The state function name.
    Type: String
    Default: MyStateMachine

Resources:
  MetricsDashboard:
    Type: 'AWS::CloudWatch::Dashboard'
    Properties:
      DashboardName: !Ref DashboardName
      DashboardBody: !Join 
        - ''
        - - >-
            { "widgets": [

            { "type": "log", "x": 6, "y": 6, "width": 18, "height": 3,
            "properties": {

            "query": "
             - !Join 
               - ""
               - "SOURCE '/aws/states/"
               - ""
               - !Ref StepFunction
               - ""
               - "' | fields  @message\r\n| filter @message like /ERROR/| filter @message like /Exception/ "
          - >-
            ",

            "region": "eu-west-1", "stacked": false, "title": "{ Ref:StepFunction},
            Step Function Error Logs", "view": "table" } },

            {
            "type": "metric",
            "x": 0,
            "y": 0,
            "width": 5,
            "height": 5,
            "properties": {
                "view": "singleValue",
                "metrics": [
                    [ "AWS/States", "ExecutionsFailed", "StateMachineArn", "',{ Ref: StepFunction },'" ],
                    [ ".", "ExecutionsSucceeded", ".", ".", { "color": "#2ca02c" } ],
                    [ ".", "ExecutionsAborted", ".", ".", { "visible": false, "color": "#ff9896" } ]
                ],
                "stat": "Sum",
                "setPeriodToTimeRange": true,
                "region": "', { Ref: AWS::Region }, '",
                "title": "', "State-Function-", { Ref: StepFunction }," Counts", '",
                "period": 300
            }
        }




            ]

            }

Заранее спасибо,

1 Ответ

1 голос
/ 13 марта 2020

Удалите объединения, они заканчиваются как часть json последней панели инструментов.

Проверьте, работает ли это для вас:

AWSTemplateFormatVersion: 2010-09-09
Description: >-
  CloudFormation template to  create a dashboard for  state functions
Parameters:
  DashboardName:
    Description: Name of the dashboard to create
    Type: String
    Default: Test-board
  LambdaFunction:
    Description: The Lambda function name.
    Type: String
    Default: test-lambda

  StepFunction:
    Description: The state function name.
    Type: String
    Default: MyStateMachine

Resources:
  MetricsDashboard:
    Type: 'AWS::CloudWatch::Dashboard'
    Properties:
      DashboardName: !Ref DashboardName
      DashboardBody: !Sub |
            {
              "widgets": [
                {
                  "type": "log",
                  "x": 6,
                  "y": 6,
                  "width": 18,
                  "height": 3,
                  "properties": {
                    "query": "SOURCE '/aws/states/${StepFunction}' | fields  @message\r\n| filter @message like /ERROR/| filter @message like /Exception/ ",
                    "region": "eu-west-1",
                    "stacked": false,
                    "title": "${StepFunction} Step Function Error Logs",
                    "view": "table"
                  }
                },
                {
                  "type": "metric",
                  "x": 0,
                  "y": 0,
                  "width": 5,
                  "height": 5,
                  "properties": {
                    "view": "singleValue",
                    "metrics": [
                      [
                        "AWS/States",
                        "ExecutionsFailed",
                        "StateMachineArn",
                        "${StepFunction}"
                      ],
                      [
                        ".",
                        "ExecutionsSucceeded",
                        ".",
                        ".",
                        {
                          "color": "#2ca02c"
                        }
                      ],
                      [
                        ".",
                        "ExecutionsAborted",
                        ".",
                        ".",
                        {
                          "visible": false,
                          "color": "#ff9896"
                        }
                      ]
                    ],
                    "stat": "Sum",
                    "setPeriodToTimeRange": true,
                    "region": "${AWS::Region}",
                    "title": "State Function ${StepFunction} Counts",
                    "period": 300
                  }
                }
              ]
            }
...