Skip to content
v2.275.0

KubectlProvider ​

Implementation of Kubectl Lambda.

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,
});
python
handler_role = iam.Role.from_role_arn(self, "HandlerRole", "arn:aws:iam::123456789012:role/lambda-role")
# get the serviceToken from the custom resource provider
function_arn = lambda_.Function.from_function_name(self, "ProviderOnEventFunc", "ProviderframeworkonEvent-XXX").function_arn
kubectl_provider = eks.KubectlProvider.from_kubectl_provider_attributes(self, "KubectlProvider",
    service_token=function_arn,
    role=handler_role
)

cluster = eks.Cluster.from_cluster_attributes(self, "Cluster",
    cluster_name="cluster",
    kubectl_provider=kubectl_provider
)
java
IRole handlerRole = Role.fromRoleArn(this, "HandlerRole", "arn:aws:iam::123456789012:role/lambda-role");
// get the serviceToken from the custom resource provider
String functionArn = Function.fromFunctionName(this, "ProviderOnEventFunc", "ProviderframeworkonEvent-XXX").getFunctionArn();
IKubectlProvider kubectlProvider = KubectlProvider.fromKubectlProviderAttributes(this, "KubectlProvider", KubectlProviderAttributes.builder()
        .serviceToken(functionArn)
        .role(handlerRole)
        .build());

ICluster cluster = Cluster.fromClusterAttributes(this, "Cluster", ClusterAttributes.builder()
        .clusterName("cluster")
        .kubectlProvider(kubectlProvider)
        .build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
var handlerRole = Role.FromRoleArn(this, "HandlerRole", "arn:aws:iam::123456789012:role/lambda-role");
// get the serviceToken from the custom resource provider
var functionArn = Function.FromFunctionName(this, "ProviderOnEventFunc", "ProviderframeworkonEvent-XXX").FunctionArn;
var kubectlProvider = KubectlProvider.FromKubectlProviderAttributes(this, "KubectlProvider", new KubectlProviderAttributes {
    ServiceToken = functionArn,
    Role = handlerRole
});

var cluster = Cluster.FromClusterAttributes(this, "Cluster", new ClusterAttributes {
    ClusterName = "cluster",
    KubectlProvider = kubectlProvider
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
handlerRole := iam.Role_FromRoleArn(this, jsii.String("HandlerRole"), jsii.String("arn:aws:iam::123456789012:role/lambda-role"))
// get the serviceToken from the custom resource provider
functionArn := lambda.Function_FromFunctionName(this, jsii.String("ProviderOnEventFunc"), jsii.String("ProviderframeworkonEvent-XXX")).FunctionArn
kubectlProvider := eks.KubectlProvider_FromKubectlProviderAttributes(this, jsii.String("KubectlProvider"), &KubectlProviderAttributes{
	ServiceToken: functionArn,
	Role: handlerRole,
})

cluster := eks.Cluster_FromClusterAttributes(this, jsii.String("Cluster"), &ClusterAttributes{
	ClusterName: jsii.String("cluster"),
	KubectlProvider: KubectlProvider,
})

Initializer ​

ts
new KubectlProvider(scope: Construct, id: string, props: KubectlProviderProps)
python
KubectlProvider(scope: Construct, id: str, props: KubectlProviderProps)
java
new KubectlProvider(Construct scope, String id, KubectlProviderProps props)
csharp
new KubectlProvider(Construct scope, string id, KubectlProviderProps props)
go
NewKubectlProvider(Scope Construct, Id *string, Props KubectlProviderProps)

Construct Props ​

awscliLayeroptionalILayerVersionawscli_layeroptionalILayerVersionawscliLayeroptionalILayerVersionAwscliLayeroptionalILayerVersionAwscliLayeroptionalILayerVersion#
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.

clusterIClusterclusterIClusterclusterIClusterClusterIClusterClusterIClusterrequired#
The cluster to control.
environmentoptional{ [key: string]: string }environmentoptionaltyping.Mapping[str, str]environmentoptionalMap<String, String>EnvironmentoptionalIDictionary<string, string>Environmentoptional*map[string]*string#
Custom environment variables when running `kubectl` against this cluster.

Default: No custom environment variables

kubectlLayerILayerVersionkubectl_layerILayerVersionkubectlLayerILayerVersionKubectlLayerILayerVersionKubectlLayerILayerVersionrequired#
An AWS Lambda layer that includes `kubectl` and `helm`.
memoryoptionalSizememoryoptionalSizememoryoptionalSizeMemoryoptionalSizeMemoryoptionalSize= 1024#
The amount of memory allocated to the kubectl provider's lambda function.
privateSubnetsoptionalISubnet[]private_subnetsoptionaltyping.List[ISubnet]privateSubnetsoptionalList<ISubnet>PrivateSubnetsoptionalISubnet[]PrivateSubnetsoptional*[]ISubnet#
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.

removalPolicyoptionalRemovalPolicyremoval_policyoptionalRemovalPolicyremovalPolicyoptionalRemovalPolicyRemovalPolicyoptionalRemovalPolicyRemovalPolicyoptionalRemovalPolicy= RemovalPolicy.DESTROY#
The removal policy applied to the custom resource that provides kubectl.
notes

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
roleoptionalIRoleroleoptionalIRoleroleoptionalIRoleRoleoptionalIRoleRoleoptionalIRole#
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.

securityGroupoptionalISecurityGroupsecurity_groupoptionalISecurityGroupsecurityGroupoptionalISecurityGroupSecurityGroupoptionalISecurityGroupSecurityGroupoptionalISecurityGroupdeprecated#
Use `securityGroups` instead.

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

securityGroupsoptionalISecurityGroup[]security_groupsoptionaltyping.List[ISecurityGroup]securityGroupsoptionalList<ISecurityGroup>SecurityGroupsoptionalISecurityGroup[]SecurityGroupsoptional*[]ISecurityGroup#
Security groups to use for `kubectl` execution.

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

Properties ​

nodeNodenodeNodenodeNodeNodeNodeNodeNode#
The tree node.
rolemay be undefinedIRolerolemay be undefinedIRolerolemay be undefinedIRoleRolemay be undefinedIRoleRolemay be undefinedIRole#
The IAM execution role of the handler.
serviceTokenstringservice_tokenstrserviceTokenStringServiceTokenstringServiceToken*string#
The custom resource provider's service token.

Methods ​

fromKubectlProviderAttributes(scope: Construct, id: string, attrs: KubectlProviderAttributes): IKubectlProvider@staticmethod def from_kubectl_provider_attributes(scope: Construct, id: str, attrs: KubectlProviderAttributes) -> IKubectlProviderpublic static IKubectlProvider fromKubectlProviderAttributes(Construct scope, String id, KubectlProviderAttributes attrs)public static IKubectlProvider FromKubectlProviderAttributes(Construct scope, string id, KubectlProviderAttributes attrs)func FromKubectlProviderAttributes(Scope Construct, Id *string, Attrs KubectlProviderAttributes) IKubectlProviderstatic#
Import an existing provider.
3 parameters

Parameters

  • scopescopescopescopeScope — Construct.
  • ididididId — an id of resource.
  • attrsattrsattrsattrsAttrs — attributes for the provider.
getKubectlProvider(scope: Construct, cluster: ICluster): IKubectlProvider@staticmethod def get_kubectl_provider(scope: Construct, cluster: ICluster) -> IKubectlProviderpublic static IKubectlProvider getKubectlProvider(Construct scope, ICluster cluster)public static IKubectlProvider GetKubectlProvider(Construct scope, ICluster cluster)func GetKubectlProvider(Scope Construct, Cluster ICluster) IKubectlProviderstatic#
Take existing provider on cluster.
2 parameters

Parameters

  • scopescopescopescopeScope — Construct.
  • clusterclusterclusterclusterCluster — k8s cluster.
isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#
Checks if `x` is a construct.
notes · 1 parameter · returns

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

  • xxxxX — Any object.

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

toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#
Returns a string representation of this construct.
with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func 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.

1 parameter · returns

Parameters

  • mixinsmixinsmixinsmixinsMixins — The mixins to apply.

Returns: This construct for chaining