Amazon Kinesis Data Analytics is the easiest way to transform and analyze streaming data in real time using Apache Flink. Customers are already using Kinesis Data Analytics to perform real-time analytics on fast-moving data generated from data sources like IoT sensors, change data capture (CDC) events, gaming, social media, and many others. Apache Flink is a popular open-source framework and distributed processing engine for stateful computations over unbounded and bounded data streams.
Although building Apache Flink applications is typically the responsibility of a data engineering team, automating the deployment and provisioning infrastructure as code (IaC) is usually owned by the platform (or DevOps) team.
The following are typical responsibilities of the data engineering role:
The following are typical responsibilities of the platform role:
In this post, we show how you can automate deployment and version updates for Kinesis Data Analytics applications and allow both Platform and engineering teams to effectively collaborate and co-own the final solution using AWS CodePipeline with the AWS Cloud Development Kit (AWS CDK).
To demonstrate the automated deployment and version update of a Kinesis Data Analytics application, we use the following example real-time data analytics architecture for this post.
The workflow includes the following steps:
You can refer to the following generic architecture to adapt this example to your preferred CI/CD tool (for example, Jenkins). The overall deployment process is divided into three high-level parts:
The following diagram illustrates this workflow.
In this post, we implement the generic architecture using CodePipeline. The following diagram illustrates our updated architecture.
The final solution includes the following steps:
The following GitHub repository contains the AWS CDK code to create all the necessary resources for the data pipeline. This removes opportunities for manual error, increases efficiency, and ensures consistent configurations over time. To deploy the resources, complete the following steps:
cdk bootstrap to initialize the AWS CDK environment in your AWS account. Replace your AWS account ID and Region before running the following command.To learn more about the bootstrapping process, refer to Bootstrapping.
The data engineering and platform teams begin work in their respective code repositories, as illustrated in the following figure.
In this post, we use two folders instead of two GitHub repositories, which you can find under the root folder of the cloned repository:
Application development teams usually stores the application source code in git repositories. For the demonstration purpose, we will use source code as zip file downloaded from Github instead of connecting CodePipeline to the Github repository. You may want to directly connect source repository with CodePipeline. To learn more about how to connect, refer to Create a connection to GitHub.
The following figure illustrates the next step in the workflow.
In this step, you deploy the first pipeline to build the Java source code from kinesis-analytics-application. Complete the following steps to deploy ApplicationPipelineStack:
infrastructure-cdk.npm install to download all dependencies. cdk deploy ApplicationPipelineStack to deploy the application pipeline.This process should take about 5 minutes to complete and deploys the following resources to your AWS account, highlighted in green in the preceding diagram:
After the cdk deploy command is successful, complete the following steps to automatically run the pipeline:
ApplicationPipelineStack.
ArtifactBucketLink.
You’re redirected to the S3 artifact bucket.
The first pipeline run (shown as Auto Build in the following diagram) starts automatically and takes about 5 minutes to reach the manual approval stage. The pipeline automatically downloads the source code from the artifact bucket, builds the Java project kinesis-analytics-application using Maven, and publishes the output binary JAR file back to the artifact bucket under the directory jars.
Complete the following steps to view the application pipeline run:
ApplicationPipelineStack.ApplicationCodePipelineLink.
You’re redirected to the pipeline details page. You can see a detailed view of the pipeline, including the state of each action in each stage and the state of the transitions.
Do not approve the build for the manual approval stage yet; this is done later.
The application pipeline run publishes a JAR file named kinesis-analytics-application-final.jar to the artifact bucket. Next, we deploy the Kinesis Data Analytics architecture. Complete the following steps to deploy the example flow:
infrastructure-cdk.cdk deploy InfraPipelineStack to deploy the infrastructure pipeline.This process should take about 5 minutes to complete and deploys a pipeline containing stages for CodeBuild and CodeDeploy to your AWS account, as highlighted in green in the following diagram.
When the cdk deploy is complete, the infrastructure pipeline run starts automatically (shown as Auto Build 1 in the following diagram) and takes about 10 minutes to download the source code from the artifact bucket, build the AWS CDK project infrastructure-stack, and deploy ApplicationStack automatically to your AWS account. When the infrastructure pipeline run is complete, the following resources are deployed to your account (shown in green in following diagram):
app-ApplicationStackkinesis-analytics-application-final.jar
Complete the following steps to view the application pipeline run:
InfraPipelineStack.
InfraCodePipelineLink.
You’re redirected to the pipeline details page. You can see a detailed view of the pipeline, including the state of each action in each stage and the state of the transitions.
Now your account has everything in place for the data engineering team to work independently and roll out new versions of the Kinesis Data Analytics application. You can approve the respective application build from the application pipeline to deploy new versions of the application. The following diagram illustrates the full workflow.
The build process starts automatically when it detects changes in the source code. You can test a version update by re-uploading the source code .zip file to the S3 artifact bucket. In a real-world use case, you update the main branch either via a pull request or by merging your changes, and this action triggers a new pipeline run automatically.
To view the current version of the Kinesis Data Analytics application, complete the following steps:
InfraPipelineStack.KDAApplicationLink.
You’re redirected to the Kinesis Data Analytics application details page. You can find the current application version by looking at Version ID.
Complete the following steps to approve the deployment (or version update) of the Kinesis Data Analytics application:
ApplicationPipelineStack.ApplicationCodePipelineLink.

You should see the application version as defined in Version ID increased by one, as shown in the following screenshot.
Deploying a new version of the Kinesis Data Analytics application will cause a downtime of around 5 minutes because the Lambda function responsible for the version update makes the API call UpdateApplication, which restarts the application after updating the version. However, the application resumes stream processing where it left off after the restart.
Complete the following steps to delete your resources and stop incurring costs:
InfraPipelineStack and choose Delete.app-ApplicationStack and choose Delete.ApplicationPipelineStack and choose Delete.javaappCodePipeline and choose Empty.infrapipelinestack-pipelineartifactsbucket.This post demonstrated how to automate deployment and version updates for your Kinesis Data Analytics applications using CodePipeline and AWS CDK.
For more information, see Continuous integration and delivery (CI/CD) using CDK Pipelines and CodePipeline tutorials.
Anand Shah is a Big Data Prototyping Solutions Architect at AWS. He works with AWS customers and their engineering teams to build prototypes using AWS analytics services and purpose-built databases. Anand helps customers solve the most challenging problems using the art of the possible technology. He enjoys beaches in his leisure time.