serverless: MSK support as an event to trigger Lambdas
Lambda now supports Amazon MSK as an event source, so it can consume messages and integrate with downstream serverless workflows. It will be great to have a Kafka event to trigger the functions from serverless.
https://aws.amazon.com/es/blogs/compute/using-amazon-msk-as-an-event-source-for-aws-lambda/
Proposed solution
(Updated on the go, to reflect final agreement):
Event name msk, with support for following properties:
batchSize: optional, maps toBatchSizearn: required, maps toEventSourceArnenabled: optional, maps toEnabledstartingPosition: optional (but required in AWS), maps toStartingPositionwith default set toTRIM_HORIZONtopic: required (technically optional in AWS, but it’s due to implied support for other stream sources), maps toTopics[0]
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 3
- Comments: 28 (16 by maintainers)
From my point of view, ARN and Topic should be mandatory. We could define some default values for the other two properties. What do you think @pgrzesik, @medikoo?
Thanks for sharing your finding @pedrocava 🙇 Looks like something added a bit later than
msksupport on Framework side was introduced as I remember it wasn’t avaialble at first. Would you like to open a separate issue that proposes to add this feature?@pgrzesik go ahead, for now, I am content with being part of the review of the pull request to learn a bit. If you need help with something I am open to help, just tell me.
I don’t - I believe we should stick to the current default. I think it’s application-specific and if current default fared well for 4 years now it sounds like the perfect choice 👍
@safv12 do you plan to implement support for
mskbased on the above implementation proposal? If not, I’d be happy to give it a try over the weekendGreat thanks @safv12 and @pgrzesik for valuable insight!
I’d say let’s follow with what we did in EFS, so stick to singular notation (unless we have a clear hint from AWS that it’s likely to change soon).
Summarizing above (and after going through AWS docs) I think in context of MSK we may have following options. (Please point if you feel I got something wrong, or something can be improved):
batchSize: optional, maps toBatchSizebisectBatchOnFunctionError: optional, maps toBisectBatchOnFunctionErroronFailureDestination: optional, maps toDestinationConfig.OnFailurearn: required, maps toEventSourceArnmaximumBatchingWindow: optional, maps toMaximumBatchingWindowInSecondsmaximumRecordAge: optional, maps toMaximumRecordAgeInSecondsmaximumRetryAttempts: optional, maps toMaximumRetryAttemptsparallelizationFactor: optional, maps toParallelizationFactorstartingPosition: optional (but required in AWS), maps toStartingPositionand we should map toLATESTas defaulttopic: required (technically optional in AWS, but it’s due to implied support for other stream sources), maps toTopics[0]Having that outlined, I wonder weather before bringing support for MSK, shouldn’t we refactor currently supported streaming events (as backed by
AWS::Lambda::EventSourceMapping).Current situation is that we have
streamevent that backs Kinesis and DynamoDB streams andsqsevent for SQS streams.Additionally in them I see following issues and in-consequences:
streamevent (dynamodb, kinesis):batchSizeto10while AWS default is1000value atbatchWindow(maps toMaximumBatchingWindowInSeconds), where it’s a supported value by AWSbatchWindowandmaximumRecordAgeInSecondsdoesn’t seem to follow same convention)sqsstream misses support forbisectBatchOnFunctionError,maximumRetryAttempts,maximumRecordAgeInSeconds,batchWindowanddestinationspropertiesImplementation proposal
1. Introduce
dynamodbandkinesisevents, and deprecatestreameventBy doing that, we can we fix listed above
streamevent issues, and follow better naming (as I proposed outlining the possible options for MSK). Separating both will also I think bring better design. It’ll be upfront clear to what stream is attached, and internally we no longer have to deduct the type from ARN (if type property was not provided)Both events could use one generic, secluded
AWS::Lambda::EventSourceMappingresource generator, which then we can use forsqs(and with that ensuring support for currently not supported properties) and thenmsk.We should also introduce a schema config to fully cover
dynamodb,kinesisand deprecatedstreamevent.Documentation should also be upgraded
2. Upgrade
sqsevent implementationSo it relies on generic
AWS::Lambda::EventSourceMappingresource generator (introduced with previous step). This will solve an issue of missing support for some properties.Additionally we should introduce config schema for
sqsevent, and update documentation so it covers new properties3. Introduce support for
mskeventRelying on generic
AWS::Lambda::EventSourceMappingresource generator, and with introduction of config schema and documentation for itI think to avoid making things to complex best would be to cover those 3 steps with 3 distinct following after each other PR’s.
What do you think?
@pgrzesik great thanks for sharing that.
I fully agree, seems as right to me
Which properties do you think should be mandatory for
mskevent type and which optional ?