title: AWS Cognito User Pool - SignInSuccesses CloudWatch Alarm and Metrics in CloudFormation
body: <p>I have been unsuccessfully trying to implement in CloudFormation what is described in the AWS documentation: <strong>Metrics for Amazon Cognito user pools</strong> [https://docs.aws.amazon.com/cognito/latest/developerguide/metrics-for-cognito-user-pools.html] for the Metric '<em>SignInSuccesses</em>', specifically &quot;To count the total number of failed user authentication requests, use the CloudWatch Math expression and subtract the Sum statistic from the Sample Count statistic.&quot;</p>
  <p>I've made a bit of progress with resolving various errors with my template from the errors provided by CloudFormation; however, I seem to have hit a wall and have now been getting the generic &quot;<em>Invalid metrics list</em>&quot; which has been hard to diagnose how to move forward.  I've also searched around a bunch to try and find other examples of Cognito Metrics/Alarms examples, as well as, have tried to achieve this manually through the console, both with no success.</p>
  <p>My template so far:</p>
  <pre><code>  CognitoFailedSignInAlarm:
      Type: AWS::CloudWatch::Alarm
      Properties:
        AlarmName: !Sub Cognito-${ApplicationName}-FailedSignIn-Alarm
        AlarmDescription: Cognito UserPool Failed Sign In Attempts Alarm
        AlarmActions:
          - !Ref AlarmsTopic
        ComparisonOperator: GreaterThanOrEqualToThreshold
        EvaluationPeriods: 1
        TreatMissingData: ignore
        Threshold: !Ref AlarmThreshold
        Metrics:
          - Id: m1
            MetricStat:
              Metric:
                Dimensions:
                  - Name: UserPool
                    Value: !Ref UserPoolId
                  - Name: UserPoolClient
                    Value: !Ref UserPoolAppClientId
                MetricName: SignInSuccesses
                Namespace: AWS/Cognito
              Period: !Ref AlarmPeriod
              Stat: SampleCount
            ReturnData: False
          - Id: m2
            MetricStat:
              Metric:
                Dimensions:
                  - Name: UserPool
                    Value: !Ref UserPoolId
                  - Name: UserPoolClient
                    Value: !Ref UserPoolAppClientId
                MetricName: SignInSuccesses
                Namespace: AWS/Cognito
              Period: !Ref AlarmPeriod
              Stat: Sum
            ReturnData: False
          - Id: TotalMinusFailed
            Expression: m1-m2
            Label: FailedCount
  </code></pre>