This repository contains the Ansible cookbooks and the Packer configuration to generate the AWS AMI, which we use at codemonauts to start our EC2 instances.
If you find some problems or errors in this repositoy feel free to open an issue or directly fix it with an pull request if you want to.
As a basis we choose the latest Debian from the official AWS AMI store. On top of this we did the following for the base images:
- Deactivate the default 'admin' user
- Create our own 'codemonauts' user with our current SSH public key
- Activate daily unattended-updates for security patches
- Install the AWS Codedeploy agent
- Install the AWS SSM agent
- Install some basic CLI tools
Additionaly on top for the webserver images:
- Install Nginx and add our config snippets
- Install mozjpeg for improved JPEG encoding
- Install PHP-FPM and some PHP Modules which are used by CraftCMS
All images are public and available in eu-central-1. The XXX in the AMI name is the timestamp during build in the format YYYY-MM-DD-hh-mm.
codemonauts-<arch>-<codename>-base_XXX
codemonauts-<arch>-<codename>-webserver-php<version>_XXX
<arch> is amd64 or arm64, <codename> is the Debian release, <version> is the PHP version without the dot. The defaults live at the top of the justfile.
- Allow direnv to run in the cloned repository.
Run just --list to see all available recipes.
just test amd64
just test-allThe webserver image builds on top of the base image, so just build creates both in that order:
just build # asks for the architecture
just build amd64 # defaults from the justfile
just build amd64 bookworm 8.3 # a different combination
just build-all # both architecturesjust stale-amis lists AMIs beyond the newest 3 of their family, just clean-amis deletes them after you confirm. A family is the AMI name without its timestamp, so every architecture, Debian release and PHP version is counted separately.
An AMI is only offered when it is older than 14 days, is not among the newest 3 of its family, and no launch template version in this account references it. just build prints how many could be cleaned up but never deletes anything itself.
asg-sets.json is the central catalogue of default instance sets for the
autoscaling groups of the consuming provisioning repos. This repo has no
autoscaling groups of its own — it only holds the catalogue, the way it builds
their base image.
A set has a handle and holds the shared attributes once, with a branch per architecture for the CPU manufacturers and the type list:
jq '.sets | keys' asg-sets.json
jq '.sets.small' asg-sets.jsondefaults.InstancesDistribution applies to every set that does not carry its
own. Consumers pull the file with just asg-sets-sync and compare it against a
single ASG config with just asg-diff-set <asg> <arch> <handle>. A repo config
may deviate — the sets are defaults, not a contract.
Two things to keep in mind when editing a set:
BurstablePerformance must stay included for any set listing t3*/t4g*
types. The AWS default is excluded and AllowedInstanceTypes does not
override the attribute filters, so those types would drop out of the pool
without an error.
The VCpuCount and MemoryMiB ranges are a tight fit around the listed types.
Adding a larger type without widening them makes it ineffective, again without
an error. Verify every change:
aws ec2 get-instance-types-from-instance-requirements \
--architecture-types x86_64 --virtualization-types hvm \
--instance-requirements file://ir.json \
--query 'InstanceTypes[].InstanceType'The result must match AllowedInstanceTypes exactly.