Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(lambda-event-sources): Support MSK and self hosted Kafka #12099

Closed
1 of 2 tasks
bracki opened this issue Dec 16, 2020 · 4 comments · Fixed by #12507
Closed
1 of 2 tasks

(lambda-event-sources): Support MSK and self hosted Kafka #12099

bracki opened this issue Dec 16, 2020 · 4 comments · Fixed by #12507
Assignees
Labels
@aws-cdk/aws-lambda-event-sources effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. p2

Comments

@bracki
Copy link
Contributor

bracki commented Dec 16, 2020

Add a KafkaEventSource that implements StreamEventSource and allows configuring either MSK or a self hosted Kafka cluster as described here and here.

Use Case

I want to setup MSK/Kafka as event source for Lambda without doing it with the lower level CfnEventSourceMapping.

Proposed Solution

Add a class KafkaEventSource that implements StreamEventSource.

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

@bracki bracki added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Dec 16, 2020
@bracki
Copy link
Contributor Author

bracki commented Dec 16, 2020

It could look like this:

export type KafkaEventSourceProps = StreamEventSourceProps

class KafkaEventSource extends StreamEventSource {
    constructor(readonly clusterArn: string,
                readonly kafkaTopic: string,
                readonly secretArn: string,
                readonly kmsKeyArn: string,
                props: KafkaEventSourceProps) {
        super(props);
    }

    public bind(target: lambda.IFunction) {
        const eventSourceMapping = target.addEventSourceMapping(
            `KafkaEventSource:${this.kafkaTopic}`,
            this.enrichMappingOptions({
                eventSourceArn: this.clusterArn,
                kafkaTopic: this.kafkaTopic,
                startingPosition: this.props.startingPosition
            })
        );

        target.addToRolePolicy(new iam.PolicyStatement(
            {
                actions: ['secretsmanager:GetSecretValue'],
                resources: [this.secretArn],
            })
        );
        target.addToRolePolicy(new iam.PolicyStatement(
            {
                actions: ['kms:Decrypt'],
                resources: [this.kmsKeyArn],
            })
        );
        target.addToRolePolicy(new iam.PolicyStatement(
            {
                actions: ['kafka:DescribeCluster', 'kafka:GetBootstrapBrokers', 'kafka:ListScramSecrets'],
                resources: [this.clusterArn]
            }
        ));
        target.role?.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('service-role/AWSLambdaMSKExecutionRole'));

        const cfnEventSourceMapping = eventSourceMapping.node.defaultChild as lambda.CfnEventSourceMapping;
        cfnEventSourceMapping.sourceAccessConfigurations = [{type: 'SASL_SCRAM_512_AUTH', uri: this.secretArn}];
    }
}

@SomayaB SomayaB changed the title (lambda-event-source): Support MSK and self hosted Kafka (lambda-event-sources): Support MSK and self hosted Kafka Dec 17, 2020
@bracki
Copy link
Contributor Author

bracki commented Dec 18, 2020

For a self hosted Kafka cluster this is needed as well: aws-cloudformation/cloudformation-coverage-roadmap#723 Or it could be retrofitted with AwsCustomResource.

Maybe we have a quick chat @nija-at?

@nija-at
Copy link
Contributor

nija-at commented Dec 18, 2020

If it's supported by the AWS SDK for Javascript, you could absolutely use a custom resource until support for it is available via CloudFormation.

@bracki - I'm out on vacation for the next 2 weeks but feel free to take a stab at a PR here. You can DM me (once I'm back) on the public CDK Slack channel (details at https://cdk.dev/)

@nija-at nija-at added effort/small Small work item – less than a day of effort needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. p2 and removed needs-triage This issue or PR still needs to be triaged. labels Jan 7, 2021
@mergify mergify bot closed this as completed in #12507 Mar 16, 2021
mergify bot pushed a commit that referenced this issue Mar 16, 2021
…12507)

Fixes #12099 
----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

hollanddd pushed a commit to hollanddd/aws-cdk that referenced this issue Mar 17, 2021
…ws#12507)

Fixes aws#12099 
----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
hollanddd pushed a commit to hollanddd/aws-cdk that referenced this issue Mar 18, 2021
…ws#12507)

Fixes aws#12099 
----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
hollanddd pushed a commit to hollanddd/aws-cdk that referenced this issue Aug 26, 2021
…ws#12507)

Fixes aws#12099 
----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda-event-sources effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants