{"id":14442,"library":"aws-cdk-aws-kinesisanalytics-flink-alpha","title":"AWS CDK Kinesis Analytics Flink Alpha","description":"This is an experimental (alpha) AWS CDK Construct Library for defining Kinesis Data Analytics Flink applications. It simplifies the setup of Flink applications, including code location, runtime versions, and IAM roles. As part of the AWS CDK, it receives frequent updates, typically aligning with the CDK's bi-weekly release cycle. The current version is 2.250.0a0.","status":"active","version":"2.250.0a0","language":"en","source_language":"en","source_url":"https://github.com/aws/aws-cdk.git","tags":["aws","cdk","kinesis","flink","analytics","serverless","streaming","alpha"],"install":[{"cmd":"pip install aws-cdk-aws-kinesisanalytics-flink-alpha aws-cdk-lib constructs","lang":"bash","label":"Install with core CDK dependencies"}],"dependencies":[{"reason":"Core AWS CDK library, required for all CDK constructs.","package":"aws-cdk-lib","optional":false},{"reason":"Base library for CDK constructs.","package":"constructs","optional":false}],"imports":[{"note":"CDK V2 generally recommends importing constructs as namespaces (e.g., `aws_s3 as s3`) rather than direct class imports for better organization and to avoid name collisions, especially in generated alpha modules.","wrong":"from aws_cdk.aws_kinesisanalytics_flink_alpha import Application","symbol":"Application","correct":"from aws_cdk import aws_kinesisanalytics_flink_alpha as flink\n# then flink.Application(...)"},{"note":"FlinkRuntime is an enum class within the flink namespace for specifying Flink versions.","symbol":"FlinkRuntime","correct":"from aws_cdk import aws_kinesisanalytics_flink_alpha as flink\n# then flink.FlinkRuntime.FLINK_1_15"},{"note":"ApplicationCode is a class within the flink namespace used to specify the source of your Flink application's code.","symbol":"ApplicationCode","correct":"from aws_cdk import aws_kinesisanalytics_flink_alpha as flink\n# then flink.ApplicationCode.from_bucket(...) or flink.ApplicationCode.from_asset(...)"}],"quickstart":{"code":"import os\nfrom aws_cdk import (\n    Stack,\n    aws_kinesisanalytics_flink_alpha as flink,\n    aws_s3 as s3,\n    aws_iam as iam,\n)\nfrom constructs import Construct\n\nclass FlinkApplicationStack(Stack):\n    def __init__(self, scope: Construct, id: str, **kwargs):\n        super().__init__(scope, id, **kwargs)\n\n        # 1. Create an S3 bucket for your Flink application JAR/ZIP\n        #    (CDK will deploy this bucket for you)\n        app_code_bucket = s3.Bucket(self, \"FlinkAppCodeBucket\")\n\n        # 2. Define the path to your Flink application code in S3\n        #    IMPORTANT: Your Flink application JAR/ZIP must be uploaded to this path BEFORE cdk deploy.\n        flink_app_jar_key = os.environ.get('FLINK_APP_JAR_KEY', 'my-flink-app.jar') # e.g., 'path/to/my-app.jar'\n\n        # 3. Create an IAM role for Kinesis Data Analytics service execution\n        #    This role grants KDA permissions to access resources like S3, Kinesis streams, etc.\n        flink_service_role = iam.Role(self, \"FlinkServiceRole\",\n            assumed_by=iam.ServicePrincipal(\"kinesisanalytics.amazonaws.com\"),\n            description=\"IAM role for Kinesis Data Analytics Flink application\"\n        )\n        # Grant read access to the application code bucket\n        app_code_bucket.grant_read(flink_service_role)\n\n        # 4. Define the Kinesis Data Analytics Flink Application\n        flink_application = flink.Application(self, \"MyFlinkApplication\",\n            application_name=\"MyCDKFlinkApp\",\n            code=flink.ApplicationCode.from_bucket(app_code_bucket, flink_app_jar_key),\n            runtime=flink.FlinkRuntime.FLINK_1_15, # Choose your Flink runtime version: FLINK_1_11, FLINK_1_13, FLINK_1_15\n            service_execution_role=flink_service_role,\n            # Optional: Add environment variables, monitoring, logging, etc.\n            # application_properties=[flink.ApplicationProperty(\n            #     property_group_id='kda.flink.run.options',\n            #     properties={'parallelism.default': '2'})\n            # ]\n        )\n\n# To deploy this, typically you'd put it in a file like 'app.py'\n# from aws_cdk import App\n# app = App()\n# FlinkApplicationStack(app, \"MyFlinkApplicationStack\",\n#   env={'region': os.environ.get('CDK_DEFAULT_REGION'), 'account': os.environ.get('CDK_DEFAULT_ACCOUNT')}\n# )\n# app.synth()","lang":"python","description":"Demonstrates how to define a Kinesis Data Analytics Flink application using the `Application` construct. This quickstart outlines setting up an S3 bucket for the application code, creating an IAM service role with necessary permissions, and configuring the Flink runtime version."},"warnings":[{"fix":"Always pin to specific alpha versions (`==2.x.x.a0`) in environments requiring stability. Regularly review the official CDK documentation and GitHub for updates before upgrading. Consider the stability of `stable` CDK constructs for production workloads if available for your use case.","message":"This is an ALPHA construct. Its API is experimental and subject to breaking changes without prior notice. Use in production environments is not recommended without thorough testing.","severity":"breaking","affected_versions":"All alpha versions (e.g., 2.x.x.a0)"},{"fix":"Run `cdk bootstrap aws://YOUR-ACCOUNT-ID/YOUR-REGION` in your terminal for your target AWS account and region before attempting to deploy any CDK application. Replace placeholders with your actual AWS account ID and desired region.","message":"AWS CDK applications require your AWS environment to be bootstrapped before deployment. Deploying without bootstrapping will result in errors such as 'No cdk bootstrap stack found'.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Manually upload your Flink application JAR/ZIP to the designated S3 bucket and key (e.g., `s3://your-bucket/my-flink-app.jar`) before running `cdk deploy`. Ensure the IAM role created for Kinesis Data Analytics has read permissions to this S3 location.","message":"The Flink application code (JAR or ZIP file) referenced by `ApplicationCode.from_bucket` must be pre-uploaded to the specified S3 location *before* the CDK deployment. CDK does not handle the uploading of your Flink application bundle itself.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure the `service_execution_role` provided to `flink.Application` has at least: `kinesisanalytics:Run` (for KDA), `s3:GetObject` (for application code), appropriate `kinesis:` or `s3:` permissions for your data sources/sinks, and `logs:CreateLogGroup`, `logs:CreateLogStream`, `logs:PutLogEvents` for CloudWatch logging. Use `grant_read` / `grant_write` methods on your data constructs (e.g., `stream.grant_read(role)`) to simplify.","message":"The Kinesis Data Analytics service execution role requires specific IAM permissions to access input/output sources (e.g., Kinesis streams, S3 buckets), the application code bucket, and CloudWatch Logs. Insufficient permissions will lead to deployment failures or runtime errors within KDA.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Run `pip install aws-cdk-aws-kinesisanalytics-flink-alpha` to install the construct library. You may also need `aws-cdk-lib` and `constructs`.","cause":"The Python package `aws-cdk-aws-kinesisanalytics-flink-alpha` is not installed in your current environment.","error":"ModuleNotFoundError: No module named 'aws_cdk.aws_kinesisanalytics_flink_alpha'"},{"fix":"Ensure all required properties are provided with valid CDK constructs or values. For `serviceExecutionRole`, create an `iam.Role` with `kinesisanalytics.amazonaws.com` as its trusted entity. For `code`, use `flink.ApplicationCode.from_bucket(...)`.","cause":"A mandatory property like `service_execution_role` or `code` was omitted or passed an invalid value when instantiating `flink.Application`.","error":"jsii.errors.JavaScriptError: The 'serviceExecutionRole' property is required for Flink Application. (or similar error indicating a missing required property)"},{"fix":"1. Verify your Flink application JAR/ZIP is uploaded to the exact S3 bucket and key specified in your CDK code. 2. Ensure the `service_execution_role` has `s3:GetObject` permission on the specific bucket and key (or the entire bucket if appropriate).","cause":"The S3 bucket or object key specified in `ApplicationCode.from_bucket` either does not exist, or the `service_execution_role` lacks `s3:GetObject` permissions for that location.","error":"The Kinesis Data Analytics application 'MyCDKFlinkApp' failed to deploy. The provided application code bucket or key does not exist or is inaccessible."},{"fix":"Use a valid `flink.FlinkRuntime` enum member, such as `flink.FlinkRuntime.FLINK_1_15`. Check the latest CDK documentation for supported versions if you encounter issues.","cause":"An invalid or unsupported Flink runtime version was specified for the `runtime` property.","error":"jsii.errors.JavaScriptError: Flink runtime version must be one of: FLINK_1_11, FLINK_1_13, FLINK_1_15. (or similar for invalid runtime)"}],"ecosystem":"pypi"}