# KubectlProvider

Implementation of Kubectl Lambda.

Extends: Construct › KubectlProvider
Implements: IKubectlProvider, IConstruct, IDependable

- Source: [`aws-eks-v2/lib/kubectl-provider.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/aws-eks-v2/lib/kubectl-provider.ts#L145)
- Type last changed: v2.240.0 · 23 Feb 2026

## Example

```ts
const handlerRole = iam.Role.fromRoleArn(this, 'HandlerRole', 'arn:aws:iam::123456789012:role/lambda-role');
// get the serviceToken from the custom resource provider
const functionArn = lambda.Function.fromFunctionName(this, 'ProviderOnEventFunc', 'ProviderframeworkonEvent-XXX').functionArn;
const kubectlProvider = eks.KubectlProvider.fromKubectlProviderAttributes(this, 'KubectlProvider', {
  serviceToken: functionArn,
  role: handlerRole,
});

const cluster = eks.Cluster.fromClusterAttributes(this, 'Cluster', {
  clusterName: 'cluster',
  kubectlProvider,
});
```

## Initializer

```ts
new KubectlProvider(scope: Construct, id: string, props: KubectlProviderProps)
```

## Construct Props

- `awscliLayer`: [ILayerVersion](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.ILayerVersion.html) — An AWS Lambda layer that contains the `aws` CLI.

  **Default:** If not defined, a default layer will be used containing the AWS CLI 2.x.

- `cluster`: [ICluster](/cdk/api/v2/docs/aws-cdk-lib.aws_eks_v2.ICluster.html) (required) — The cluster to control.

- `environment`: { [key: string]: string } — Custom environment variables when running `kubectl` against this cluster.

  **Default:** No custom environment variables

- `kubectlLayer`: [ILayerVersion](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.ILayerVersion.html) (required) — An AWS Lambda layer that includes `kubectl` and `helm`.

- `memory`: [Size](/cdk/api/v2/docs/aws-cdk-lib.Size.html) = 1024 — The amount of memory allocated to the kubectl provider's lambda function.

- `privateSubnets`: [ISubnet](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.ISubnet.html)[] — Subnets to host the `kubectl` compute resources.

  **Default:** the k8s is accessible publicly

  If not specified, the k8s
  endpoint is expected to be accessible publicly.

- `removalPolicy`: [RemovalPolicy](/cdk/api/v2/docs/aws-cdk-lib.RemovalPolicy.html) = RemovalPolicy.DESTROY — The removal policy applied to the custom resource that provides kubectl.

  The removal policy controls what happens to the resource if it stops being managed by CloudFormation.
  This can happen in one of three situations:

  - The resource is removed from the template, so CloudFormation stops managing it
  - A change to the resource is made that requires it to be replaced, so CloudFormation stops managing it
  - The stack is deleted, so CloudFormation stops managing all resources in it

- `role`: [IRole](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) — An IAM role that can perform kubectl operations against this cluster.

  **Default:** if not specified, the default role created by a lambda function will be used.

  The role should be mapped to the `system:masters` Kubernetes RBAC role.

  This role is directly passed to the lambda handler that sends Kube Ctl commands to the cluster.

- `securityGroup`: [ISecurityGroup](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.ISecurityGroup.html) — Use `securityGroups` instead.

  **Default:** If not specified, the k8s endpoint is expected to be accessible publicly.

- `securityGroups`: [ISecurityGroup](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.ISecurityGroup.html)[] — Security groups to use for `kubectl` execution.

  **Default:** If not specified, the k8s endpoint is expected to be accessible publicly.

## Properties

- `node`: [Node](/cdk/api/v2/docs/constructs.Node.html) — The tree node.

- `role`: [IRole](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) — The IAM execution role of the handler.

- `serviceToken`: string — The custom resource provider's service token.

## Methods

- `fromKubectlProviderAttributes(scope: Construct, id: string, attrs: KubectlProviderAttributes): IKubectlProvider` (static) — Import an existing provider.

  **Parameters**

  - `scope` — Construct.
  - `id` — an id of resource.
  - `attrs` — attributes for the provider.

- `getKubectlProvider(scope: Construct, cluster: ICluster): IKubectlProvider` (static) — Take existing provider on cluster.

  **Parameters**

  - `scope` — Construct.
  - `cluster` — k8s cluster.

- `isConstruct(x: any): boolean` (static) — Checks if `x` is a construct.

  Use this method instead of `instanceof` to properly detect `Construct`
  instances, even when the construct library is symlinked.

  Explanation: in JavaScript, multiple copies of the `constructs` library on
  disk are seen as independent, completely different libraries. As a
  consequence, the class `Construct` in each copy of the `constructs` library
  is seen as a different class, and an instance of one class will not test as
  `instanceof` the other class. `npm install` will not create installations
  like this, but users may manually symlink construct libraries together or
  use a monorepo tool: in those cases, multiple copies of the `constructs`
  library can be accidentally installed, and `instanceof` will behave
  unpredictably. It is safest to avoid using `instanceof`, and using
  this type-testing method instead.

  **Parameters**

  - `x` — Any object.

  **Returns:** true if `x` is an object created from a class which extends `Construct`.

- `toString(): string` — Returns a string representation of this construct.

- `with(...mixins: IMixin[]): IConstruct` — Applies one or more mixins to this construct.

  Mixins are applied in order. The list of constructs is captured at the
  start of the call, so constructs added by a mixin will not be visited.
  Use multiple `with()` calls if subsequent mixins should apply to added
  constructs.

  **Parameters**

  - `mixins` — The mixins to apply.

  **Returns:** This construct for chaining
