I want to start ECS task that will do some stuff with RDS DB after my service is redeployed via my CI pipeline, is there any option to catch such event using EventBridge?
I tried to catch deployment state, but really didn't get how to use it. I can't catch specific deployment ID and check it's status, also it happens not only when it is redeployed, but also during scaling operations.
I want to start ECS task that will do some stuff with RDS DB after my service is redeployed via my CI pipeline, is there any option to catch such event using EventBridge?
I tried to catch deployment state, but really didn't get how to use it. I can't catch specific deployment ID and check it's status, also it happens not only when it is redeployed, but also during scaling operations.
Share Improve this question asked Nov 19, 2024 at 15:20 Dmytro KostinDmytro Kostin 1 3 |1 Answer
Reset to default 0EventBridge can capture ECS service deployment events. Specifically, when an ECS service is updated or a new deployment is triggered, EventBridge emits an event. However, deployment events may also occur during scaling operations, as you’ve noticed.
I think the best option which i can see is to create a create an SSM parameter with DEPLOYMENT ID or something and update it at the end of your CI pipeline. and whenever that parameter get updated you can trigger an event bridge to launch specific job.
or keep the same structure, but update the event bridge to trigger a Lambda function and that lambda function check wether the Launch template is a new one or no. if it's a new one, then it's a new deployment, if it's an old one, then there's a scaling either up or down.
While you can create an event for the creation of a task definitions using EventBridge, it does not guarantee that the new template is actually used in a deployment. This creates a risk of triggering tasks or workflows based on a false assumption that the new task definitions is active, it can be created for future use or something.
This tells you a new task definition is available. However, it doesn’t confirm the task definition is used in a service yet.
{
"source": ["aws.ecs"],
"detail-type": ["ECS Task Definition State Change"],
"detail": {
"lastStatus": ["ACTIVE"]
}
}
The latest solution, if your CI pipeline is implemented using AWS code Pipeline, you can listen for pipeline execution completion events using EventBridge. These events are specific to the CodePipeline process and will not trigger during ECS scaling.
{
"source": ["aws.codepipeline"],
"detail-type": ["CodePipeline Pipeline Execution State Change"],
"detail": {
"pipeline": ["<your-pipeline-name>"],
"state": ["SUCCEEDED"]
}
}
aws ecs wait services-stable
), and then run the task (aws ecs run-task
) – Mark B Commented Nov 19, 2024 at 15:42