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 raw form, not base64-encoded form.
  • 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 cloud-init >= 0.7.9 for automatic disk 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 user-data following options are used:

  • merge_how: this options is necessary for applying cloud-init configuration via user-data;
  • cloud_init_modules: list of utilized cloud-init modules;
  • disk_setup: This module enables configuration of simple partition tables;
    • ebs2: The virtual devices associated with EBS volumes, if any are present;
      • table_type: This option specifies the partition table type, either mbr or gpt;
      • layout: This option specifies how partitions on the device are to be arranged;
      • overwrite: If overwrite: true is set, no checks for a partition table and for a file system will be performed;

You can find more information about dist_setup module at disk_setup documentation