AWS
cloud-init
CentOS
custom AMIs
cloud setup

How do I set up cloud-init on custom AMIs in AWS? CentOS

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Cloud-init is an essential tool for automating cloud instance configuration. The setup of cloud-init on custom Amazon Machine Images (AMIs) in AWS, especially CentOS, requires some specific steps. This article guides you through the necessary configuration and usage to harness the power of cloud-init effectively.

Prerequisites

Before venturing into configuring cloud-init for custom AMIs on AWS, ensure the following prerequisites:

  1. AWS Account: Ensure you have access to an AWS account with suitable permissions to manage EC2 instances and AMIs.
  2. AWS CLI: A working setup of the AWS Command Line Interface (CLI) can help in managing resources programmatically.
  3. CentOS: You're using a CentOS-based VM environment because of the specific package manager (yum) and configuration files we'll use.
  4. Basic Knowledge of Shell: Understanding basic shell scripting would be advantageous.
  5. Familiarity with YAML: Since cloud-init uses YAML syntax for user data scripts, a basic familiarity is needed.

Installing Cloud-init on CentOS

To get started with cloud-init, begin by installing it on your CentOS-based instance:

  • default
  • migrator
  • bootcmd
  • write-files
  • set-hostname
  • update hostname
  • rsyslog
  • users-groups
  • mounts
  • locale
  • set-passwords
  • timezone
  • puppet
  • disable-ec2-metadata
  • Users: Configures default users. Here, a default user is specified.
  • Root Login: With `disable_root: 0`, root login is enabled.
  • Password Authentication: Enabled using `ssh_pwauth: 1`.
  • Set Passwords: Managed via the `chpasswd` section.
  • Modules: Sequence of operations cloud-init should perform categorized as `cloud_init_modules` and `cloud_config_modules`.
    • Clear SSH host keys: `sudo shred -u /etc/ssh/_key /etc/ssh/_key.pub`.
    • Remove cloud-init logs: `sudo rm -rf /var/log/cloud-init*`.
    • Clear network configurations and user ssh keys if necessary.
    • httpd
    • [ systemctl, start, httpd.service ]
    • [ systemctl, enable, httpd.service ]
  • Logs: Investigate logs in `/var/log/cloud-init.log` and `/var/log/cloud-init-output.log` for debugging.
  • Module Failures: Check YAML syntax and module sequence in `cloud.cfg` if certain actions don’t occur.
  • Permissions: Ensure AWS IAM roles provide required permissions for tasks set via cloud-init.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.