Prerequisites
To use the adapter, you need:- An Amazon MSK cluster that uses Simple Authentication and Security Layer (SASL) with Salted Challenge Response Authentication Mechanism (SCRAM)-512. The cluster, the topics, and a failure topic must already exist.
- A SCRAM secret in AWS Secrets Manager whose name starts with
AmazonMSK_, encrypted with a customer managed AWS Key Management Service (KMS) key. MSK doesn’t accept the AWS managed key. - Maia API credentials (a client ID and client secret). If you’re not familiar with API credentials in Maia, read Authenticate to the Maia API.
- An AWS account with permission to create Lambda functions and event source mappings, DynamoDB tables, Amazon Elastic Container Registry (ECR) repositories, Identity and Access Management (IAM) roles and inline policies, CloudWatch log groups and alarms, and Amazon Simple Notification Service (SNS) topics.
- Terraform 1.9 or later and AWS provider 6.28.0 or later. The module needs this provider version because it’s the first to support a Kafka failure destination and a poller group.
- A published pipeline to trigger. The adapter can only run published pipelines.
DescribeConfigson the cluster.DescribeandReadon each topic and on each consumer group. The consumer group ID is<function-name>-<topic>, andname_prefixsets the function name.- Write access on the failure topic, because Lambda’s event source mapping, not the adapter, writes failed records there, as the SCRAM user. A Kafka producer needs at least
WriteandDescribe.
Adapter version
Use adapter version 1.2.0 or later. To route a topic that carries its own payload, as described in Route a topic that carries its own payload, use version 1.3.0 or later.Copy the adapter image to your own ECR repository
Lambda only runs images from a private ECR repository in the same region as the function. Copy the adapter image to your own repository as described in Copy the adapter image to your own ECR repository, and note the image URI. Copy version 1.2.0 or later (1.3.0 or later for topic routes).Store your API credentials
The adapter authenticates to Maia using OAuth client credentials. Create a secret in AWS Secrets Manager that contains your client ID and client secret, as described in Store your API credentials. The adapter only runs published pipelines. If the credentials have an account role other than Super Admin, they need access to the project (Viewer or higher) and at least the Operator role on the environment. Operator is the lowest environment role that can run published pipelines—Viewer can’t. Read project roles and environment roles. The secret must exist before you deploy. Terraform doesn’t create it. Pass its name to the module assecret_name.
Deploy the adapter with Terraform
The adapter has its own Terraform module,modules/aws/lambda/msk-maia-foundation-adapter, in the deployment library. Deploy it as its own Terraform configuration. Neither runner/aws/ecs nor runner/aws/eks calls it. The deployment library has no tags or releases, so pin ref to the commit you want to use, for example cd3deb7xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx:
terraform init, terraform plan, and terraform apply.
The module creates:
- The Lambda function and its execution role.
- One event source mapping for each topic, all in one poller group.
- An optional DynamoDB project mapping table.
- A CloudWatch log group.
- An optional SNS topic and CloudWatch alarms.
Variables
The module has more optional variables, including the function’s memory, timeout, log level, and log retention. For the full list, read the module’s
variables.tf file.
Add project mappings
The adapter uses a DynamoDB table to look up the project ID for the project name and environment in each record. Add one item to the table for each project and environment combination you want to trigger pipelines in, as described in Add project mappings. The table has the same schema as the SQS adapter’s table, so both adapters can share one table. To share the SQS adapter’s table, setcreate_mapping_table to false, and pass the name and ARN of the table as existing_mapping_table_name and existing_mapping_table_arn. Use the actual name and ARN from your SQS deployment, which might not be the default. The SQS deployment owns the table, so destroying that deployment also removes the MSK mappings.
Send a record to trigger a pipeline
Produce a record to one of the topics. The record value must be a UTF-8 JSON message in the same format as the SQS adapter uses. The adapter ignores the record key and headers. Each message contains the following fields:project: The name of the project that contains the pipeline.environment: The name of the environment to run the pipeline in.job: The folder path and name of the pipeline, without a file extension, for examplefolder/PipelineName. Don’t add.orch.yaml.variables: The scalar variables to pass to the pipeline. Each value can be up to 10,000 characters.gridVariables: The grid variables to pass to the pipeline.
Route a topic that carries its own payload
If a producer sends its own payload instead of the adapter’s message format, route the topic to a pipeline withtopic_routes. This setting requires adapter version 1.3.0 or later. Each route names the project, environment, and pipeline that the topic’s records trigger, and the scalar variable that receives the record:
orders. The adapter doesn’t parse the record. It passes the value to the pipeline that the route names, and the pipeline does the rest.
The adapter base64-encodes the record value into the payload_variable and passes these scalar variables to the pipeline:
In the pipeline, decode the payload with
BASE64_DECODE_STRING and parse it yourself. Base64 encoding keeps a backslash or quotation mark in the payload from breaking the pipeline’s SQL.
Keep these points in mind:
- Base64 encoding increases the value size by a third. With the 10,000-character limit for scalar variables, the payload can be about 7,500 bytes.
- The event source mapping can deliver a record more than once. If the pipeline inserts rows, you need to deduplicate them by topic, partition, and offset.
- A topic that isn’t in
topic_routesmust carry the adapter’s message format. - A route’s topic must be in
topics, andpayload_variablecan’t bekafkaTopic,kafkaPartition, orkafkaOffset.terraform planrejects both. - Terraform doesn’t check the project, environment, or pipeline in a route. If a route names a pipeline that doesn’t exist, every record goes to the failure topic. A route the function can’t use, such as a pipeline path that contains
.., stops the function starting, so every record fails until you fix the route.
Handle failed records
Lambda’s event source mapping retries a record that fails, including one that the Maia API rejects,maximum_retry_attempts times. It then writes the record, with its content, to the failure topic.
The record on the failure topic is a JSON message. Its payload field holds the original records with each value base64-encoded, and requestContext.condition is RetryAttemptsExhausted. To replay a record, decode the value, fix the message, and produce it to the topic again.
The first failure in a partition holds back the rest of that partition until the record succeeds or goes to the failure topic, because a retry redelivers everything from the lowest failed offset. With batch_size set to 1, a bad record only holds back itself.
The following diagram shows what happens to a record that fails at offset 42.
When create_alarms is true, each topic gets a CloudWatch alarm that fires when a record reaches the failure topic or can’t be written there. The Lambda errors alarm doesn’t see these failures, because the function reports them in its response and doesn’t raise an error.
For a topic in topic_routes, the alarm only covers failures to start a run. If a run starts and then fails inside the pipeline, the adapter doesn’t retry it, the record doesn’t reach the failure topic, and no alarm fires. Watch those runs in Pipeline run history.
Scaling and cost
- Pollers: Each topic’s mapping has its own minimum and maximum pollers, so your baseline is the number of topics multiplied by
minimum_pollers. The mappings share one poller group, which packs those pollers into shared event poller units of 10 pollers each. A poller group can hold up to 100 topics, and the maximum pollers across the group can’t add up to more than 2,000. - Concurrency: The adapter runs at most one invocation per partition, so the partition counts of your topics set the ceiling for a burst. If you set
reserved_concurrency, it’s one cap shared by every topic, and it must be at least the total partition count. - Cost: AWS bills provisioned mode in event poller units for as long as the mappings exist. All the module’s mappings share one poller group, so they share units instead of each topic being billed separately.
- Renaming the function: Changing
name_prefixchanges the function name, which recreates the mappings with new consumer groups. They start fromstarting_position, not from the old groups’ offsets.