Skip to main content
Skip table of contents

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

CODE
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.yaml

Generation Rule

CODE
apiVersion: runwhen.com/v1
kind: GenerationRules
spec:
  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.yaml

Explanation

  1. resourceTypes: Targets AWS EKS Clusters (aws_eks_clusters).

  2. matchRules: Matches any cluster name containing at least one character.

  3. 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

CODE
apiVersion: runwhen.com/v1
kind: ServiceLevelIndicator
metadata:
  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

CODE
apiVersion: runwhen.com/v1
kind: ServiceLevelX
metadata:
  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

CODE
apiVersion: runwhen.com/v1
kind: Runbook
metadata:
  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:

  1. A single Generation Rule matches AWS EKS Clusters.

  2. It emits an SLX, SLI, and Runbook for each matched cluster.

  3. 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.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.