Customized cloud-init - Amazon Linux 2022
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China.

Amazon Linux 2022 is in preview release and is subject to change.

Customized cloud-init

The cloud-init package is an open-source application that bootstraps Linux images in a cloud computing environment. For more information, see the cloud-init documentation.

Amazon Linux 2022 contains a customized version of cloud-init. With cloud-init, you can specify what occurs to your instance at boot time.

When you launch an instance, you can use user-data fields to pass actions to cloud-init. This means that you can use common Amazon Machine Images (AMIs) for many use cases and configure them dynamically when you start an instance. Amazon Linux 2022 also uses cloud-init to configure the ec2-user account.

Amazon Linux 2022 uses the cloud-init actions in /etc/cloud/cloud.cfg.d and /etc/cloud/cloud.cfg. You can create your own cloud-init action files in the /etc/cloud/cloud.cfg.d directory. Cloud-init reads all the files in this directory in lexicographical order. Later files overwrite values in earlier files. When cloud-init launches an instance, the cloud-init package does the following configuration tasks:

  • Sets the default locale

  • Sets the hostname

  • Parses and handles user-data

  • Generates host private SSH keys

  • Adds a user's public SSH keys to .ssh/authorized_keys for easy login and administration

  • Prepares the repositories for package management

  • Handles package actions that are defined in user-data

  • Runs user scripts that are in user-data

  • Mounts instance store volumes, if applicable

    • By default, if the ephemeral0 instance store volume is present and contains a valid file system, the instance store volume is mounted at /media/ephemeral0. Otherwise, it's not mounted.

    • By default, for the m1.small and c1.medium instance types, all swap volumes that are associated with the instance are mounted.

    • You can override the default instance store volume mount with the following cloud-init directive:

      #cloud-config mounts: - [ ephemeral0 ]

      For more control over mounts, see Mounts in the cloud-init documentation.

    • When an instance launches, instance store volumes that support TRIM aren't formatted. Before you can mount instance store volumes, you must partition and format instance store volumes.

      For more information, see Instance store volume TRIM support in the Amazon EC2 User Guide for Linux Instances.

    • When you launch your instances, you can use the disk_setup module to partition and format your instance store volumes.

      For more information, see Disk Setup in the cloud-init documentation.

For information about using cloud-init with SELinux, see Use cloud-init to enable enforcing mode.

For information about cloud-init user-data formats, see User-Data Formats in the cloud-init documentation.

For more information about cloud-init, see the cloud-init Documentation.