Setup workflow

In this tutorial you will learn how to setup a simple workflow that allows you to handle any type of documents in a safe and semi-automatic way.

The workflow in this tutorial will consist of two steps:

  • automatic prediction

  • manual verification

Workflow

Prerequisites

Manual approval (manual transition)

To create a manual step you first need a remote component that will serve as a user interface. If you are using this standard remote component you can also configure the fields to show and manipulate by adding an asset called fieldConfig. Here is an example of a field config for a typical invoice.

Create the remote component asset

When you have created your javascript remote component, lets call it remote_component.js you are ready to create an asset.

$ las assets create remote_component.js

This should give the following output:

{
"assetId": "las:asset:<hex-uuid>",
"name": null,
"description": null
}

You now have an assetId that we will use to refer to this specific asset in the future. Note that you can also add a name and a description to help you identify the asset.

Create the transition

Create a json file, let's call it params.json with the following structure:

{
"assets": {
"jsRemoteComponent": "las:asset:<hex-uuid>",
"fieldConfig": "las:asset:<hex-uuid>"
}
}

jsRemoteComponent and fieldConfig are used to find the assets, so they have to be named like this if you want to use them.

Where las:asset:<hex:uuid> is replaced with the assetId you got in the previous step. Now you are ready to create the manual step

las transitions create manual -p params.json

This should give the following output

{
"transitionId": "las:transition:<hex-uuid>",
"name": null,
"description": null,
"transitionType": "manual",
"inputJsonSchema": {
"$schema": "https://json-schema.org/draft-04/schema#"
},
"outputJsonSchema": {
"$schema": "https://json-schema.org/draft-04/schema#"
},
"parameters": {
"assets": {
"jsRemoteComponent": "las:asset:<hex-uuid>"
}
}
}

As you can see from the output the transition can also accept name and description arguments, that is common for most resources in LAS. In addition we recommend to provide input and output json-schemas that can help you catch bad input immediately instead of triggering bugs at a later point in the workflow. Use las transitions update --help for more information on how to update your transitions.

Automatic prediction (docker transition)

An automatic step is made by creating a docker image that will perform a task without any user involved. Check our sample images and tutorial for inspiration and best practices.

The first step is to build a docker image and push it to some repository

$ docker build . -t <image-url> && docker push <image-url>

It is recommended to place the docker image in a private repository, if that is the case you need to store your credentials as a secret.

$ las secrets create username=<username> password=<password> --description 'docker credentials'

The next step is to create a json-file that contains the parameters you need to run the docker image.

{
"imageUrl": "<image-url>",
"secretId": "las:secret:<hex-uuid>"
}

The secretId field is only needed if you are using a private image.

Now we are ready to create the transition

las transitions create docker params.json

Creating the workflow

Now that we have created the two transitions we are ready to put them together in a single workflow. The workflow definition must be provided using Amazon States Language.

The Resource name of each state must be a transition ID.

The only allowed types of States are Task and Choice.

{
"definition": {
"Comment": "A workflow for prediction and approval",
"StartAt": "Predict",
"States": {
"Predict": {
"Type": "Task",
"Resource": "las:transition:<docker-hex>",
"Next": "Approve"
},
"Approve": {
"Type": "Task",
"Resource": "las:transition:<manual-hex>",
"End": true
}
}
}
}

store the file and use it as input for creating the workflow

$ las workflows create workflow.json --name 'Predict and Approve'

Execute workflow

You can now define your input.json and execute your workflow with a simple call from the CLI

{
"documentId": "las:document:<hex-uuid>",
"modelId": "las:model:<hex-uuid>"
}
$ las workflows execute las:workflow:<hex-uuid> input.json

You can also use this script for execution, or use or standard email-integration that will allow you to send in your documents by email.