AWS MSK
Amazon Managed Streaming for Apache Kafka (AWS MSK) is a fully managed Apache Kafka service provided by AWS. VeloDB Cloud supports importing data from AWS MSK in real time through Routine Load, providing the IAM authentication mechanism for AWS MSK. It supports CSV and JSON formats and commits consumed offsets with load transactions for exactly-once ingestion within the job. For details, see Routine Load.
Before you begin
This page describes the Routine Load SQL path with AWS MSK IAM authentication. For the console workflow and its deployment, network, and authentication requirements, see Import from AWS MSK. That workflow documents SASL/SCRAM and private connectivity separately from the IAM examples here.
IAM authentication for Routine Load was added in VeloDB Core 26.1.1. The 26.1 series is in Public Preview. Confirm your warehouse version before using it. Use a running warehouse, a SQL user with load privileges, and a pre-created target table t with columns a and b. Select the target database and use a distinct job name for each independent example.
Prerequisites
Before using Routine Load to import data from AWS MSK, confirm that the following conditions are met:
- The AWS MSK cluster has been created and IAM authentication is enabled.
- Appropriate AWS IAM permissions have been configured to allow access to the MSK cluster.
- The VeloDB Cloud warehouse can access the Bootstrap Servers of AWS MSK.
Authentication parameters
The following table lists the authentication-related parameters that need to be configured when importing data from AWS MSK:
| Parameter | Description | Example |
|---|---|---|
aws.region | AWS Region | "us-east-1" |
aws.access_key | AWS Access Key ID | - |
aws.secret_key | AWS Secret Access Key | - |
aws.role_arn | Role used for cross-account access credentials | "arn:aws:iam::123456789012:role/MyRole" |
aws.profile_name | Profile in the service execution environment, only when provisioned through an approved service configuration | - |
aws.credentials_provider | Standard credentials provider of the AWS SDK. Supports various provider types | "INSTANCE_PROFILE" |
aws.external_id | Used as the "calling context identifier" for AssumeRole | - |
property.security.protocol | Due to IAM authentication restrictions, this is fixed to SASL_SSL | "SASL_SSL" |
property.sasl.mechanism | Due to librdkafka library restrictions, this is fixed to OAUTHBEARER | "OAUTHBEARER" |
Available values for aws.credentials_provider
| Value | Description |
|---|---|
DEFAULT | Use the default provider chain |
ENV | Read credentials from the service execution environment (requires service-managed setup) |
INSTANCE_PROFILE | Use the service execution environment's EC2 instance profile (requires service-managed setup) |
Authentication configuration examples
The engine supports the following credential configurations. Explicit AK/SK can be supplied in the job. Instance profiles, environment variables, profiles, and the default chain refer to the warehouse service environment, not your client. Use those examples only after confirming the service-managed credential setup with VeloDB Cloud support. Do not modify warehouse hosts or their credential files.
| Authentication method | Applicable scenario |
|---|---|
| Use AK/SK directly | You already have a long-term valid Access Key/Secret Key |
| IAM Role (Assume Role) | Cross-account access, or when temporary credentials are preferred |
Specify the credential source through aws.credentials_provider | When you do not want to explicitly fill in AK/SK, for example with EC2 Instance Profile |
Method 1: use Access Key and Secret Key (AK/SK) directly
CREATE ROUTINE LOAD IAM_Test ON t
COLUMNS TERMINATED BY ",",
COLUMNS(a,b)
FROM KAFKA(
"kafka_broker_list" = "your_msk_broker_list",
"kafka_topic" = "your_kafka_topic",
"aws.region" = "us-west-1",
"aws.access_key" = "<your-ak>",
"aws.secret_key" = "<your-sk>",
"property.kafka_default_offsets" = "OFFSET_BEGINNING",
"property.security.protocol" = "SASL_SSL",
"property.sasl.mechanism" = "OAUTHBEARER"
);
Method 2: IAM Role (assume role) mode
When aws.role_arn is configured, the client uses STS to assume that role. For a role-based job with explicit source credentials, add aws.role_arn to the AK/SK example above and grant those credentials permission to assume the role. The examples below instead use a service-managed credential source.
Example 2.1: EC2 instance profile as the STS source credential
2.1: EC2 instance profile as the STS source credential
CREATE ROUTINE LOAD IAM_Test ON t
COLUMNS TERMINATED BY ",",
COLUMNS(a,b)
FROM KAFKA(
"kafka_broker_list" = "your_msk_broker_list",
"kafka_topic" = "your_kafka_topic",
"aws.region" = "us-west-1",
"aws.role_arn" = "arn:aws:iam::123456789012:role/demo-role",
"aws.credentials_provider" = "INSTANCE_PROFILE",
"property.kafka_default_offsets" = "OFFSET_BEGINNING",
"property.security.protocol" = "SASL_SSL",
"property.sasl.mechanism" = "OAUTHBEARER"
);
Example 2.2: read AK/SK from environment variables as the STS source credential
2.2: read AK/SK from environment variables as the STS source credential
CREATE ROUTINE LOAD IAM_Test ON t
COLUMNS TERMINATED BY ",",
COLUMNS(a,b)
FROM KAFKA(
"kafka_broker_list" = "your_msk_broker_list",
"kafka_topic" = "your_kafka_topic",
"aws.region" = "us-west-1",
"aws.role_arn" = "arn:aws:iam::123456789012:role/demo-role",
"aws.credentials_provider" = "ENV",
"property.kafka_default_offsets" = "OFFSET_BEGINNING",
"property.security.protocol" = "SASL_SSL",
"property.sasl.mechanism" = "OAUTHBEARER"
);
Example 2.3: use the default provider chain as the STS source credential
2.3: use the default provider chain as the STS source credential
CREATE ROUTINE LOAD IAM_Test ON t
COLUMNS TERMINATED BY ",",
COLUMNS(a,b)
FROM KAFKA(
"kafka_broker_list" = "your_msk_broker_list",
"kafka_topic" = "your_kafka_topic",
"aws.region" = "us-west-1",
"aws.role_arn" = "arn:aws:iam::123456789012:role/demo-role",
"aws.credentials_provider" = "DEFAULT",
"property.kafka_default_offsets" = "OFFSET_BEGINNING",
"property.security.protocol" = "SASL_SSL",
"property.sasl.mechanism" = "OAUTHBEARER"
);
Method 3: specify the credential source through aws.credentials_provider
This is suitable for scenarios where AK/SK is not explicitly provided, such as EC2 Instance Profile.
CREATE ROUTINE LOAD IAM_Test ON t
COLUMNS TERMINATED BY ",",
COLUMNS(a,b)
FROM KAFKA(
"kafka_broker_list" = "your_msk_broker_list",
"kafka_topic" = "your_kafka_topic",
"aws.region" = "us-west-1",
"aws.credentials_provider" = "INSTANCE_PROFILE",
"property.kafka_default_offsets" = "OFFSET_BEGINNING",
"property.security.protocol" = "SASL_SSL",
"property.sasl.mechanism" = "OAUTHBEARER"
);
Credential resolution rules
Credential selection follows these rules:
- If
aws.role_arnis set, the client assumes that role. The STS source credentials are selected from explicit AK/SK, thenaws.profile_name, thenaws.credentials_provider, then the default provider chain. - Without a role ARN, explicit AK/SK takes priority, followed by a named profile, then the configured provider.
- Without a role ARN, explicit keys, profile, or provider, credential initialization fails. To use the default chain directly, specify
aws.credentials_provider=DEFAULT.
For a public MSK broker endpoint containing -public., job validation requires both aws.access_key and aws.secret_key. If a role ARN is also supplied, these keys are the source credentials for STS.
Public network access troubleshooting
Prefer an approved private connection where available. The following checks apply only when you intentionally use MSK public access. For users accessing AWS MSK from a public network environment, if AWS authentication issues occur during data import, troubleshoot using the following steps:
Step 1: ensure that the MSK cluster has public access enabled
In the AWS MSK console, select the cluster you want to access, and check Networking settings under Properties by going to Edit public access. Make sure that the public access option is turned on.
Step 2: ensure that the subnet is public
The subnet associated with the cluster must be public. In the AWS VPC console, ensure that the route table entries of the subnet contain the 0.0.0.0/0 : igw-xxxx entry.
Step 3: use the correct bootstrap public endpoint
In the AWS MSK console, select the cluster you want to access, click View client information, and ensure that the kafka_broker_list property used when creating the Routine Load is filled in with the public endpoint rather than the private endpoint.
Step 4: ensure that the security group is configured with correct inbound and outbound rules
Check the inbound rules of the security group configured for MSK to see whether an appropriate source IP is configured for port 9198.
Note:
Port
9198applies to public IAM broker endpoints. Private and multi-VPC connections use their corresponding bootstrap endpoints and ports. Use the endpoint supplied by AWS for your connection method.
Reference documents
For more detailed information, refer to the related AWS documents:
- How to safely access Amazon Managed Streaming for Apache Kafka (Amazon MSK) clusters through the internet
- Access from within AWS but outside cluster's VPC
- Enable internet access for a VPC using an internet gateway
FAQ
Q1: Why must property.security.protocol and property.sasl.mechanism be fixed values?
Due to the AWS MSK IAM authentication mechanism and the limitations of the underlying librdkafka library, these two parameters must be fixed to SASL_SSL and OAUTHBEARER respectively. Otherwise, the IAM authentication handshake cannot be completed successfully.
Q2: When AK/SK and aws.role_arn are configured at the same time, which credential is used?
If aws.role_arn is present, the client assumes the role using AK/SK as the STS source credentials. Without a role ARN, AK/SK is used directly. See Credential Resolution Rules.
Q3: Authentication always fails when accessing MSK from the public network. How should this be troubleshot?
Follow the four steps in Public Network Access Troubleshooting and check each item: whether public access is enabled, whether the subnet is public, whether the Bootstrap endpoint uses the public endpoint, and whether the security group allows port 9198.
Q4: When running VeloDB Cloud on EC2, how can AK/SK configuration be avoided?
In a managed warehouse, an instance profile must be provisioned and authorized through the service. Confirm this setup with VeloDB Cloud support before setting aws.credentials_provider=INSTANCE_PROFILE. A role on your own EC2 client is not inherited by the warehouse. Refer to Method 3.
Q5: Does VeloDB Cloud guarantee no data loss or duplication when importing data from MSK through Routine Load?
Routine Load commits Kafka offsets with load transactions to provide exactly-once ingestion within a job. This does not recover messages expired by Kafka retention or rows filtered by your load settings. Monitor job state, lag, and rejected rows, and preserve source data long enough for recovery.