Adding User Data#

When you specify user data, note the following:

  • User data is treated as opaque data: what you give is what you get back. It is up to the instance to be able to interpret it.

  • User data is limited to 16 KB. This limit applies to the data in the raw format, not base64-encoded.

  • User data must be base64-encoded before being submitted to the API. The EC2 command line tools perform the base64 encoding for you. The data is decoded before being presented to the instance.

  • You can pass cloud-init configuration via user-data.

Cloud-init#

Cloud-init can configure instance on start. Yaml formatted cloud-init config can be passed via user-data attribute. cloud-init is available for various modern Linux and FreeBSD distributions.

Disk partitioning with cloud-init#

Note

You can use the cloud-init version 0.7.9 or later for automatic volume partitioning.

user-data
#cloud-config
merge_how: "dict(recurse_array)+list(recurse_list,recurse_str)+str()"

cloud_init_modules:
- disk_setup

disk_setup:
  ebs2:
    table_type: 'mbr'
    layout:
    - [66, 83]
    - [33, 82]
    overwrite: true

In the example above the following options are used:

  • merge_how — This options is necessary for applying cloud-init configuration via user-data;

  • cloud_init_modules — The list of the utilized cloud-init modules.

  • disk_setup — This module enables configuration of simple partition tables.

  • ebs2 — The name of a virtual device associated with an EBS volume, if any are present.

    • table_type — This option specifies the partition table type, either mbr or gpt.

    • layout — This option specifies how the device will be partioned.

    • overwrite — If true, no checks for a partition table and for a file system will be performed.

Note

For more information on the dist_setup module, see the official documentation cloud-init