How aws-greengrass/aws-greengrass-nucleus works
Project type and purpose
• This is a backend‐only, device‐side orchestration runtime (AWS Greengrass Nucleus) written in Java.
• Purpose: manage and monitor “services” (components) on IoT devices—handling configuration, lifecycle, inter‐process communication (IPC), deployments, and cloud interactions (IoT Jobs, MQTT, S3/ECR, etc.).
File structure
• Top‐level modules (under src/main/java/com/aws/greengrass):
• config (hierarchical key‐value store with watchers)
• dependency (injection framework)
• lifecyclemanager (service FSM, start/stop logic)
• componentmanager (artifact download, dependency resolution, recipe parsing)
• deployment (IoT Jobs integration, deployment queue, activators, bootstrapping)
• provisioning & easysetup (device onboarding)
• ipc (EventStream RPC server & modules)
• mqttclient & iot (publish/subscribe to AWS IoT Core)
• status & telemetry (fleet/status reporting, metrics aggregation)
• security & authorization (token management, policy enforcement)
• util (OS abstraction, systemd/Winsw/procd, platform controllers)
• Scripts (scripts/greengrass.*) and conf (conf/recipe.yaml) support systemd or procd launch.
• Build and CI/config files: pom.xml, .github/workflows, checkstyle, license, README variants.
Readme insights
• Emphasizes four layers: config, dependency DI, lifecyclemanager, util.
• Project is a mash‐up of “make,” pub/sub, key‐value store with continuous adaptation.
a. Local Runtime (Nucleus) – a single process hosting:
• Configuration Store (config)
• Dependency Injector (dependency)
• Lifecycle Manager (lifecyclemanager)
• Component Manager (componentmanager)
• Deployment Service (deployment + IoT Jobs client)
• IPC Server (IPCEventStreamService)
• MQTT Client (awsIoT client)
• Status & Telemetry Agents
• Security & Authorization Module
• EasySetup / Provisioning Modules
b. External Services & Dependencies
• AWS IoT Core (MQTT)
• AWS IoT Jobs (Deployment control plane)
• Artifact Repositories (S3, Docker/ECR, Greengrass Repo)
• System Service Controllers (systemd, procd, Winsw)
c. Data flows & interactions
1. On boot, EasySetup/Provisioning registers device → writes config
2. Deployment Service polls/subscribes to IoT Jobs → on “new job”: download recipe → Component Manager downloads artifacts via S3/ECR → resolve dependencies → update local store → Lifecycle Manager orchestrates start/stop of component processes
3. Components and built-in services communicate via IPC server (publish/subscribe channels)
4. Config store watchers notify dependent modules when config changes
5. Telemetry & Status modules collect state, push metrics/status back to cloud (IoT Core)
6. Security module validates tokens/requests for IPC, network access
7. Util/orchestration modules handle OS‐level process control, permissions, restart logic
d. Architectural patterns & principles
• Dependency Injection (inversion of control for service objects)
• Finite-State Machine for lifecycle phases
• Publish/Subscribe for IPC and config notification
• Modular layering (core nucleus, built-in services, extensions/plugins)
• Pluggable Artifact Downloaders (S3, Docker, Greengrass Repo)
• Cloud-edge decoupling via IoT Jobs & MQTT
e. Technologies & frameworks
• Java 11+
• Maven build
• AWS SDK v2 (IoT, S3, STS)
• EventStream RPC (IPC)
• JNA (native calls)
• systemd / procd / Winsw wrappers