Expand description
AWS EC2 deployer
Deploy a custom binary (and configuration) to any number of EC2 instances across multiple regions. View metrics and logs from all instances with Grafana.
§Features
- Automated creation, update, and destruction of EC2 instances across multiple regions
- Provide a unique name, instance type, region, binary, and configuration for each deployed instance
- Collect metrics, profiles (when enabled), and logs from all deployed instances on a long-lived monitoring instance (accessible only to the deployer’s IP)
§Architecture
Deployer's Machine (Public IP)
|
|
v
+-----------------------------------+
| Monitoring VPC (us-east-1) |
| - Monitoring Instance |
| - Prometheus |
| - Loki |
| - Pyroscope |
| - Tempo |
| - Grafana |
| - Security Group |
| - All: Deployer IP |
| - 3100: Binary VPCs |
| - 4040: Binary VPCs |
| - 4318: Binary VPCs |
+-----------------------------------+
^ ^
(Telemetry) (Telemetry)
| |
| |
+------------------------------+ +------------------------------+
| Binary VPC 1 | | Binary VPC 2 |
| - Binary Instance | | - Binary Instance |
| - Binary A | | - Binary B |
| - Promtail | | - Promtail |
| - Node Exporter | | - Node Exporter |
| - Pyroscope Agent | | - Pyroscope Agent |
| - Memleak Agent | | - Memleak Agent |
| - Security Group | | - Security Group |
| - All: Deployer IP | | - All: Deployer IP |
| - 9090: Monitoring IP | | - 9090: Monitoring IP |
| - 9100: Monitoring IP | | - 9100: Monitoring IP |
| - 9200: Monitoring IP | | - 9200: Monitoring IP |
| - 8012: 0.0.0.0/0 | | - 8765: 12.3.7.9/32 |
+------------------------------+ +------------------------------+
§Instances
§Monitoring
- Deployed in
us-east-1
with a configurable ARM64 instance type (e.g.,t4g.small
) and storage (e.g., 10GB gp2). - Runs:
- Prometheus: Scrapes binary metrics from all instances at
:9090
and system metrics from all instances at:9100
. - Loki: Listens at
:3100
, storing logs in/loki/chunks
with a TSDB index at/loki/index
. - Pyroscope: Listens at
:4040
, storing profiles in/var/lib/pyroscope
. - Tempo: Listens at
:4318
, storing traces in/var/lib/tempo
. - Grafana: Hosted at
:3000
, provisioned with Prometheus and Loki datasources and a custom dashboard.
- Prometheus: Scrapes binary metrics from all instances at
- Ingress:
- Allows deployer IP access (TCP 0-65535).
- Binary instance traffic to Loki (TCP 3100), Pyroscope (TCP 4040), and Tempo (TCP 4318).
§Binary
- Deployed in user-specified regions with configurable ARM64 instance types and storage.
- Run:
- Custom Binary: Executes with
--hosts=/home/ubuntu/hosts.yaml --config=/home/ubuntu/config.conf
, exposing metrics at:9090
. - Promtail: Forwards
/var/log/binary.log
to Loki on the monitoring instance. - Node Exporter: Exposes system metrics at
:9100
. - Pyroscope Agent: Forwards
perf
profiles to Pyroscope on the monitoring instance. - Memleak Agent: Exposes
memleak
metrics at:9200
.
- Custom Binary: Executes with
- Ingress:
- Deployer IP access (TCP 0-65535).
- Monitoring IP access to
:9090
,:9100
, and:9200
for Prometheus. - User-defined ports from the configuration.
§Networking
§VPCs
One per region with CIDR 10.<region-index>.0.0/16
(e.g., 10.0.0.0/16
for us-east-1
).
§Subnets
Single subnet per VPC (e.g., 10.<region-index>.1.0/24
), linked to a route table with an internet gateway.
§VPC Peering
Connects the monitoring VPC to each binary VPC, with routes added to route tables for private communication.
§Security Groups
Separate for monitoring (tag) and binary instances ({tag}-binary
), dynamically configured for deployer and inter-instance traffic.
§Workflow
§ec2 create
- Validates configuration and generates an SSH key pair, stored in
/tmp/deployer-{tag}/id_rsa_{tag}
. - Creates VPCs, subnets, internet gateways, route tables, and security groups per region.
- Establishes VPC peering between the monitoring region and binary regions.
- Launches the monitoring instance, uploads service files, and installs Prometheus, Grafana, Loki, and Pyroscope.
- Launches binary instances, uploads binaries, configurations, and hosts.yaml, and installs Promtail and the binary.
- Configures BBR on all instances and updates the monitoring security group for Loki traffic.
- Marks completion with
/tmp/deployer-{tag}/created
.
§ec2 update
- Stops the
binary
service on each binary instance. - Uploads the latest binary and configuration from the YAML config.
- Restarts the
binary
service, ensuring minimal downtime.
§ec2 authorize
- Obtains the deployer’s current public IP address (or parses the one provided).
- For each security group in the deployment, adds an ingress rule for the IP (if it doesn’t already exist).
§ec2 destroy
- Terminates all instances across regions.
- Deletes security groups, subnets, route tables, VPC peering connections, internet gateways, key pairs, and VPCs in dependency order.
- Marks destruction with
/tmp/deployer-{tag}/destroyed
, retaining the directory to prevent tag reuse.
§Persistence
- A temporary directory
/tmp/deployer-{tag}
stores the SSH private key, service files, and status files (created
,destroyed
). - The deployment state is tracked via these files, ensuring operations respect prior create/destroy actions.
§Example Configuration
tag: ffa638a0-991c-442c-8ec4-aa4e418213a5
monitoring:
instance_type: t4g.small
storage_size: 10
storage_class: gp2
dashboard: /path/to/dashboard.json
instances:
- name: node1
region: us-east-1
instance_type: t4g.small
storage_size: 10
storage_class: gp2
binary: /path/to/binary
config: /path/to/config.conf
profiling: true
- name: node2
region: us-west-2
instance_type: t4g.small
storage_size: 10
storage_class: gp2
binary: /path/to/binary2
config: /path/to/config2.conf
profiling: false
ports:
- protocol: tcp
port: 4545
cidr: 0.0.0.0/0
Modules§
- aws
- AWS EC2 SDK function wrappers
- services
- Service configuration for Prometheus, Loki, Grafana, Promtail, and a caller-provided binary
- utils
- Utility functions for interacting with EC2 instances
Structs§
- Config
- Deployer configuration
- Host
- Host deployment information
- Hosts
- List of hosts
- Instance
Config - Instance configuration
- Monitoring
Config - Monitoring configuration
- Port
Config - Port configuration
Enums§
- Error
- Errors that can occur when deploying infrastructure on AWS
Constants§
- AUTHORIZE_
CMD - Authorize subcommand name
- CMD
- Subcommand name
- CREATE_
CMD - Create subcommand name
- DESTROY_
CMD - Destroy subcommand name
- METRICS_
PORT - Port on binary where metrics are exposed
- UPDATE_
CMD - Update subcommand name