Amazon MSK Serverless is a cluster sort for Amazon Managed Streaming for Apache Kafka (Amazon MSK) that’s the most simple approach to run Apache Kafka clusters with out having to handle compute and storage capability. With MSK Serverless, you possibly can run your purposes with out having to provision, configure, or optimize clusters, and also you pay for the information quantity you stream and retain. MSK Serverless absolutely manages partitions, together with monitoring and shifting them to even load throughout a cluster.
With as we speak’s launch, MSK Serverless now helps writes and reads from Kafka shoppers written in all programming languages. Directors can simplify and standardize entry management to Kafka sources utilizing AWS Id and Entry Administration (IAM). This help for IAM in Amazon MSK is predicated on SASL/OUATHBEARER, an open normal for authorization and authentication.
You may get began by utilizing IAM principals as identities in your Apache Kafka shoppers and outline id insurance policies to offer them exactly scoped entry permissions. For instance, you possibly can create an IAM consumer and a coverage that permits the consumer to write down to a particular Kafka subject however restricts entry to different sources with out worrying about managing Kafka ACLs. After you present the id insurance policies with the mandatory permissions, you possibly can configure consumer purposes to make use of the IAM authentication with minimal code modifications.
The code modifications permit your shoppers to make use of SASL/OAUTHBEARER, a Kafka supported token-based entry mechanism, to move the credentials required for IAM authentication. With OAUTHBEARER help, you possibly can construct shoppers that may work throughout each Amazon MSK and different Kafka environments. On this submit, we present how one can make these code modifications by utilizing the offered code libraries and examples.
With this launch, Amazon MSK gives new code libraries for the next programming languages within the AWS GitHub repo:
The next diagram reveals the conceptual course of circulate of utilizing SASL/OAUTHBEARER with IAM entry management for non-Java shoppers.
The workflow comprises the next steps:
- The consumer generates an OAUTHBEARER token with the assistance of the offered library. The token comprises a signed base64 encoded transformation of your IAM id credentials.
- The consumer sends this to Amazon MSK utilizing the bootstrap deal with together with its request to entry Apache Kafka sources.
- The MSK Serverless cluster decodes the OATHBEARER token, validates the credentials, and checks if the consumer is allowed to carry out the requested motion in line with the coverage connected to the IAM id.
- When the token expires, the consumer Kafka library robotically refreshes the token by making one other name to the required token supplier.
Create IAM identities and insurance policies
IAM entry management for non-Java shoppers is supported for MSK Serverless clusters with no extra price. Earlier than you begin, it’s worthwhile to configure the IAM identities and insurance policies that outline the consumer’s permissions to entry sources on the cluster. The next is an instance authorization coverage for a cluster named
MyTestCluster. To know the semantics of the motion and useful resource components, see Semantics of actions and sources.
Configure the consumer
You need to make code modifications to your software that permit the shoppers to make use of SASL/OAUTHBEARER to move the credentials required for IAM authentication. You additionally want to ensure the safety group related along with your MSK Serverless cluster has an inbound rule permitting the visitors from the consumer purposes within the related VPCs to the TCP port quantity 9098.
You need to use a Kafka consumer library that gives help for SASL with OAUTHBRARER authentication.
For this submit, we use the Python programming language. We additionally use https://github.com/dpkp/kafka-python as our Kafka consumer library.
Amazon MSK gives you with a brand new code library per every language that generates the OAUTHBEARER token.
- To get began working with the Amazon MSK IAM SASL signer for Python along with your Kafka consumer library, run the next command:
- Import the put in Amazon MSK IAM SASL signer library in your code:
- Subsequent, your software code must outline a token supplier that wraps the perform that generates new tokens:
oauthbearerin your Python Kafka consumer properties, and move the token supplier within the configuration object:
You at the moment are completed with all of the code modifications. For extra examples of producing auth tokens or for extra troubleshooting ideas, confer with the next GitHub repo.
MSK Serverless now helps writes and reads from Kafka shoppers written in all programming languages. You’ll be able to run your purposes with out having to configure and handle the infrastructure or optimize clusters, and also you pay for the information quantity you stream and retain. MSK Serverless absolutely manages partitions, together with monitoring, and ensures a fair stability of partition distribution throughout brokers within the cluster (auto-balancing).
For additional studying on Amazon MSK, go to the official product web page.
In regards to the creator
Ali Alemi is a Streaming Specialist Options Architect at AWS. Ali advises AWS clients with architectural greatest practices and helps them design real-time analytics knowledge methods which are dependable, safe, environment friendly, and cost-effective. He works backward from buyer’s use circumstances and designs knowledge options to resolve their enterprise issues. Previous to becoming a member of AWS, Ali supported a number of public sector clients and AWS consulting companions of their software modernization journey and migration to the Cloud.