{"id":3895,"library":"aws-cdk-asset-kubectl-v20","title":"AWS CDK Asset Kubectl v20 Layer","description":"The `aws-cdk-asset-kubectl-v20` library provides an AWS CDK construct for a Lambda Layer that contains the `kubectl` (v1.20) and `aws-iam-authenticator` (v0.5.2) binaries. This enables AWS Lambda functions to interact with Kubernetes clusters. It is designed for AWS CDK v2 applications and is actively maintained by cdklabs.","status":"active","version":"2.1.4","language":"en","source_language":"en","source_url":"https://github.com/cdklabs/awscdk-asset-kubectl.git","tags":["aws","cdk","kubernetes","kubectl","lambda-layer","cdklabs","containers"],"install":[{"cmd":"pip install aws-cdk-asset-kubectl-v20","lang":"bash","label":"Install package"}],"dependencies":[{"reason":"This is an AWS CDK construct and requires the AWS CDK core library as a peer dependency.","package":"aws-cdk.lib","optional":false}],"imports":[{"note":"The v20 suffix is crucial for CDK v2 compatibility; the base package name (without suffix) typically refers to CDK v1 assets.","wrong":"from aws_cdk_asset_kubectl import KubectlV20Layer","symbol":"KubectlV20Layer","correct":"from aws_cdk_asset_kubectl_v20 import KubectlV20Layer"}],"quickstart":{"code":"import os\nfrom aws_cdk import App, Stack\nfrom aws_cdk.aws_lambda import Runtime, Function, Code\nfrom aws_cdk_asset_kubectl_v20 import KubectlV20Layer\n\nclass MyKubectlStack(Stack):\n    def __init__(self, scope, id, **kwargs):\n        super().__init__(scope, id, **kwargs)\n\n        # Instantiate the Kubectl v1.20 layer\n        kubectl_layer = KubectlV20Layer(self, 'KubectlLayer')\n\n        # Example Lambda function using the layer\n        # Replace 'my_handler' with your actual handler code\n        # and ensure the runtime is compatible.\n        Function(self, 'MyKubectlFunction',\n            runtime=Runtime.PYTHON_3_9, # Use a compatible Python runtime\n            handler='index.handler',\n            code=Code.from_inline(\n                'import os\\nimport subprocess\\n\\ndef handler(event, context):\\n    # Kubectl is available in /opt/kubectl\\n    kubectl_path = os.path.join(os.sep, 'opt', 'kubectl')\\n    try:\\n        result = subprocess.run([kubectl_path, 'version', '--client'], capture_output=True, text=True, check=True)\\n        print(f\"Kubectl client version: {result.stdout}\")\\n        return {'statusCode': 200, 'body': result.stdout}\\n    except subprocess.CalledProcessError as e:\\n        print(f\"Error executing kubectl: {e.stderr}\")\\n        return {'statusCode': 500, 'body': e.stderr}\\n'\n            ),\n            layers=[kubectl_layer]\n        )\n\napp = App()\nMyKubectlStack(app, \"MyKubectlStackExample\")\napp.synth()","lang":"python","description":"This quickstart demonstrates how to add the `KubectlV20Layer` to an AWS Lambda function within an AWS CDK stack. The example Lambda function simply runs `kubectl version --client` to confirm the binary's presence and version. Remember to adjust the Lambda runtime for compatibility with your function code and the layer."},"warnings":[{"fix":"Ensure your CDK application is using `aws-cdk.lib@^2.0.0` and that you install `aws-cdk-asset-kubectl-v20` for CDK v2. For CDK v1, use `aws-cdk-asset-kubectl`.","message":"This package is specifically for AWS CDK v2. If you are using AWS CDK v1, you should use the older `aws-cdk-asset-kubectl` package (without the `vXX` suffix), which is not compatible with CDK v2.","severity":"breaking","affected_versions":"< 2.0.0 (CDK v1 vs CDK v2)"},{"fix":"Verify your EKS cluster's Kubernetes version. If it requires a different `kubectl` client, look for an `aws-cdk-asset-kubectl-vXX` package that matches, or consider building your own custom layer.","message":"This layer provides `kubectl v1.20` and `aws-iam-authenticator v0.5.2` ONLY. If your EKS cluster is running a significantly different Kubernetes version, you might encounter compatibility issues. Always try to match your `kubectl` client version with your cluster's server version.","severity":"gotcha","affected_versions":"All versions of `aws-cdk-asset-kubectl-v20`"},{"fix":"If `helm` is required, install the appropriate `aws-cdk-asset-kubectl-helm-vXX` package and add `KubectlHelmVXXLayer` to your Lambda function's layers.","message":"This specific `aws-cdk-asset-kubectl-v20` layer does NOT include the `helm` binary. Many users expect `kubectl` layers to also contain `helm`. If you need `helm` in your Lambda function, you must use a different layer such as `aws-cdk-asset-kubectl-helm-v20` (or a higher version depending on your `kubectl` requirements).","severity":"gotcha","affected_versions":"All versions of `aws-cdk-asset-kubectl-v20`"},{"fix":"Ensure your Lambda function is configured with `aws_lambda.Architecture.X86_64`. If `ARM64` is required, you will need to find or build a compatible layer for that architecture.","message":"The layer is compiled for the `x86_64` architecture. If your Lambda function is configured to use the `ARM64` architecture, this layer will not be compatible.","severity":"gotcha","affected_versions":"All versions of `aws-cdk-asset-kubectl-v20`"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}