Syncing data from Apache Kafka® topics to an Object Storage bucket without using the internet
Note
The VPC Private Endpoints feature in Yandex Virtual Private Cloud is at the Preview stage. To get access to the feature, contact your account manager.
You can synchronize data from Apache Kafka® topics to a Yandex Object Storage bucket without using the internet via a service connection in the user network hosting the Managed Service for Apache Kafka® cluster. To do this:
- Send data to the topic.
- Make sure the bucket is not accessible from the external network.
- Check if there is data in the bucket.
If you no longer need the resources you created, delete them.
Required paid resources
The support cost for this solution includes:
- Fee for an Object Storage bucket: Covers data storage and bucket operations (see Object Storage pricing).
- Managed Service for Apache Kafka® cluster fee: Covers the use of computating resources allocated to hosts and disk space (see Managed Service for Apache Kafka® pricing).
- Fee for using public IP addresses for cluster hosts (see Virtual Private Cloud pricing).
Getting started
-
Set up the infrastructure:
ManuallyTerraform-
Create a network named
my-private-network. Disable Create subnets when creating it. -
Create a subnet in any availability zone.
-
Create a service connection to Object Storage in
my-private-networkand write down its ID. -
Create a service account named
storage-pe-adminwith thestorage.adminrole. The Managed Service for Apache Kafka® cluster will use it to access the bucket. -
Create a static access key for the
storage-pe-adminservice account. -
Create a Yandex Object Storage bucket and configure its bucket policy:
- Result:
Allow. - Action:
All actions. - Resource:
<bucket_name>and<bucket_name>/*. - Condition: Select the
yc:private-endpoint-idkey from the list and specify the ID of the created service connection as its value.
- Result:
-
Create a Managed Service for Apache Kafka® cluster of any suitable configuration and the following settings:
- Broker hosts: One
- Access to cluster hosts: Public
- Network:
my-private-network
-
If using security groups in your cluster, make sure they are configured correctly and allow connecting to the cluster.
-
In the cluster, create a topic named
my-private-topic. -
In the cluster, create a user named
mkf-userwith theACCESS_ROLE_PRODUCERaccess permission for the new topic. -
In the cluster, create a connector with the following settings:
- Under Additional properties, specify the connector properties:
key.converter:org.apache.kafka.connect.storage.StringConvertervalue.converter:org.apache.kafka.connect.converters.ByteArrayConverterformat.output.fields.value.encoding:none
- Select the S3 Sink connector type.
- In the Topics field, specify
my-private-topic. - Under S3 connection, specify the following settings:
- Bucket: Bucket you created previously.
- Endpoint:
storage.pe.yandexcloud.net. - Access key ID, Secret access key: ID and secret key of the previously created static access key.
- Under Additional properties, specify the connector properties:
-
Create a VM with a public IP address in the created
my-private-networkto connect to the bucket.
-
If you do not have Terraform yet, install it.
-
Get the authentication credentials. You can add them to environment variables or specify them later in the provider configuration file.
-
Configure and initialize a provider. There is no need to create a provider configuration file manually, you can download it
. -
Place the configuration file in a separate working directory and specify the parameter values. If you did not add the authentication credentials to environment variables, specify them in the configuration file.
-
Download the kafka-objstorage-sync-private-network.tf
configuration file to the same working directory.This file describes:
- Network.
- Subnet.
- Service connection.
- Security group required for cluster connection.
- Service account for creating and accessing the bucket.
- Object Storage bucket.
- Managed Service for Apache Kafka® cluster.
- Apache Kafka® topic.
- Apache Kafka® user.
- Apache Kafka® connector.
- VM to read data from the bucket.
-
In the
kafka-objstorage-sync-private-network.tffile, specify the following:tf_account_name: Service account name, the same as the one in the provider settings.bucket_name: Bucket name consistent with the naming conventions.mkf_version: Apache Kafka® version.mkf_user_password: Apache Kafka® user password.vm_image_id: ID of the public image.vm_usernameandvm_ssh_key: Username and absolute path to the public key, for access to the VM.
-
Validate your Terraform configuration files using this command:
terraform validateTerraform will display any configuration errors detected in your files.
-
Create the required infrastructure:
-
Run this command to view the planned changes:
terraform planIf you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
-
If everything looks correct, apply the changes:
-
Run this command:
terraform apply -
Confirm updating the resources.
-
Wait for the operation to complete.
-
All the required resources will be created in the specified folder. You can check resource availability and their settings in the management console
. -
-
-
Make sure that Yandex Cloud DNS has the
*.storage.pe.yandexcloud.netrecord in the.service zone of the new network. -
Install kafkacat
to write data to the Apache Kafka® topic.sudo apt update && sudo apt install --yes kafkacatMake sure you can use it to connect to the previously created Managed Service for Apache Kafka® cluster over SSL.
Send data to the topic
-
Send test data to
my-private-topicusingkafkacat:for i in $(echo {1..50}) do echo "test message_"$i | kafkacat -P \ -b <broker_host_FQDN>:9091 \ -t my-private-topic \ -k key \ -X security.protocol=SASL_SSL \ -X sasl.username="<username_in_source_cluster>" \ -X sasl.password="<user_password_in_source_cluster>" \ -X ssl.ca.location=/usr/local/share/ca-certificates/Yandex/YandexInternalRootCA.crt -Z done -
Make sure data is replicated to the bucket. To do this, open the bucket upload statistics and check the Modify Requests chart for requests.
Make sure the bucket is not accessible from the external network
-
If you do not have the AWS CLI yet, install and configure it.
-
Run this command to get a list of bucket objects at a public network address:
aws s3 ls s3://<bucket_name> \ --endpoint-url=https://storage.yandexcloud.net \ --recursiveResult:
An error occurred (AccessDenied) when calling the ListObjectsV2 operation: Access Denied -
Run this command to get a list of bucket objects at a private network address:
aws s3 ls s3://<bucket_name> \ --endpoint-url=https://storage.pe.yandexcloud.net \ --recursiveResult:
Could not connect to the endpoint URL: "https://storage.pe.yandexcloud.net/<bucket_name>?list-type=2&prefix=&encoding-type=url"
Check if there is data in the bucket via the service connection
Connect to the previously created VM over SSH and do the following:
-
Run this command to get a list of bucket objects at a private network address:
aws s3 ls s3://<bucket_name> \ --endpoint-url=https://storage.pe.yandexcloud.net \ --recursiveResult:
2025-08-01 14:38:23 20 my-private-topic-1-0 2025-08-01 14:38:23 587 my-private-topic-1-1 2025-08-01 14:38:24 440 my-private-topic-1-29
This result means Apache Kafka® topic data has been successfully synchronized via the service connection.
Delete the resources you created
Some resources incur charges. To avoid paying for them, delete the resources you no longer need:
First, delete all objects from the bucket you created previously.
-
In the terminal window, go to the directory containing the infrastructure plan.
Warning
Make sure the directory has no Terraform manifests with the resources you want to keep. Terraform deletes all resources that were created using the manifests in the current directory.
-
Delete resources:
-
Run this command:
terraform destroy -
Confirm deleting the resources and wait for the operation to complete.
All the resources described in the Terraform manifests will be deleted.
-