- Newest
- Most votes
- Most comments
In AWS IoT Greengrass V2, components will restart during deployment even if they haven't changed, but there are several approaches to prevent this behavior:
-
Use the DeploymentComponentUpdatePolicy: When creating your deployment, you can set the update policy action to
NOTIFY_COMPONENTS. This allows components to receive notifications before they're stopped and updated. Components can then use the SubscribeToComponentUpdates IPC operation to receive these notifications and respond with the DeferComponentUpdate IPC operation. -
Component State Management: Design your components to maintain their own state. Your component can check if it has already run and decide whether to execute its main logic or simply exit. This can be implemented by having the component write a status to a file or database after the first run, and on subsequent runs, check this state and exit if it determines it should not run again.
-
Use the Skipif Lifecycle Field: In your component recipe, you can use the Skipif lifecycle field to conditionally skip execution based on certain criteria. For example:
{
"Lifecycle": {
"Run": {
"Script": "python3 /path/to/your/script.py",
"Skipif": "[ -f /path/to/marker.file ]"
}
}
}
-
Leverage Component Versioning: Design your components to only run once per version. After a deployment, it would not run again unless a new version of the component is deployed.
-
Modify Environment Variables: Greengrass restarts a component when its
Setenvconfiguration changes. You can use this behavior to your advantage by only changing environment variables for components you want to restart, while keeping them the same for components you want to keep running.
Remember that when you create a new deployment for a target that already has a deployment, the components in the new deployment replace those from the previous deployment. If you want to preserve existing components, consider using the "revise deployments" approach, which allows you to update only specific components without removing others that are already running on the core devices.
Sources
How do I redeploy the same deployment config in Greengrass v2 | AWS re:Post
DeploymentComponentUpdatePolicy - AWS IoT Greengrass
How to make a greengrass component run only once? | AWS re:Post
Revise deployments - AWS IoT Greengrass
(1) Would work if components can determine a good time to restart (e.g. right after sending a heartbeat, emptying most or all of the logs). (2) is probably not applicable since these are long-running services. (3) N/A (Component would be stopped and never run again) (4) N/A (Component isn't having its version bumped) (5) Not sure if this is a culprit.
nothing worked
Relevant content
- asked 3 years ago
- asked 10 months ago

Do these component have any dependencies on each other? Greengrass will restart dependent components if they have a HARD dependency on an updated component. This is not true of components with a SOFT dependency on an updated component. https://docs.aws.amazon.com/greengrass/v2/developerguide/component-recipe-reference.html#recipe-format Search for the
ComponentDependenciesfield.While this is unrelated to why the component is restarting, specifying the image as an Artifact instead of downloading it each time in the Lifecycle step would reduce the time taken for the component to restart. https://docs.aws.amazon.com/greengrass/v2/developerguide/run-docker-container.html#run-docker-container-private-ecr