@@ -32,6 +32,9 @@ module "eventbridge" {
3232 attach_cloudwatch_policy = true
3333 cloudwatch_target_arns = [aws_cloudwatch_log_group . this . arn ]
3434
35+ attach_ecs_policy = true
36+ ecs_target_arns = [aws_ecs_task_definition . hello_world . arn ]
37+
3538 rules = {
3639 orders = {
3740 description = " Capture all order data"
@@ -90,6 +93,15 @@ module "eventbridge" {
9093 dead_letter_arn = aws_sqs_queue.dlq.arn
9194 input_transformer = local.order_input_transformer
9295 attach_role_arn = true
96+ },
97+ {
98+ name = " process-email-with-ecs-task" ,
99+ arn = module.ecs.ecs_cluster_arn,
100+ attach_role_arn = true
101+ ecs_target = {
102+ task_count = 1
103+ task_definition_arn = aws_ecs_task_definition.hello_world.arn
104+ }
93105 }
94106 ]
95107 }
@@ -248,3 +260,43 @@ module "step_function" {
248260 }
249261 }
250262}
263+
264+ # #####
265+ # ECS
266+ # #####
267+
268+ module "ecs" {
269+ source = " terraform-aws-modules/ecs/aws"
270+ version = " ~> 3.0"
271+
272+ name = random_pet. this . id
273+
274+ capacity_providers = [" FARGATE" , " FARGATE_SPOT" ]
275+ }
276+
277+ resource "aws_ecs_service" "hello_world" {
278+ name = " hello_world-${ random_pet . this . id } "
279+ cluster = module. ecs . ecs_cluster_id
280+ task_definition = aws_ecs_task_definition. hello_world . arn
281+ launch_type = " FARGATE"
282+
283+ desired_count = 1
284+
285+ deployment_maximum_percent = 100
286+ deployment_minimum_healthy_percent = 0
287+ }
288+
289+ resource "aws_ecs_task_definition" "hello_world" {
290+ family = " hello_world-${ random_pet . this . id } "
291+
292+ container_definitions = << EOF
293+ [
294+ {
295+ "name": "hello_world-${ random_pet . this . id } ",
296+ "image": "hello-world",
297+ "cpu": 0,
298+ "memory": 128
299+ }
300+ ]
301+ EOF
302+ }
0 commit comments