Skip to content

Useful DKCloudCommand Techniques

The following collection comes from veteran DK command line users. The ideas here have not received thorough platform testing, and are provided as suggestions. Use at your own risk.

Overrides fed from a file

Typically, users define override variables in the UI for a variation or at runtime. Using the CLI, it can be easier to create and reference a JSON file containing override values.

Use case: email an attachment

You can use a JSON parameter file to set recipients, subjects, text, and an attachment.

Example

  • Kitchen: Email_File
  • Recipe: Utility_Email_Approval
  • Variation: send_email_with_attachment
  • Variables:
{
    "s3_bucket": "{{s3Config.bucket}}",
    "s3_access_key": "{{s3Config.access_key}}",
    "s3_secret_key": "{{s3Config.secret_key}}",
    "recipient": "{{CurrentUser}}",
    "text": "This is an example text.",
    "subject": "Email attachment: {{CurrentOrderRunId}}",
    "attachment": "input/spreadsheets/conditional_wb.xlsx"
}

How to

  1. Create the file, for example, email.json.

    {
      "recipient": ["user1@company.com"; "user2@company.com"; "user3@company.com"],
      "text": "This is a body with a long line of text. This is more content. This is more content. This is more content. This is more content.",
      "subject": "Important info from {{CurrentUser}}",
      "attachment": "input/image001.jpg"
    }
    

    Where the following values will override the recipe variables:

    • recipient: the address (or semi-colon delimited addresses) to which the email will be sent.
    • text: the body of the email message specified in the file as a string.
    • subject: the email subject line string (Note that you can use Jinja expressions in these fields, such as the CurrentUsers system variable).
    • attachment: the location and name of the file stored in Amazon S3.
  2. Issue the order-run (or) command.

    Command: (export JSON=$(cat email.json); dk or -p $JSON variation_name)

    Example: (export JSON=$(cat email.json) ; dk or -k Email_File -r Utility_Email_Approval -y -p $JSON send_email_with_attachment)

Use case: update a spreadsheet with query results

This technique gets a Microsoft Excel template from an Amazon S3 resource, runs specific queries, records the results in Excel worksheets, and writes the spreadsheet to S3.

How to

  1. Create the file, for example, excel.json.

    {
      "has_input": true,
      "template_file": "input/spreadsheets/demo_superstore_sales_template.xlsx",
      "output_file": "output/spreadsheets/demo1.xlsx",
      "queries": [
        "select * from development.demo_superstore_sales where segment = 'Consumer';",
        "select * from development.demo_superstore_sales where segment = 'Corporate' and row_id = '26341';"
      ],
      "worksheets": [
        "consumer!A1",
        "corporate!A1"
      ]
    }
    

    Where the following values represent:

    • template_file: the path of the Excel template on S3.
    • output_file: the path of the new Excel spreadsheet on S3.
    • queries: the list of queries to run.
    • worksheets: the locations to add query results.
  2. Issue the order-run (or) command.

    Command: (export JSON=$(cat excel.json); dk or -p $JSON variation_name)

    Example: (export JSON=$(cat excel.json) ; dk or -k create_excel_from_template -r create_excel_from_template -y -p $JSON kitchen_info)