You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2020/08/11 00:58:36 UTC

[GitHub] [beam] TheNeuralBit commented on a change in pull request #12297: [BEAM-10137] Add KinesisIO for cross-language usage with python wrapper

TheNeuralBit commented on a change in pull request #12297:
URL: https://github.com/apache/beam/pull/12297#discussion_r468265791



##########
File path: sdks/python/apache_beam/io/kinesis.py
##########
@@ -0,0 +1,317 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+"""PTransforms for supporting Kinesis streaming in Python pipelines.
+
+  These transforms are currently supported by Beam Flink and Spark portable
+  runners.
+
+  **Setup**
+
+  Transforms provided in this module are cross-language transforms
+  implemented in the Beam Java SDK. During the pipeline construction, Python SDK
+  will connect to a Java expansion service to expand these transforms.
+  To facilitate this, a small amount of setup is needed before using these
+  transforms in a Beam Python pipeline.
+
+  There are several ways to setup cross-language Kinesis transforms.
+
+  * Option 1: use the default expansion service
+  * Option 2: specify a custom expansion service
+
+  See below for details regarding each of these options.
+
+  *Option 1: Use the default expansion service*
+
+  This is the recommended and easiest setup option for using Python Kinesis
+  transforms. This option is only available for Beam 2.24.0 and later.
+
+  This option requires following pre-requisites before running the Beam
+  pipeline.
+
+  * Install Java runtime in the computer from where the pipeline is constructed
+    and make sure that 'java' command is available.
+
+  In this option, Python SDK will either download (for released Beam version) or
+  build (when running from a Beam Git clone) a expansion service jar and use
+  that to expand transforms. Currently Kinesis transforms use the
+  'beam-sdks-java-io-kinesis-expansion-service' jar for this purpose.
+
+  *Option 2: specify a custom expansion service*
+
+  In this option, you startup your own expansion service and provide that as
+  a parameter when using the transforms provided in this module.
+
+  This option requires following pre-requisites before running the Beam
+  pipeline.
+
+  * Startup your own expansion service.
+  * Update your pipeline to provide the expansion service address when
+    initiating Kinesis transforms provided in this module.
+
+  Flink Users can use the built-in Expansion Service of the Flink Runner's
+  Job Server. If you start Flink's Job Server, the expansion service will be
+  started on port 8097. For a different address, please set the
+  expansion_service parameter.
+
+  **More information**
+
+  For more information regarding cross-language transforms see:
+  - https://beam.apache.org/roadmap/portability/
+
+  For more information specific to Flink runner see:
+  - https://beam.apache.org/documentation/runners/flink/
+"""
+
+# pytype: skip-file
+
+from __future__ import absolute_import
+
+import time
+from typing import List
+from typing import NamedTuple
+from typing import Optional
+from typing import Tuple
+
+from past.builtins import unicode
+
+from apache_beam import BeamJarExpansionService
+from apache_beam import ExternalTransform
+from apache_beam import NamedTupleBasedPayloadBuilder
+
+__all__ = [
+    'WriteToKinesis',
+    'ReadDataFromKinesis',
+    'InitialPositionInStream',
+    'WatermarkPolicy',
+]
+
+
+def default_io_expansion_service():
+  return BeamJarExpansionService(
+      'sdks:java:io:kinesis:expansion-service:shadowJar')
+
+
+WriteToKinesisSchema = NamedTuple(
+    'WriteToKinesisSchema',
+    [
+        ('stream_name', unicode),
+        ('aws_access_key', unicode),
+        ('aws_secret_key', unicode),
+        ('region', unicode),
+        ('partition_key', unicode),
+        ('service_endpoint', Optional[unicode]),
+        ('verify_certificate', Optional[bool]),
+        ('producer_properties', Optional[List[Tuple[unicode, unicode]]]),
+    ],
+)
+
+
+class WriteToKinesis(ExternalTransform):
+  """
+    An external PTransform which writes byte array stream to Amazon Kinesis.
+
+    Experimental; no backwards compatibility guarantees.
+  """
+  URN = 'beam:external:java:kinesis:write:v1'
+
+  def __init__(
+      self,
+      stream_name,
+      aws_access_key,
+      aws_secret_key,
+      region,
+      partition_key,
+      service_endpoint=None,
+      verify_certificate=None,
+      producer_properties=None,
+      expansion_service=None,
+  ):
+    """
+    Initializes a write operation to Kinesis.
+
+    :param stream_name: Kinesis stream name.
+    :param aws_access_key: Kinesis access key.
+    :param aws_secret_key: Kinesis access key secret.
+    :param region: AWS region. Example: 'us-east-1'.
+    :param service_endpoint: Kinesis service endpoint
+    :param verify_certificate: Enable or disable certificate verification.
+        Never set to False on production. True by default.
+    :param partition_key: Specify default partition key.
+    :param producer_properties: Specify the configuration properties for Kinesis
+        Producer Library (KPL) as List[KV[string, string]].
+        Example: [('CollectionMaxCount', '1000'), ('ConnectTimeout', '10000')]
+    :param expansion_service: The address (host:port) of the ExpansionService.
+    """
+    super(WriteToKinesis, self).__init__(
+        self.URN,
+        NamedTupleBasedPayloadBuilder(
+            WriteToKinesisSchema(
+                stream_name=stream_name,
+                aws_access_key=aws_access_key,
+                aws_secret_key=aws_secret_key,
+                region=region,
+                partition_key=partition_key,
+                service_endpoint=service_endpoint,
+                verify_certificate=verify_certificate,
+                producer_properties=producer_properties,
+            )),
+        expansion_service or default_io_expansion_service(),
+    )
+
+
+ReadFromKinesisSchema = NamedTuple(
+    'ReadFromKinesisSchema',
+    [
+        ('stream_name', unicode),
+        ('aws_access_key', unicode),
+        ('aws_secret_key', unicode),
+        ('region', unicode),
+        ('service_endpoint', Optional[unicode]),
+        ('verify_certificate', Optional[bool]),
+        ('max_num_records', Optional[int]),
+        ('max_read_time', Optional[int]),
+        ('initial_position_in_stream', Optional[unicode]),
+        ('initial_timestamp_in_stream', Optional[int]),
+        ('request_records_limit', Optional[int]),
+        ('up_to_date_threshold', Optional[int]),
+        ('max_capacity_per_shard', Optional[int]),
+        ('watermark_policy', Optional[unicode]),
+        ('watermark_idle_duration_threshold', Optional[int]),
+        ('rate_limit', Optional[int]),
+    ],
+)
+
+
+class InitialPositionInStream:
+  LATEST = 'LATEST'
+  TRIM_HORIZON = 'TRIM_HORIZON'
+  AT_TIMESTAMP = 'AT_TIMESTAMP'
+
+
+class WatermarkPolicy:
+  PROCESSING_TYPE = 'PROCESSING_TYPE'
+  ARRIVAL_TIME = 'ARRIVAL_TIME'
+
+
+class ReadDataFromKinesis(ExternalTransform):
+  """
+    An external PTransform which reads byte array stream from Amazon Kinesis.
+
+    Experimental; no backwards compatibility guarantees.
+  """
+  URN = 'beam:external:java:kinesis:read_data:v1'
+
+  def __init__(
+      self,
+      stream_name,
+      aws_access_key,
+      aws_secret_key,
+      region,
+      service_endpoint=None,
+      verify_certificate=None,
+      max_num_records=None,
+      max_read_time=None,
+      initial_position_in_stream=None,
+      initial_timestamp_in_stream=None,
+      request_records_limit=None,
+      up_to_date_threshold=None,
+      max_capacity_per_shard=None,
+      watermark_policy=None,
+      watermark_idle_duration_threshold=None,
+      rate_limit=None,
+      expansion_service=None,
+  ):
+    """
+    Initializes a read operation from Kinesis.
+
+    :param stream_name: Kinesis stream name.
+    :param aws_access_key: Kinesis access key.
+    :param aws_secret_key: Kinesis access key secret.
+    :param region: AWS region. Example: 'us-east-1'.
+    :param service_endpoint: Kinesis service endpoint
+    :param verify_certificate: Enable or disable certificate verification.
+        Never set to False on production. True by default.
+    :param max_num_records: Specifies to read at most a given number of records.
+        Must be greater than 0.
+    :param max_read_time: Specifies to read records during x seconds.
+    :param initial_timestamp_in_stream: Specify reading beginning at the given
+        timestamp in seconds. Must be in the past.
+    :param initial_position_in_stream: Specify reading from some initial
+        position in stream. Possible values:
+        LATEST - Start after the most recent data record (fetch new data).
+        TRIM_HORIZON - Start from the oldest available data record.
+        AT_TIMESTAMP - Start from the record at or after the specified
+        server-side timestamp.
+    :param request_records_limit: Specifies the maximum number of records in
+        GetRecordsResult returned by GetRecords call which is limited by 10K
+        records. If should be adjusted according to average size of data record
+        to prevent shard overloading. More at:
+        docs.aws.amazon.com/kinesis/latest/APIReference/API_GetRecords.html
+    :param up_to_date_threshold: Specifies how late in seconds records consumed
+        by this source can be to still be considered on time. Defaults to zero.
+    :param max_capacity_per_shard: Specifies the maximum number of messages per
+        one shard. Defaults to 10'000.
+    :param watermark_policy: Specifies the watermark policy. Possible values:
+        PROCESSING_TYPE, ARRIVAL_TIME. Defaults to ARRIVAL_TIME.
+    :param watermark_idle_duration_threshold: Use only when watermark policy is
+        ARRIVAL_TIME. Denotes the duration for which the watermark can be idle.
+        Passed in seconds.
+    :param rate_limit: Sets fixed rate policy for given seconds value. By
+        default there is no rate limit.
+    :param expansion_service: The address (host:port) of the ExpansionService.
+    """
+    if watermark_policy:
+      assert watermark_policy == WatermarkPolicy.ARRIVAL_TIME or\
+             watermark_policy == WatermarkPolicy.PROCESSING_TYPE
+
+    if initial_position_in_stream:
+      i = initial_position_in_stream
+      assert i == InitialPositionInStream.AT_TIMESTAMP or \
+             i == InitialPositionInStream.LATEST or \
+             i == InitialPositionInStream.TRIM_HORIZON
+
+    if request_records_limit:
+      assert 0 < request_records_limit <= 10000
+
+    if initial_timestamp_in_stream:
+      assert initial_timestamp_in_stream < time.time()

Review comment:
       This worries me a little bit since the system clock could be wrong. Maybe this should be a warning instead?

##########
File path: sdks/python/apache_beam/io/kinesis.py
##########
@@ -0,0 +1,317 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+"""PTransforms for supporting Kinesis streaming in Python pipelines.
+
+  These transforms are currently supported by Beam Flink and Spark portable
+  runners.
+
+  **Setup**
+
+  Transforms provided in this module are cross-language transforms
+  implemented in the Beam Java SDK. During the pipeline construction, Python SDK
+  will connect to a Java expansion service to expand these transforms.
+  To facilitate this, a small amount of setup is needed before using these
+  transforms in a Beam Python pipeline.
+
+  There are several ways to setup cross-language Kinesis transforms.
+
+  * Option 1: use the default expansion service
+  * Option 2: specify a custom expansion service
+
+  See below for details regarding each of these options.
+
+  *Option 1: Use the default expansion service*
+
+  This is the recommended and easiest setup option for using Python Kinesis
+  transforms. This option is only available for Beam 2.24.0 and later.
+
+  This option requires following pre-requisites before running the Beam
+  pipeline.
+
+  * Install Java runtime in the computer from where the pipeline is constructed
+    and make sure that 'java' command is available.
+
+  In this option, Python SDK will either download (for released Beam version) or
+  build (when running from a Beam Git clone) a expansion service jar and use
+  that to expand transforms. Currently Kinesis transforms use the
+  'beam-sdks-java-io-kinesis-expansion-service' jar for this purpose.
+
+  *Option 2: specify a custom expansion service*
+
+  In this option, you startup your own expansion service and provide that as
+  a parameter when using the transforms provided in this module.
+
+  This option requires following pre-requisites before running the Beam
+  pipeline.
+
+  * Startup your own expansion service.
+  * Update your pipeline to provide the expansion service address when
+    initiating Kinesis transforms provided in this module.
+
+  Flink Users can use the built-in Expansion Service of the Flink Runner's
+  Job Server. If you start Flink's Job Server, the expansion service will be
+  started on port 8097. For a different address, please set the
+  expansion_service parameter.
+
+  **More information**
+
+  For more information regarding cross-language transforms see:
+  - https://beam.apache.org/roadmap/portability/
+
+  For more information specific to Flink runner see:
+  - https://beam.apache.org/documentation/runners/flink/
+"""
+
+# pytype: skip-file
+
+from __future__ import absolute_import
+
+import time
+from typing import List
+from typing import NamedTuple
+from typing import Optional
+from typing import Tuple
+
+from past.builtins import unicode
+
+from apache_beam import BeamJarExpansionService
+from apache_beam import ExternalTransform
+from apache_beam import NamedTupleBasedPayloadBuilder
+
+__all__ = [
+    'WriteToKinesis',
+    'ReadDataFromKinesis',
+    'InitialPositionInStream',
+    'WatermarkPolicy',
+]
+
+
+def default_io_expansion_service():
+  return BeamJarExpansionService(
+      'sdks:java:io:kinesis:expansion-service:shadowJar')
+
+
+WriteToKinesisSchema = NamedTuple(
+    'WriteToKinesisSchema',
+    [
+        ('stream_name', unicode),
+        ('aws_access_key', unicode),
+        ('aws_secret_key', unicode),
+        ('region', unicode),
+        ('partition_key', unicode),
+        ('service_endpoint', Optional[unicode]),
+        ('verify_certificate', Optional[bool]),
+        ('producer_properties', Optional[List[Tuple[unicode, unicode]]]),

Review comment:
       FYI if https://github.com/apache/beam/pull/12481 is merged first this can (and will have to) change to `Mapping[unicode, unicode]`

##########
File path: sdks/java/io/kinesis/src/main/java/org/apache/beam/sdk/io/kinesis/KinesisIO.java
##########
@@ -295,14 +300,16 @@
   private static final int DEFAULT_NUM_RETRIES = 6;
 
   /** Returns a new {@link Read} transform for reading from Kinesis. */
-  public static Read read() {
-    return new AutoValue_KinesisIO_Read.Builder()
-        .setMaxNumRecords(Long.MAX_VALUE)
-        .setUpToDateThreshold(Duration.ZERO)
-        .setWatermarkPolicyFactory(WatermarkPolicyFactory.withArrivalTimePolicy())
-        .setRateLimitPolicyFactory(RateLimitPolicyFactory.withoutLimiter())
-        .setMaxCapacityPerShard(ShardReadersPool.DEFAULT_CAPACITY_PER_SHARD)
-        .build();
+  public static Read<KinesisRecord> read() {

Review comment:
       @lukecwik I suggested that Piotr make Read generic so that we can add `Read<byte[]> readData()` naturally, but now I'm wondering if this is a bad idea since it changes our Public API. Does this have a risk of breaking users?
   
   It looks like at least the way the method is used in our tests (`p.apply(KinesisIO.read())`) is unaffected.

##########
File path: sdks/python/apache_beam/io/external/xlang_kinesisio_it_test.py
##########
@@ -0,0 +1,304 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+"""
+Integration test for Python cross-language pipelines for Java KinesisIO.
+
+If you want to run the tests on localstack then run it just with pipeline
+options.
+
+To test it on a real AWS account you need to pass some additional params, e.g.:
+python setup.py nosetests \
+--tests=apache_beam.io.external.xlang_kinesisio_it_test \
+--test-pipeline-options="
+  --use_real_aws
+  --aws_kinesis_stream=<STREAM_NAME>
+  --aws_access_key=<AWS_ACCESS_KEY>
+  --aws_secret_key=<AWS_SECRET_KEY>
+  --aws_region=<AWS_REGION>
+  --runner=FlinkRunner"
+"""
+
+# pytype: skip-file
+
+from __future__ import absolute_import
+
+import argparse
+import logging
+import time
+import unittest
+import uuid
+
+import apache_beam as beam
+from apache_beam.io.kinesis import InitialPositionInStream
+from apache_beam.io.kinesis import ReadDataFromKinesis
+from apache_beam.io.kinesis import WriteToKinesis
+from apache_beam.options.pipeline_options import PipelineOptions
+from apache_beam.options.pipeline_options import StandardOptions
+from apache_beam.testing.test_pipeline import TestPipeline
+from apache_beam.testing.util import assert_that
+from apache_beam.testing.util import equal_to
+
+# pylint: disable=wrong-import-order, wrong-import-position, ungrouped-imports
+try:
+  import boto3
+except ImportError:
+  boto3 = None
+
+try:
+  from testcontainers.core.container import DockerContainer
+except ImportError:
+  DockerContainer = None
+# pylint: enable=wrong-import-order, wrong-import-position, ungrouped-imports
+
+LOCALSTACK_VERSION = '0.11.3'
+NUM_RECORDS = 10
+NOW = time.time()
+RECORD = b'record' + str(uuid.uuid4()).encode()
+
+
+@unittest.skipIf(DockerContainer is None, 'testcontainers is not installed.')
+@unittest.skipIf(boto3 is None, 'boto3 is not installed.')
+@unittest.skipIf(
+    TestPipeline().get_pipeline_options().view_as(StandardOptions).runner is
+    None,
+    'Do not run this test on precommit suites.',
+)
+class CrossLanguageKinesisIOTest(unittest.TestCase):
+  def test_kinesis_io(self):
+    self.run_kinesis_write()
+    # TODO: remove once BEAM-10664 is resolved
+    if not self.use_localstack:
+      self.run_kinesis_read_data()
+
+  def run_kinesis_write(self):
+    with TestPipeline(options=PipelineOptions(self.pipeline_args)) as p:
+      p.not_use_test_runner_api = True
+      _ = (
+          p
+          | 'Impulse' >> beam.Impulse()
+          | 'Generate' >> beam.FlatMap(lambda x: range(NUM_RECORDS))  # pylint: disable=range-builtin-not-iterating
+          | 'Map to bytes' >>
+          beam.Map(lambda x: RECORD + str(x).encode()).with_output_types(bytes)
+          | 'WriteToKinesis' >> WriteToKinesis(
+              stream_name=self.aws_kinesis_stream,
+              aws_access_key=self.aws_access_key,
+              aws_secret_key=self.aws_secret_key,
+              region=self.aws_region,
+              service_endpoint=self.aws_service_endpoint,
+              verify_certificate=(not self.use_localstack),
+              partition_key='1',
+          ))
+
+    # TODO: Remove once BEAM-10664 is resolved
+    if self.use_localstack:
+      records = self.kinesis_helper.read_from_stream(self.aws_kinesis_stream)
+      self.assertEqual(
+          sorted(records),
+          sorted([RECORD + str(i).encode() for i in range(NUM_RECORDS)]))

Review comment:
       I think it would be better if this had three tests:
   - test_kinesis_io_roundtrip (what you have now in the `self.use_localstack = False` case)
   - test_kinesis_write (what you have now in the `self.use_localstack = True` case)
   - test_kinesis_read (a new test that runs `run_kinesis_read_data` and injects the test data)
   
   test_kinesis_io_roundtrip and test_kinesis_read would be skipped when `self.use_localstack = True`
   If you'd rather not write up `test_kinesis_read` right now that could be left as a TODO for BEAM-10664. But I think we should at least separate out the two versions of test_kinesis_io into two distinct tests, so it's clear what is being tested.

##########
File path: sdks/python/apache_beam/io/kinesis.py
##########
@@ -0,0 +1,317 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+"""PTransforms for supporting Kinesis streaming in Python pipelines.
+
+  These transforms are currently supported by Beam Flink and Spark portable
+  runners.
+
+  **Setup**
+
+  Transforms provided in this module are cross-language transforms
+  implemented in the Beam Java SDK. During the pipeline construction, Python SDK
+  will connect to a Java expansion service to expand these transforms.
+  To facilitate this, a small amount of setup is needed before using these
+  transforms in a Beam Python pipeline.
+
+  There are several ways to setup cross-language Kinesis transforms.
+
+  * Option 1: use the default expansion service
+  * Option 2: specify a custom expansion service
+
+  See below for details regarding each of these options.
+
+  *Option 1: Use the default expansion service*
+
+  This is the recommended and easiest setup option for using Python Kinesis
+  transforms. This option is only available for Beam 2.24.0 and later.
+
+  This option requires following pre-requisites before running the Beam
+  pipeline.
+
+  * Install Java runtime in the computer from where the pipeline is constructed
+    and make sure that 'java' command is available.
+
+  In this option, Python SDK will either download (for released Beam version) or
+  build (when running from a Beam Git clone) a expansion service jar and use
+  that to expand transforms. Currently Kinesis transforms use the
+  'beam-sdks-java-io-kinesis-expansion-service' jar for this purpose.
+
+  *Option 2: specify a custom expansion service*
+
+  In this option, you startup your own expansion service and provide that as
+  a parameter when using the transforms provided in this module.
+
+  This option requires following pre-requisites before running the Beam
+  pipeline.
+
+  * Startup your own expansion service.
+  * Update your pipeline to provide the expansion service address when
+    initiating Kinesis transforms provided in this module.
+
+  Flink Users can use the built-in Expansion Service of the Flink Runner's
+  Job Server. If you start Flink's Job Server, the expansion service will be
+  started on port 8097. For a different address, please set the
+  expansion_service parameter.
+
+  **More information**
+
+  For more information regarding cross-language transforms see:
+  - https://beam.apache.org/roadmap/portability/
+
+  For more information specific to Flink runner see:
+  - https://beam.apache.org/documentation/runners/flink/
+"""
+
+# pytype: skip-file
+
+from __future__ import absolute_import
+
+import time
+from typing import List
+from typing import NamedTuple
+from typing import Optional
+from typing import Tuple
+
+from past.builtins import unicode
+
+from apache_beam import BeamJarExpansionService
+from apache_beam import ExternalTransform
+from apache_beam import NamedTupleBasedPayloadBuilder
+
+__all__ = [
+    'WriteToKinesis',
+    'ReadDataFromKinesis',
+    'InitialPositionInStream',
+    'WatermarkPolicy',
+]
+
+
+def default_io_expansion_service():
+  return BeamJarExpansionService(
+      'sdks:java:io:kinesis:expansion-service:shadowJar')
+
+
+WriteToKinesisSchema = NamedTuple(
+    'WriteToKinesisSchema',
+    [
+        ('stream_name', unicode),
+        ('aws_access_key', unicode),
+        ('aws_secret_key', unicode),
+        ('region', unicode),
+        ('partition_key', unicode),
+        ('service_endpoint', Optional[unicode]),
+        ('verify_certificate', Optional[bool]),
+        ('producer_properties', Optional[List[Tuple[unicode, unicode]]]),
+    ],
+)
+
+
+class WriteToKinesis(ExternalTransform):
+  """
+    An external PTransform which writes byte array stream to Amazon Kinesis.
+
+    Experimental; no backwards compatibility guarantees.
+  """
+  URN = 'beam:external:java:kinesis:write:v1'
+
+  def __init__(
+      self,
+      stream_name,
+      aws_access_key,
+      aws_secret_key,
+      region,
+      partition_key,
+      service_endpoint=None,
+      verify_certificate=None,
+      producer_properties=None,
+      expansion_service=None,
+  ):
+    """
+    Initializes a write operation to Kinesis.
+
+    :param stream_name: Kinesis stream name.
+    :param aws_access_key: Kinesis access key.
+    :param aws_secret_key: Kinesis access key secret.
+    :param region: AWS region. Example: 'us-east-1'.
+    :param service_endpoint: Kinesis service endpoint
+    :param verify_certificate: Enable or disable certificate verification.
+        Never set to False on production. True by default.
+    :param partition_key: Specify default partition key.
+    :param producer_properties: Specify the configuration properties for Kinesis
+        Producer Library (KPL) as List[KV[string, string]].
+        Example: [('CollectionMaxCount', '1000'), ('ConnectTimeout', '10000')]

Review comment:
       Can you make this argument accept a mapping and convert it to `List[Tuple[..]]` as is done in KafkaIO?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org