compose-x / ecs_composex

Manage, Configure and Deploy your services and AWS services and applications from your docker-compose definitions
https://docs.compose-x.io
Mozilla Public License 2.0
164 stars 17 forks source link

[BUG] Unable to create multiple x-events for a service #578

Closed krishin-js closed 2 years ago

krishin-js commented 2 years ago

Describe the bug A clear and concise description of what the bug is.

To Reproduce Use-case, I need to trigger a task twice a day - one at 8am and other at 8pm. I've used the following:

x-events:
  TestTaskSchedule:
    Properties:
      Description: "EventRule to trigger the ECS Tasks"
      ScheduleExpression: "cron(0 8 * * ? *)"
      State: "ENABLED"    
    Services:
      - name: service1
        TaskCount: 2
        DeleteDefaultService: True 

  TestTaskSchedule2:
    Properties:
      Description: "EventRule to trigger the ECS Tasks"
      ScheduleExpression: "cron(0 20 * * ? *)"
      State: "ENABLED"    
    Services:
      - name: service1
        TaskCount: 2
        DeleteDefaultService: True 

I was getting the following error:

Traceback (most recent call last):
  File "/usr/local/bin/ecs-compose-x", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.9/site-packages/ecs_composex/cli.py", line 171, in main
    root_stack = generate_full_template(settings)
  File "/usr/local/lib/python3.9/site-packages/ecs_composex/ecs_composex.py", line 664, in generate_full_template
    apply_x_configs_to_ecs(
  File "/usr/local/lib/python3.9/site-packages/ecs_composex/ecs_composex.py", line 199, in apply_x_configs_to_ecs
    invoke_x_to_ecs(None, root_stack, resource_stack, settings)
  File "/usr/local/lib/python3.9/site-packages/ecs_composex/ecs_composex.py", line 173, in invoke_x_to_ecs
    ecs_function(
  File "/usr/local/lib/python3.9/site-packages/ecs_composex/events/events_ecs.py", line 235, in events_to_ecs
    define_service_targets(settings, res_root_stack, rule, cluster_arn)
  File "/usr/local/lib/python3.9/site-packages/ecs_composex/events/events_ecs.py", line 126, in define_service_targets
    service[0].template.add_resource(
  File "/usr/local/lib/python3.9/site-packages/troposphere/__init__.py", line 689, in add_resource
    return self._update(self.resources, resource)
  File "/usr/local/lib/python3.9/site-packages/troposphere/__init__.py", line 658, in _update
    self.handle_duplicate_key(values.title)
  File "/usr/local/lib/python3.9/site-packages/troposphere/__init__.py", line 648, in handle_duplicate_key
    raise ValueError('duplicate key "%s" detected' % key)
ValueError: duplicate key "EventsAccessPolicy" detected

I have noticed that the Policy name is hard-coded to "EventsAccess". We may be able to resolve if we remove the hard-coding.

Expected behavior The cloud formation template should generate as expected with the event rules for the service.

JohnPreston commented 2 years ago

Thanks @krishin-js I will take a look at that for 0.18 / main branch. Keep you posted.