1

AWS CDK provides a function to add new SQS trigger (aka eventSource) to a lambda, addEventSource. But is there a way to get a hand on the existing eventSources that a Lambda might already have, in order to update or disable/enable them for example? Or by default, is there a way to delete the triggers so I can recreate them? Also open to other suggestions.

Thanks a lot

I looked into the documentation but didn't find methods that could help me

tomtom
  • 23
  • 4
  • Not sure if this will lead you anywhere, however, here is what appears to be the cli command for doing that -> https://awscli.amazonaws.com/v2/documentation/api/2.1.21/reference/lambda/delete-event-source-mapping.html – Ross Bush Oct 27 '22 at 19:48
  • that could work as a fallback but is there a way to do this exclusively with CDK? – tomtom Oct 27 '22 at 21:02
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Oct 28 '22 at 07:01
  • CDK doesn't query the existing state, and cannot modify existing resources. – gshpychka Oct 28 '22 at 11:01
  • Hi gshpychka, can you elaborate please? I've been updating resources created by CDK. for example, if I were to change a queue retention period and run CDK again, I would see my queue being updated in cloudformation. Or are you saying this does not apply to event sources only? – tomtom Oct 28 '22 at 21:50

1 Answers1

0

Can you provide some further context, is the current lambda being built by cdk?

It looks like if you use the following, you could toggle the event source:

your_lambda.add_event_source_mapping(enable=false, event_source_arn='your_arn')

In the docs[1] - they explain that the enable arg is:

:param enabled: Set to false to disable the event source upon creation. Default: true

user37649
  • 74
  • 5
  • the triggers are created by SAM commands. the name of the method seems to imply it adds an event (although why provide an event source arn in that case). will give it a try, thanks! I would have loved a solution that doesnt require passing arns but that will work. thanks again! – tomtom Oct 28 '22 at 21:35
  • it fails saying the event source already exists: An event source mapping with SQS arn (" arn:aws:sqs:us-west-2:: ") and function (" ") already exists. Please update or delete the existing mapping with UUID 8 426f82d-87f2-40bc-9d4d-e725dc6b0647 (Service: Lambda, Status Code: 409, Request ID: b441a6b1-bee3-423e-82cd-0ba696ea1558)" (RequestT oken: 24f46acf-5eee-20a6-7c42-68954f23849b, HandlerErrorCode: AlreadyExists) thanks for the suggestion though – tomtom Oct 28 '22 at 21:46