Registry / aws / aws-cdk-asset-kubectl-v20

aws-cdk-asset-kubectl-v20

JSON →
library2.1.4pypypi✓ verified 23d ago

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.

pip install aws-cdk-asset-kubectl-v20
INSTALL
IMPORT
SIG · AWS-CDK-ASSET-KUBE
A
aws-cdk-asset-kubectl-v20
awspythonv2.1.4
Install
2.6s avg
Import
Disk
45MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.1.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 47.3MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.6s · import 0.000s · 48MB
45MB installed
● package 45MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

KubectlV20Layer
from aws_cdk.aws_lambda import KubectlV20Layer
from aws_cdk.aws_lambda import KubectlV20Layer

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.

import os from aws_cdk import App, Stack from aws_cdk.aws_lambda import Runtime, Function, Code from aws_cdk_asset_kubectl_v20 import KubectlV20Layer class MyKubectlStack(Stack): def __init__(self, scope, id, **kwargs): super().__init__(scope, id, **kwargs) # Instantiate the Kubectl v1.20 layer kubectl_layer = KubectlV20Layer(self, 'KubectlLayer') # Example Lambda function using the layer # Replace 'my_handler' with your actual handler code # and ensure the runtime is compatible. Function(self, 'MyKubectlFunction', runtime=Runtime.PYTHON_3_9, # Use a compatible Python runtime handler='index.handler', code=Code.from_inline( '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' ), layers=[kubectl_layer] ) app = App() MyKubectlStack(app, "MyKubectlStackExample") app.synth()
Debug
Known issues
breakingThis 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.
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`.
affects: < 2.0.0 (CDK v1 vs CDK v2)
gotchaThis 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.
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.
affects: All versions of `aws-cdk-asset-kubectl-v20`
gotchaThis 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).
fix
If `helm` is required, install the appropriate `aws-cdk-asset-kubectl-helm-vXX` package and add `KubectlHelmVXXLayer` to your Lambda function's layers.
affects: All versions of `aws-cdk-asset-kubectl-v20`
gotchaThe 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.
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.
affects: All versions of `aws-cdk-asset-kubectl-v20`
Upgrade
Version history
2.1.4latest on PyPI · released Feb 7, 2025
Audit
Dependencies
aws-cdk.librequiredThis is an AWS CDK construct and requires the AWS CDK core library as a peer dependency.
Agent activity
35 hits · last 30 days
node
32
OpenAI (training)
1
Resources
aws-cdk-asset-kubectl-v20 — pip install aws-cdk-asset-kubectl-v20 · libregistry