Skip to content

Templates

perpil edited this page Apr 2, 2024 · 32 revisions

Overview

A template is a reusable blueprint that defines what you are trying to do. When you reference one, your wiki entry must only provide the variables and wiki content needed by the template; it relies on the template for the rest. There are several built-in templates, but you can also create your own to simplify repeated effort, i.e. if you constantly need to go to an item in a dynamo table, define a template that takes a table name and an item key like this called DDBItem:

#copy.raw
"DDBItem": {
            "type" : "federate",
            "value" : "dynamodbv2/home?region=${region}#edit-item?table=${tableName}&itemMode=2&pk=${key}&sk${typeof searchKey === 'undefined' ? '' : `=${searchKey}`}&route=ROUTE_ITEM_EXPLORER"
}

Then, all you need to put on your wiki to is the template name, a table name and a prompt for the key like this:

#copy.raw.noPrompts
```
#DDBItem {"tableName":"state"}
//Prompt user to enter the key
~~~key=State Identifier~~~
```

Syntax

Templates live in the templates section of the config. They have a name, type (one of copy, federate, download, or link) and value (the template content). Variables defined in the template other than type and value are available when the template is used.

#copy.raw {"stripComments":true}
#srConfig
{
   "templates" : {
       "name" : {
           "type" : "copy|federate|link|download|iframe",
           "value" : "template content use ${content} to reference wiki content"
       }
   },
   "services" : {
       "ServiceName" : {
           "regions" : {
               "us-east-1" : {
                   //config for us-east-1 region goes here
               },
               "aws" : {
                   //config for aws partition goes here
               }
           }
       }
   }
}

Types

federate

Federate is used to federate to a path in the AWS console in an IAM role. An example would be to go to a specific AWS Step Machine execution using a role. Read more here.

link

Link is used to deeplink to a url. An example would be to link to a specific YouTube video.

download

Download is used to build a file and download it. An example would be to build a CloudFormation template.

copy

Copy is used to copy something to the clipboard. An example would be to build a command line. If you need to get credentials and copy, use these instructions

iframe

Embed an iframe on the page, set the block content to the src of the iframe. An example would be to embed a CloudWatch dashboard on your page. See iframe properties for supported configuration, or the cookbook for examples.

eventbridge

Put an event on an AWS EventBridge event bus with content as the payload. An example would be to send a slack notification.

lambda

Invoke an AWS Lambda function with content as the payload and copy the result to the clipboard. An example would be to invoke a lambda function that blocks a username the user is prompted for. It also works for AWS Lambda function urls.

stepfunction

Invoke an AWS Step Function with content as the payload and open the execution in a new tab. An example would be to kick off a account unlock step function that checks for fraud before reactivating an account.

Built-in templates

CWLInsights

For running a relative time query in CloudWatch Logs Insights

variable purpose required default
content The query to run true undefined
logGroups Array of log groups or single log group true undefined
start Start Time false -3600
end End Time false 0

CWLInsightsSRTimestamp

For running a query in CloudWatch Logs Insights with the last time interval you were looking at

variable purpose required default
content The query to run true undefined
logGroups Array of log groups or single log group true undefined
start Start Time if specified, no dropdown of last 5 times is displayed false undefined
end End Time false undefined

CloudWatchLogs

Go to a log group in Cloudwatch Logs

variable purpose required default
logGroup The log group true undefined

DDBItem

Go to an item in a Dynamo Table

variable purpose required default
tableName Table Name true undefined
partitionKey Partition Key true undefined
sortKey Sort Key false undefined

EC2Instance

Go to an EC2 Instance details page. Either specify the instance id in the speedrun block content, or use the instanceId variable to set it.

variable purpose required default
instanceId Instance Id false undefined

S3Bucket

Go to a S3 bucket

variable purpose required default
bucket S3 Bucket Name true undefined

S3Object

Go to a S3 bucket and key

variable purpose required default
bucket S3 Bucket Name true undefined
key S3 Object Key true undefined

iframe

Render a website in an iframe, the block content is the url for the iframe.

variable purpose required default
src The src of the iframe true undefined
allow iframe allow value false undefined
allow-top-navigation iframe allow-top-navigation value false undefined
allowfullscreen iframe allowfullscreen value false undefined
frameBorder iframe sandbox value false 0
height iframe height value false 480
loading iframe loading value false undefined
name iframe name value false Speedrun Content
sandbox iframe sandbox value false undefined
width iframe width value false 100%

!eventbridge

Publish event to eventbridge using the block content as the payload. Your role requires eventbridge:PutEvents to work.

variable purpose required default
eventBusName The name of the event bus to publish to true undefined
source The source of this event false cc.speedrun
detailType The detail type of this message false Speedrun V<speedrun version> Invocation

!lambda

Invoke a lambda with the block content as the payload. If you use functionName your role requires InvokeFunction permissions. If you use functionUrl your role requires InvokeFunctionUrl permissions, you get access to caller identity in your Lambda, and it uses Lambda Function Urls

Transforming the output

Beta If you want to transform the output of the lambda before copying it to the clipboard put ---output--- on a new line and follow it with the transform template. Use $ to reference the output of the lambda. If the lambda returns content-encoding application/json, it is an object and you can use dot notation to reference keys. Here's an example of how you might extract the greeting from the lambda response and prefix it with some text.

#copy.raw.noPrompts
```
#!lambda {functionName:'HelloFunction'}
{
   "name" : "~~~Name~~~"
}
---output---
The lambda returned: ${$.greeting}
```
variable purpose required default
functionName The name of the lambda function to invoke this or functionUrl is required undefined
functionUrl The subdomain for the lambda function url or full lambda function url this or functionName is required undefined

!stepfunction

Invoke a step function with the block content as the payload. Your role requires stepfunction:StartExecution and stepfunction:DescribeExecution permissions.

variable purpose required default
functionName The name of the step function to invoke true undefined