模板格式错误:YAML 在指标过滤器中格式不正确

问题描述

模板格式错误:YAML 格式不正确。 (第 30 行,第 36 列)。请帮我。错误出现在 FilterPattern

AWstemplateFormatVersion: "2010-09-09"

Resources:
 MySNSTopic:
  Type: AWS::SNS::Topic
  Properties:
    Subscription:
    - Endpoint: "abcd@abcd.com"
      Protocol: email
   
 snstopic: 
  Type: AWS::Logs::LogGroup
  DependsOn: MySNSTopic
  Properties: 
    RetentionInDays: 7
  
 UnauthorizedApiCalls: 
  Type: AWS::Logs::MetricFilter
  DependsOn: snstopic
  Properties: 
    LogGroupName: 
      Ref: "snstopic"
    FilterPattern: "{($.errorCode="*UnauthorizedOperation") || ($.errorCode="AccessDenied*")}"
    MetricTransformations: 
      - 
        MetricValue: "1"
        MetricNamespace: "unauthorized-api-calls"
        MetricName: "LogMetrics"

解决方法

你应该使用单引号:

FilterPattern: '{($.errorCode="*UnauthorizedOperation") || ($.errorCode="AccessDenied*")}'