Hey guys… I want to re-use a function, to be call...
# sst
a
Hey guys… I want to re-use a function, to be called by a Cron and also by API GW… Do I need to define the
permissions
on each integration? or I can jut define a Function and assign the permissions to it, and later attach that function to both Cron and GW?
f
Hey @Adrián Mouly, I don’t think you need to define the
permissions
unless the function is going to call AWS SDK to do something.
That said.. I would create 2 functions, and move the common logic into a lib.
a
I need permissions to call EventBridge and SSM.
I mean my lambda needs it.
@Frank why? it’s basically a function that I can trigger in 2 ways.
One manually, and one every 12 hours.
It’s a background sync.
That’s why I need the function to be called from Cron and also from a GW.
t
I personally house near zero logic in my function and put everything in core libraries. That lets me compose that logic into all sorts of functions where I need it
a
But why I would need 2 functions? @thdxr
If the logic it’s exact same.
f
just to give a dummy example… say ur cron job isn’t getting triggered every 12 hrs, and u need to look at the metrics/analytics to figure out how often it’s getting triggered.
a
Why I would need 2 instances of the same?
Ok.
Monitoring.
f
It’d just be easier if u can just look at the Cron function’s log/metrics/analytics.
t
The event sent to the function would be different also right? This only works if you ignore the event
a
Yeah not really concerned about that… but is a good point.
Yes, the event would be different…. but also I can trigger the event from API GW v2.
I mean the EventBridge event.
But yes, is going to be different somehow.
f
on the off chance something goes wrong, it might just be slightly easier to debug when you can differentiate the two functions
a
Yeah makes sense in that case.