Skip to main content

Templates

Define and share common Tasks with your team.

Introduction#

Templates are pre-defined Tasks stored in a Git repository. These special Tasks have variables defined in their scripts. When creating a Task using a Template, you have to provide only the variables. A regular Task will be created using the Template script filled with the parameters you provide.

This is powerful because you can make high-level abstractions available even to non-technical users.

You can start a Task from Slack providing the parameters to the Runops bot, get reviews, run, and get result logs; all without touching a single line of code. You can also use the Runops CLI.

Let's create a Template for querying DynamoDB. It must provide a better experience than the AWS CLI. AWS CLI makes you create a separate file with your query data, let's improve this!

We will create a Template using Python with AWS's boto3 library. After creating the script, we commit it to the main branch of the Runops Templates repository. Connecting this repository to Runops lets users create Tasks from it.

Create the Template#

Here is our template, lets save it to a file and commit it to the main branch of a Github repository.

#file: dynamodb-query.py
import boto3
client = boto3.client('dynamodb')
response = client.get_item(
Key={
'{{pk}}': {
'S': '{{pk_value}}',
},
'{{sk}}': {
'S': '{{sk_value}}',
},
},
TableName='{{table}}',
)
print(response)

Connect Runops to Github#

To connect Runops to your Templates repository, add the Github user runopsbot as a read-only collaborator to the repository.

You will soon be able to connect using OAuth from the Runops web app.

Check available templates#

Now we can see the template available. Listing the Templates will read all the files in the main branch of the Github repository:

$ runops templates list
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ name β”‚ params β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ dynamodb-query.py β”‚ {{pk}} β”‚
β”‚ β”‚ {{pk_value}} β”‚
β”‚ β”‚ {{sk}} β”‚
β”‚ β”‚ {{sk_value}} β”‚
β”‚ β”‚ {{table}} β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Use a Template#

Create a Task from the Template

runops templates run \
--name dynamodb-query \
--target aws-account-prod-a
--parameters \
table='Music'
pk='Artist', \
pk_value='Acme Band', \
sk='SongTitle'
sk_value='Happy Day'

Use Templates in Slack#

To run templates from Slack, run /runops templates anywhere in your Slack workspace:

Creating Templates#

Templates are very similar to regular Tasks scripts. The only difference is that instead of directly using values in the business logic, we use placeholders. These placeholders are the parameters of our Template. You will provide these values when creating a Task from a Template.

Parameters are indicated by double curly braces.Β {{person}}Β is a parameter, and we'd refer toΒ personΒ as the key or parameter key. Let's take a look at our DynamoDB query template from the Getting Started guide:

dynamodb-query.py

import boto3
client = boto3.client('dynamodb')
response = client.get_item(
Key={
'{{pk}}': {
'S': '{{pk_value}}',
},
'{{sk}}': {
'S': '{{sk_value}}',
},
},
TableName='{{table}}',
)
print(response)

This template has 5 parameters:

table - the name of the DynamoDB table

pk - the name of the Partition Key

sk - the name of the Sort Key

pk_value- the value of the Partition Key

sk_value - the value of the Sort Key

Workflow#

A powerful workflow for Templates is having a central Git repository with scripts certified by stakeholders of a Target. This workflow lets any area of the company take part in automation and speeding up autonomy.

Engineers from multiple teams submit Pull Requests to this repository. After testing, the Template gets merged into the main branch and becomes available to everyone to create Tasks from.

Custom markup