AWS Cloudwatch Alarm

For Lambda:

MyNewAlarm:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmName: "AlarmNameGoesHere"
      AlarmDescription: "Alarm if lambda errors out too many times"
      Namespace: "AWS/Lambda"
      MetricName: "Errors"
      Dimensions:
      - Name: "FunctionName"
        Value: "NameOfYourLambdaFunction"
      Statistic: "Sum"
      ComparisonOperator: "GreaterThanThreshold"
      Threshold: 0
      EvaluationPeriods: 5
      Period: 60
      TreatMissingData: "breaching"

Alarm on metrics

LambdaCriticalErrorAlarm:
    Type: 'AWS::CloudWatch::Alarm'
    Properties:
      ActionsEnabled: true
      AlarmDescription: !Sub 'Lambda Critical Error Alarm for ${FunctionName}'
      AlarmName: !Sub '${FunctionName}-Lambda-Critical-Error-Alarm'
      AlarmActions:
        - !Sub 'arn:aws:sns:${AWS::Region}:${AWS::AccountId}:${CriticalSnsTopicName}'
      ComparisonOperator: GreaterThanOrEqualToThreshold
      EvaluationPeriods: 1
      Threshold: 0.25
      DatapointsToAlarm: 1
      Metrics:
        - Id: !Sub "errorPercentage_${FunctionName}"
          Expression: !Sub "errors_${FunctionName} / requests_${FunctionName} * 100"
          Label: !Sub "${FunctionName}-ErrorPercentage"
          ReturnData: true
        - Id: !Sub "errors_${FunctionName}"
          MetricStat:
            Metric:
              Namespace: "AWS/Lambda"
              MetricName: "Errors"
              Dimensions:
                - Name: FunctionName
                  Value: !Sub '${FunctionName}'
                - Name: Resource
                  Value: !Sub '${FunctionName}'
            Period: 300
            Stat: Sum
          ReturnData: false
        - Id: !Sub "requests_${FunctionName}"
          MetricStat:
            Metric:
              Namespace: "AWS/Lambda"
              MetricName: "Invocations"
              Dimensions:
                - Name: FunctionName
                  Value: !Sub '${FunctionName}'
            Period: 300
            Stat: Sum
          ReturnData: false
      TreatMissingData: missing

Example: alarm on duration

Resources:
  testAlarm:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmName: test-alarm
      AlarmDescription: "I'm taking too long!"
      ComparisonOperator: GreaterThanThreshold
      EvaluationPeriods: 1
      DatapointsToAlarm: 1
      MetricName: Duration
      Namespace: AWS/Lambda
      Period: 60
      Statistic: Maximum
      Threshold: 0
      Dimensions:
        - Name: 'FunctionName'
          Value: 'hello world'
      TreatMissingData: notBreaching