Configset DSL

Configsets can be written with a DSL. The DSL generates the AWS::CloudFormation::Init YAML structure. The DSL stays very close to the underlying structure, so there’s little mental mapping.

The DSL form is the preferred form because it is generally more maintainable over the long haul. It also easy to extend the DSL with your own helpers. Helpers are one of the big reasons it leads to improved maintainability.

Example

package("yum",
  httpd: []
)
file("/var/www/html/index.html",
  content: "<h1>headline</h1>"
)
service("sysvinit",
  httpd: {
    enabled: true,
    ensureRunning: true,
  }
)

This generates:

AWS::CloudFormation::Init:
  configSets:
    default:
    - main
  main:
    packages:
      yum:
        httpd: []
    files:
      "/var/www/html/index.html":
        content: "<h1>headline</h1>"
    services:
      sysvinit:
        httpd:
          enabled: true
          ensureRunning: true

DSL Methods

Method Description
package You can use the packages key to download and install pre-packaged applications and components. On Windows systems, the packages key supports only the MSI installer. The package method maps to the AWS::CloudFormation::Init packages section.
group You can use the groups key to create Linux/UNIX groups and to assign group IDs. The group method maps to the AWS::CloudFormation::Init groups section.
user You can use the users key to create Linux/UNIX users on the EC2 instance. The user method maps to the AWS::CloudFormation::Init users section.
source You can use the sources key to download an archive file and unpack it in a target directory on the EC2 instance. This key is fully supported for both Linux and Windows systems. The source method maps to the AWS::CloudFormation::Init sources section.
file You can use the files key to create files on the EC2 instance. The content can be either inline in the template or the content can be pulled from a URL. The file method maps to the AWS::CloudFormation::Init files section.
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.
service You can use the services key to define which services should be enabled or disabled when the instance is launched. On Linux systems, this key is supported by using sysvinit. On Windows systems, it is supported by using the Windows service manager. The service method maps to the AWS::CloudFormation::Init services seciton.
configset You can use the configset method to build multiple configset blocks within one configset. This allow you to better organize large configsets. Also, as noted in AWS::CloudFormation::Init, cfn-init processes configuration sections in a specific order. So this can also be useful if you need to more control over ordering.

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!