最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

amazon ecs - Start ECS task using Event Bridge after ECS service redeployed - Stack Overflow

programmeradmin0浏览0评论

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
  • Seems like it would be easier to just modify your CI pipeline to wait for the service deployment to complete (aws ecs wait services-stable), and then run the task (aws ecs run-task) – Mark B Commented Nov 19, 2024 at 15:42
  • Yeah, it's kinda easier, so I have to add --network-configuration and explicitly specify which subnet and sg I want to be used by task, but it's not something I want to expose in my CI – Dmytro Kostin Commented Nov 19, 2024 at 16:01
  • You don't want to expose the security group IDs and subnet IDs in your CI tool? Are you afraid that is a security risk or something? – Mark B Commented Nov 19, 2024 at 16:45
Add a comment  | 

1 Answer 1

Reset to default 0

EventBridge 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"]
  }
}
发布评论

评论列表(0)

  1. 暂无评论