hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.85k stars 9.19k forks source link

[New Service]: CloudWatch Application Signals Service Level Objectives (SLO) - `aws_service_level_objective` #39555

Open LozanoMatheus opened 1 month ago

LozanoMatheus commented 1 month ago

Description

A few months ago, AWS has annouced the CloudWatch Application Signals and one of the features is to be able to set up the SLOs.

It seems to have a pretty low rate/retry limit on this API: An error occurred (InternalFailure) when calling the UpdateServiceLevelObjective operation (reached max retries: 2): None

Requested Resource(s) and/or Data Source(s)

Resource

Data

Potential Terraform Configuration

**Resource**

resource "aws_service_level_objective" "example" {
  name = "example" ## or id

  request_based_sli_config {
    request_based_sli_metric_config {
      total_request_count_metric {
        metric_stat {
          metric {
            namespace  = "AWS/Lambda"
            metric_name = "Invocations"
            dimensions {
              name  = "FunctionName"
              value = "my-lambda-lambda"
            }
          }
          period = 60
          stat   = "Sum"
        }
        return_data = true
      }

      monitored_request_count_metric {
        bad_count_metric {
          id = "cwMetricNumerator"
          metric_stat {
            metric {
              namespace  = "AWS/Lambda"
              metric_name = "Errors"
              dimensions {
                name  = "FunctionName"
                value = "my-lambda-lambda"
              }
            }
            period = 60
            stat   = "Sum"
          }
          return_data = true
        }
      }
    }
  }

  goal {
    interval {
      rolling_interval {
        duration_unit = "DAY"
        duration      = 90
      }
    }
    attainment_goal   = 99.98
    warning_threshold = 99.9
  }

  tags = {
    Name = "My SLO Example"
  }
}

**Data**

data "aws_service_level_objective" "example" {
  name = "example" ## or id
}

## I'm not sure if somehow we could use this or the above to filter by tag or prefix. It doesn't seems to be possible tho.
data "aws_service_level_objectives" "example" {}

References

--

I also made a few scripts for it

aws application-signals \
  create-service-level-objective \
  --name "example" \
  --cli-input-json file://file.json

file.json

{
  "RequestBasedSliConfig": {
    "RequestBasedSliMetricConfig": {
      "TotalRequestCountMetric": [
        {
          "Id": "cwMetricDenominator",
          "MetricStat": {
            "Metric": {
              "Namespace": "AWS/Lambda",
              "MetricName": "Invocations",
              "Dimensions": [
                {
                  "Name": "FunctionName",
                  "Value": "my-function-example"
                }
              ]
            },
            "Period": 60,
            "Stat": "Sum"
          },
          "ReturnData": true
        }
      ],
      "MonitoredRequestCountMetric": {
        "BadCountMetric": [
          {
            "Id": "cwMetricNumerator",
            "MetricStat": {
              "Metric": {
                "Namespace": "AWS/Lambda",
                "MetricName": "Errors",
                "Dimensions": [
                  {
                    "Name": "FunctionName",
                    "Value": "my-function-example"
                  }
                ]
              },
              "Period": 60,
              "Stat": "Sum"
            },
            "ReturnData": true
          }
        ]
      }
    }
  },
  "Goal": {
    "Interval": {
      "RollingInterval": {
        "DurationUnit": "DAY",
        "Duration": 90
      }
    },
    "AttainmentGoal": 99.98,
    "WarningThreshold": 99.9
  }
}
aws application-signals \
  get-service-level-objective \
  --id "example"
aws application-signals \
  list-service-level-objectives

I'll add here once I can call the UpdateServiceLevelObjective again (reached a rate/retry limit of 2)

Would you like to implement a fix?

No

github-actions[bot] commented 1 month ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue