Lambda commands

Assigning an Opsidian command to a Lambda function

With Opsidian it is possible to trigger Lambda functions from Slack. In order to assign a Lambda function to an Opsidian command, go to the Opsidian dashboard and sign in. Go to "Lambda functions" and click "Add a new Lambda function command". Select the account, region and Lambda function and define what command should trigger the function.

Allowing only specific users to run a Lambda command

You can decide which users are able to run your Lambda commands. First create a group:

/ops group add <group-name>

                /ops group add run-summarize

Next add users that you want to be able to run the Lambda command to the group:

/ops group add-user <username> <group-name>

                /ops group add-user @john run-summarize

Finally, to assign the Lambda command to the group, go to the Lambda configuration page in the Opsidian dashboard. Click "Edit" next to the Lambda command, select a group in the "Group" dropdown list and click "Save". From now on, only users assigned to this group will be able to run this Lambda function.

Adding all channel users to a group

You can add all Opsidian users from a specific channel to a group by running the following command in the channel:

                /ops group add-all <group_name>

                /ops group add-all run-summarize
To see the hepl section about groups, use:

                /ops group help
Running Lambda commands

The following command will trigger the Lambda function in the selected account and region.

/ops run <command>

                /ops run hello

In order to invoke the Lambda function, the Opsidian role or user needs an "lambda:InvokeFunction" policy. After you create the Lambda command in the dashboard, Opsidian will perform a dry run of the function to check the permissions. If there is an issue, the dashboard will display instructions on how to add the policy.

The policy has the following form:

  "Version": "2012-10-17",
  "Statement": [
    "Effect": "Allow",
    "Action": ["lambda:InvokeFunction"],
    "Resource": [LAMBDA_FUNCTION_ARN]

The policy allows the Opsidian role or user to run this particular Lambda function.


Remember that a Lambda command can be triggered by any Opsidian user that belongs to the group assigned to the command - think carefully about the implications. It is up to you to ensure that the Lambda function is safe.

Waiting for a response

If you choose to "Wait for a response", Opsidian will wait for up to 5 seconds for a response from the Lambda function. The response should contain a message key. The value of message will be displayed in Slack.

The following Lambda function will display a "Hello World!" message in Slack, when triggered with Opsidian:

import json

def lambda_handler(event, context):
    return json.dumps({'message': 'Hello world!'})

If you choose not to wait for a response, Opsidian will display a generic message about the function being triggered.

Passing arguments

It is possible to pass arguments into the Lambda function, by appending them to the command:

/ops run <command> arg1 arg2

The arguments can be used in the Lambda function in the following way:

import json

def lambda_handler(event, context):
    args = None
    if 'args' in event:
        args = event['args']

    return json.dumps({'message': 'Your args: {}!'.format(args)})

In the following example, the argument "world" is passed to the Lambda function:

              /ops run hello world
Default arguments:

By default Opsidian passes the following arguments to your Lambda function:

  "region": <region>,
  "aws_account_id": <account_id>,
  "user_name": <username>, # who triggered the command
  "account_name": <account_name>,
  "args": <your-args>

Powered by PrettyDocs.



Privacy Policy
© Opsidian 2018