command

You can use the commands key to execute commands on the EC2 instance. The command method maps to the AWS::CloudFormation::Init commands section.

Example

command("create-file",
  command: "touch /tmp/test.txt",
  test: "test -e /tmp/test.txt",
)
command("uptime-command",
  command: "uptime"
)

Generates:

AWS::CloudFormation::Init:
  configSets:
    default:
    - main
  main:
    commands:
      001_create-file:
        command: touch /tmp/test.txt
        test: test -e /tmp/test.txt
      002_uptime-command:
        command: uptime

Command Conveniences

Notice above, lono prepends a padded number in front of the command key as a convenience. This is done so commands are processed in the order you declare them. Lono decorates the command method with other conveniences.

if clause

command("create-file",
  command: "touch /tmp/test.txt",
  if: "[ -e /tmp/test.txt ]",
)

Generates:

AWS::CloudFormation::Init:
  configSets:
    default:
    - main
  main:
    commands:
      001_create-file:
        command: touch /tmp/test.txt
        test: if [ -e /tmp/test.txt ] ; then true ; else false ; fi

unless clause

command("install-jq",
  command: "yum install jq",
  unless: "type jq",
)

Generates:

AWS::CloudFormation::Init:
  configSets:
    default:
    - main
  main:
    commands:
      001_install-jq:
        command: yum install jq
        test: if type jq ; then false ; else true ; fi

Back to DSL Docs

Pro tip: Use the <- and -> arrow keys to move back and forward.

Edit this page

See a typo or an error? You can improve this page. This website is available on GitHub and contributions are encouraged and welcomed. We love pull requests from you!