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.
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:
- AWS Account: Ensure you have access to an AWS account with suitable permissions to manage EC2 instances and AMIs.
- AWS CLI: A working setup of the AWS Command Line Interface (CLI) can help in managing resources programmatically.
- CentOS: You're using a CentOS-based VM environment because of the specific package manager (yum) and configuration files we'll use.
- Basic Knowledge of Shell: Understanding basic shell scripting would be advantageous.
- 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
- How do I set up TensorFlow in the Google cloud?
- How do I set up TensorFlow in the Google cloud?
- How do I specify template parameters when running AWS SAM Local?
- How do I ssh to nodes in ACS Kubernetes cluster?
- How do I tell if my container is running inside a Kubernetes cluster?
- How do I terraform Amazon MSK topics?
- How do I test a module that depends on boto and an Amazon AWS service?
- How do I to forward example.com to www.example.com at godaddy for s3 hosted site?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack 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.