AWS Generation Rule Examples
Below is an example of how to configure Generation Rules and templates for AWS resources—in this case, Amazon EKS Clusters. The final result automatically generates an SLX, SLI, and Runbook for each matched cluster.
Example Directory Layout
aws-eks-health└── .runwhen ├── generation-rules │ └── aws-eks-health.yaml └── templates ├── aws-eks-health-slx.yaml ├── aws-eks-health-sli.yaml └── aws-eks-health-taskset.yamlGeneration Rule
apiVersion: runwhen.com/v1kind: GenerationRulesspec: platform: aws generationRules: - resourceTypes: - aws_eks_clusters matchRules: - type: pattern pattern: ".+" properties: [ name ] mode: substring slxs: - baseName: aws-eks-health qualifiers: [ "resource" ] baseTemplateName: aws-eks-health levelOfDetail: basic outputItems: - type: slx - type: sli - type: runbook templateName: aws-eks-health-taskset.yamlExplanation
- resourceTypes: Targets AWS EKS Clusters (
aws_eks_clusters). - matchRules: Matches any cluster name containing at least one character.
- slxs: Generates an SLX, an SLI, and a Runbook for every matched cluster. The templates are all prefixed by
aws-eks-health.
SLI Template Example
apiVersion: runwhen.com/v1kind: ServiceLevelIndicatormetadata: name: {{slx_name}} labels: {% include "common-labels.yaml" %} annotations: {% include "common-annotations.yaml" %}spec: displayUnitsLong: OK displayUnitsShort: ok location: {{default_location}} description: Measures EKS status in the region. codeBundle: {% if repo_url %} repoUrl: {{repo_url}} {% else %} repoUrl: https://github.com/runwhen-contrib/rw-cli-codecollection.git {% endif %} {% if ref %} ref: {{ref}} {% else %} ref: main {% endif %} pathToRobot: codebundles/aws-eks-health/sli.robot intervalStrategy: intermezzo intervalSeconds: 300 configProvided: - name: AWS_REGION value: {{match_resource.resource.region}} secretsProvided: - name: AWS_ACCESS_KEY_ID workspaceKey: {{custom.aws_access_key_id}} - name: AWS_SECRET_ACCESS_KEY workspaceKey: {{custom.aws_secret_access_key}} - name: AWS_ROLE_ARN workspaceKey: {{custom.aws_role_arn}}Explanation
- intervalSeconds: Runs every 300 seconds (5 minutes).
- configProvided: Passes the AWS region from the matched resource into the SLI code.
- secretsProvided: Provides AWS credentials and a role if needed.
SLX Template Example
apiVersion: runwhen.com/v1kind: ServiceLevelXmetadata: name: {{slx_name}} labels: {% include "common-labels.yaml" %} annotations: {% include "common-annotations.yaml" %}spec: imageURL: https://storage.googleapis.com/runwhen-nonprod-shared-images/icons/aws/eks.png alias: AWS EKS Cluster {{match_resource.resource.cluster_name}} asMeasuredBy: Availability of EKS Cluster {{match_resource.resource.cluster_name}} in region {{match_resource.resource.region}} configProvided: - name: SLX_PLACEHOLDER value: SLX_PLACEHOLDER owners: - {{workspace.owner_email}} statement: EKS Nodes {{match_resource.resource.region}} should be available. additionalContext: region: "{{match_resource.resource.region}}" name: "{{match_resource.resource.cluster_name}}"Explanation
- imageURL: Illustrates a reference to an AWS EKS icon.
- alias / asMeasuredBy: Provide descriptive text about the cluster.
- additionalContext: Adds more details about region and cluster name for debugging.
Runbook Template Example
apiVersion: runwhen.com/v1kind: Runbookmetadata: name: {{slx_name}} labels: {% include "common-labels.yaml" %} annotations: {% include "common-annotations.yaml" %}spec: location: {{default_location}} description: Generates a report for EKS and a summary of their CloudWatch metrics. codeBundle: {% if repo_url %} repoUrl: {{repo_url}} {% else %} repoUrl: https://github.com/runwhen-contrib/rw-cli-codecollection.git {% endif %} {% if ref %} ref: {{ref}} {% else %} ref: main {% endif %} pathToRobot: codebundles/aws-eks-health/runbook.robot configProvided: - name: AWS_REGION value: {{match_resource.resource.region}} secretsProvided: - name: AWS_ACCESS_KEY_ID workspaceKey: {{custom.aws_access_key_id}} - name: AWS_SECRET_ACCESS_KEY workspaceKey: {{custom.aws_secret_access_key}} - name: AWS_ROLE_ARN workspaceKey: {{custom.aws_role_arn}}Explanation
- pathToRobot: Points to the location of your runbook code in the AWS EKS health CodeBundle.
- configProvided: Passes the AWS region for gathering EKS info.
- secretsProvided: The same AWS credentials used by the SLI.
Summary
With these configurations:
- A single Generation Rule matches AWS EKS Clusters.
- It emits an SLX, SLI, and Runbook for each matched cluster.
- The templates reference region, cluster name, and AWS credentials.
This approach can be extended to other AWS resource types by adjusting resourceTypes, matchRules, and the code bundles used in your templates.