Skip to content

Commit 5077d8a

Browse files
authored
feat(lambda-event-sources): starting position timestamp for kafka (#31439)
### Issue # (if applicable) Closes #31808 ### Reason for this change It was impossible to start consuming a Kafka topic from a specific point in time. ### Description of changes The user may now set `startingPositionTimestamp` to `ManagedKafkaEventSource` and `SelfManagedKafkaEventSource` to start consuming a Kafka topic from a specific point in time. [Lambda and CloudFormation have supported the functionality for a while](https://aws.amazon.com/about-aws/whats-new/2023/06/aws-lambda-starting-timestamp-kafka-sources/), and other stream event sources like `KinesisEventSource` already had a CDK implementation for it. So, technically, this change is doing nothing new; it is only repeating the pattern that has already been proven to work on other sources. ### Description of how you validated changes The change is tested by adding similar unit tests to other event sources supporting this functionality. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 7c1870f commit 5077d8a

File tree

11 files changed

+445
-13
lines changed

11 files changed

+445
-13
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-lambda-event-sources/test/integ.kafka-selfmanaged.js.snapshot/LambdaEventSourceKafkaSelfManagedTestDefaultTestDeployAssertAF78BD0F.assets.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-lambda-event-sources/test/integ.kafka-selfmanaged.js.snapshot/cdk.out

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-lambda-event-sources/test/integ.kafka-selfmanaged.js.snapshot/integ.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-lambda-event-sources/test/integ.kafka-selfmanaged.js.snapshot/lambda-event-source-kafka-self-managed.assets.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-lambda-event-sources/test/integ.kafka-selfmanaged.js.snapshot/lambda-event-source-kafka-self-managed.template.json

+122
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,128 @@
454454
"my-test-topic3"
455455
]
456456
}
457+
},
458+
"F4ServiceRole100FF901": {
459+
"Type": "AWS::IAM::Role",
460+
"Properties": {
461+
"AssumeRolePolicyDocument": {
462+
"Statement": [
463+
{
464+
"Action": "sts:AssumeRole",
465+
"Effect": "Allow",
466+
"Principal": {
467+
"Service": "lambda.amazonaws.com"
468+
}
469+
}
470+
],
471+
"Version": "2012-10-17"
472+
},
473+
"ManagedPolicyArns": [
474+
{
475+
"Fn::Join": [
476+
"",
477+
[
478+
"arn:",
479+
{
480+
"Ref": "AWS::Partition"
481+
},
482+
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
483+
]
484+
]
485+
}
486+
]
487+
}
488+
},
489+
"F4ServiceRoleDefaultPolicy1E98EC08": {
490+
"Type": "AWS::IAM::Policy",
491+
"Properties": {
492+
"PolicyDocument": {
493+
"Statement": [
494+
{
495+
"Action": [
496+
"secretsmanager:DescribeSecret",
497+
"secretsmanager:GetSecretValue"
498+
],
499+
"Effect": "Allow",
500+
"Resource": [
501+
{
502+
"Ref": "S509448A1"
503+
},
504+
{
505+
"Ref": "SC0855C491"
506+
}
507+
]
508+
}
509+
],
510+
"Version": "2012-10-17"
511+
},
512+
"PolicyName": "F4ServiceRoleDefaultPolicy1E98EC08",
513+
"Roles": [
514+
{
515+
"Ref": "F4ServiceRole100FF901"
516+
}
517+
]
518+
}
519+
},
520+
"F4F1740A13": {
521+
"Type": "AWS::Lambda::Function",
522+
"Properties": {
523+
"Code": {
524+
"ZipFile": "exports.handler = async function handler(event) {\n console.log('event:', JSON.stringify(event, undefined, 2));\n return { event };\n}"
525+
},
526+
"Handler": "index.handler",
527+
"Role": {
528+
"Fn::GetAtt": [
529+
"F4ServiceRole100FF901",
530+
"Arn"
531+
]
532+
},
533+
"Runtime": "nodejs18.x"
534+
},
535+
"DependsOn": [
536+
"F4ServiceRoleDefaultPolicy1E98EC08",
537+
"F4ServiceRole100FF901"
538+
]
539+
},
540+
"F4KafkaEventSource838c4d5ff3c99c1a617120adfca83e5bmytesttopic4F6589D62": {
541+
"Type": "AWS::Lambda::EventSourceMapping",
542+
"Properties": {
543+
"BatchSize": 100,
544+
"FunctionName": {
545+
"Ref": "F4F1740A13"
546+
},
547+
"SelfManagedEventSource": {
548+
"Endpoints": {
549+
"KafkaBootstrapServers": [
550+
"my-self-hosted-kafka-broker-1:9092",
551+
"my-self-hosted-kafka-broker-2:9092",
552+
"my-self-hosted-kafka-broker-3:9092"
553+
]
554+
}
555+
},
556+
"SelfManagedKafkaEventSourceConfig": {
557+
"ConsumerGroupId": "myTestConsumerGroup4"
558+
},
559+
"SourceAccessConfigurations": [
560+
{
561+
"Type": "CLIENT_CERTIFICATE_TLS_AUTH",
562+
"URI": {
563+
"Ref": "SC0855C491"
564+
}
565+
},
566+
{
567+
"Type": "SERVER_ROOT_CA_CERTIFICATE",
568+
"URI": {
569+
"Ref": "S509448A1"
570+
}
571+
}
572+
],
573+
"StartingPosition": "AT_TIMESTAMP",
574+
"StartingPositionTimestamp": 1730270400,
575+
"Topics": [
576+
"my-test-topic4"
577+
]
578+
}
457579
}
458580
},
459581
"Parameters": {

packages/@aws-cdk-testing/framework-integ/test/aws-lambda-event-sources/test/integ.kafka-selfmanaged.js.snapshot/manifest.json

+26-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)