You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@Scheduled events appear to not work at all on AWS Lambda, when custom event IDs are used.
Summary: The short summary is that making scheduled events with custom IDs work (which would be required to not plaster one's AWS account with merged-X lambdas), some non-minor refactoring needs to be done.
As far as I can see from my initial investigation, the issue is as follows:
When the LambdaHandler gets the scheduled event, it contains a resource identifier such as arn:aws:events:us-east-1:123456789012:rule/general-analyseOffers. As the general prefix is contained in the resource ID, the EventsStorage is called to fetch the target function:
for ((ids, method, _) inEventsReflectionScanner.getEvents()) {
val kFunc = method.kotlinFunction!!
for (id in ids) {
cache[id] = kFunc
logger.debug("Saved with key $id function ${kFunc.name} for annotation ${Scheduled::class.simpleName}")
}
}
If there is a custom ID, it is used (analyseOffers in our case), otherwise an ID is generated that that includes the general prefix (e.g. general-12345):
Now, as the Cloudwatch event includes the prefix, but the EventsStorage stored the event using the custom ID which does NOT include the prefix (analyseOffers), the lookup fails silently and the function is NOT called:
This means that for example @Scheduled(Scheduled.everyHour, 'com.example.scheduled') creates a Cloudwatch rule with the name general-com-example-scheduled. Thus during event registration, we need to apply the very same rules to the event ID to make sure that when the event is called, the ID lookup will succeed. The issue with that is that at the moment the logic for generating AWS-compatible names is part of the Gradle plugin, but not of the Kotless runtime library. Basically, the code above and its depending classes (mainly io.kotless.utils.Text from kotless-engine) would have to be moved to a shared library so it can be called both at compile-time and at runtime.
The text was updated successfully, but these errors were encountered:
Move the logic for making event IDs AWS-compatible to some shared library available at both compile-time and runtime
When scanning for @Scheduled events and encourering custom event IDs, use prefix them with ScheduledEventType.General.prefix AND make the event ID AWS-compatible using the same logic as at compile-time
If possible it also would be great to have some form of log message, when an event lookup fails. Failing silently is a really unfortunate option in my opinion.
Originally posted at #82
@Scheduled
events appear to not work at all on AWS Lambda, when custom event IDs are used.Summary: The short summary is that making scheduled events with custom IDs work (which would be required to not plaster one's AWS account with
merged-X
lambdas), some non-minor refactoring needs to be done.As far as I can see from my initial investigation, the issue is as follows:
When the
LambdaHandler
gets the scheduled event, it contains a resource identifier such asarn:aws:events:us-east-1:123456789012:rule/general-analyseOffers
. As thegeneral
prefix is contained in the resource ID, theEventsStorage
is called to fetch the target function:kotless/dsl/kotless/kotless-lang/src/main/kotlin/io/kotless/dsl/app/events/EventsDispatcher.kt
Lines 23 to 27 in 415d5b3
substring
part, the resource ID including thegeneral
prefix is passed as an argument, in this casegeneral-analyseOffers
.The
EventsStorage
scans for all functions with the@Scheduled
annotation and notes their ID:kotless/dsl/kotless/kotless-lang/src/main/kotlin/io/kotless/dsl/app/events/EventsStorage.kt
Lines 21 to 27 in 415d5b3
analyseOffers
in our case), otherwise an ID is generated that that includes thegeneral
prefix (e.g.general-12345
):kotless/dsl/kotless/kotless-lang/src/main/kotlin/io/kotless/dsl/app/events/EventsReflectionScanner.kt
Lines 32 to 37 in 415d5b3
The event is now looked up using the prefixed ID (
general-analyseOffers
):kotless/dsl/kotless/kotless-lang/src/main/kotlin/io/kotless/dsl/app/events/EventsStorage.kt
Line 34 in 415d5b3
EventsStorage
stored the event using the custom ID which does NOT include the prefix (analyseOffers
), the lookup fails silently and the function is NOT called:kotless/dsl/kotless/kotless-lang/src/main/kotlin/io/kotless/dsl/app/events/EventsDispatcher.kt
Line 26 in 415d5b3
And it gets even more complicated. The rule name, that is generated for AWS, is actually modified to fit the AWS naming rules:
kotless/engine/src/main/kotlin/io/kotless/gen/GenerationContext.kt
Lines 63 to 65 in 415d5b3
@Scheduled(Scheduled.everyHour, 'com.example.scheduled')
creates a Cloudwatch rule with the namegeneral-com-example-scheduled
. Thus during event registration, we need to apply the very same rules to the event ID to make sure that when the event is called, the ID lookup will succeed. The issue with that is that at the moment the logic for generating AWS-compatible names is part of the Gradle plugin, but not of the Kotless runtime library. Basically, the code above and its depending classes (mainlyio.kotless.utils.Text
fromkotless-engine
) would have to be moved to a shared library so it can be called both at compile-time and at runtime.The text was updated successfully, but these errors were encountered: