KubernetesObjectValue
Represents a value of a specific object deployed in the cluster.
Use this to fetch any information available by the kubectl get command.
Example
declare const cluster: eks.Cluster;
// query the load balancer address
const myServiceAddress = new eks.KubernetesObjectValue(this, 'LoadBalancerAttribute', {
cluster: cluster,
objectType: 'service',
objectName: 'my-service',
jsonPath: '.status.loadBalancer.ingress[0].hostname', // https://kubernetes.io/docs/reference/kubectl/jsonpath/
});
// pass the address to a lambda function
const proxyFunction = new lambda.Function(this, 'ProxyFunction', {
handler: 'index.handler',
code: lambda.Code.fromInline('my-code'),
runtime: lambda.Runtime.NODEJS_LATEST,
environment: {
myServiceAddress: myServiceAddress.value,
},
})
# cluster: eks.Cluster
# query the load balancer address
my_service_address = eks.KubernetesObjectValue(self, "LoadBalancerAttribute",
cluster=cluster,
object_type="service",
object_name="my-service",
json_path=".status.loadBalancer.ingress[0].hostname"
)
# pass the address to a lambda function
proxy_function = lambda_.Function(self, "ProxyFunction",
handler="index.handler",
code=lambda_.Code.from_inline("my-code"),
runtime=lambda_.Runtime.NODEJS_LATEST,
environment={
"my_service_address": my_service_address.value
}
)
Cluster cluster;
// query the load balancer address
KubernetesObjectValue myServiceAddress = KubernetesObjectValue.Builder.create(this, "LoadBalancerAttribute")
.cluster(cluster)
.objectType("service")
.objectName("my-service")
.jsonPath(".status.loadBalancer.ingress[0].hostname")
.build();
// pass the address to a lambda function
Function proxyFunction = Function.Builder.create(this, "ProxyFunction")
.handler("index.handler")
.code(Code.fromInline("my-code"))
.runtime(Runtime.NODEJS_LATEST)
.environment(Map.of(
"myServiceAddress", myServiceAddress.getValue()))
.build();
// Install: dotnet add package Amazon.CDK.Lib
Cluster cluster;
// query the load balancer address
var myServiceAddress = new KubernetesObjectValue(this, "LoadBalancerAttribute", new KubernetesObjectValueProps {
Cluster = cluster,
ObjectType = "service",
ObjectName = "my-service",
JsonPath = ".status.loadBalancer.ingress[0].hostname"
});
// pass the address to a lambda function
var proxyFunction = new Function(this, "ProxyFunction", new FunctionProps {
Handler = "index.handler",
Code = Code.FromInline("my-code"),
Runtime = Runtime.NODEJS_LATEST,
Environment = new Dictionary<string, string> {
{ "myServiceAddress", myServiceAddress.Value }
}
});
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var cluster Cluster
// query the load balancer address
myServiceAddress := eks.NewKubernetesObjectValue(this, jsii.String("LoadBalancerAttribute"), &KubernetesObjectValueProps{
Cluster: cluster,
ObjectType: jsii.String("service"),
ObjectName: jsii.String("my-service"),
JsonPath: jsii.String(".status.loadBalancer.ingress[0].hostname"),
})
// pass the address to a lambda function
proxyFunction := lambda.NewFunction(this, jsii.String("ProxyFunction"), &FunctionProps{
Handler: jsii.String("index.handler"),
Code: lambda.Code_FromInline(jsii.String("my-code")),
Runtime: lambda.Runtime_NODEJS_LATEST(),
Environment: map[string]*string{
"myServiceAddress": myServiceAddress.value,
},
})
Initializer
new KubernetesObjectValue(scope: Construct, id: string, props: KubernetesObjectValueProps)
KubernetesObjectValue(scope: Construct, id: str, props: KubernetesObjectValueProps)
new KubernetesObjectValue(Construct scope, String id, KubernetesObjectValueProps props)
new KubernetesObjectValue(Construct scope, string id, KubernetesObjectValueProps props)
NewKubernetesObjectValue(Scope Construct, Id *string, Props KubernetesObjectValueProps)
Construct Props
[disable-awslint:ref-via-interface]
objectNamespacestringobject_namespacestrobjectNamespaceStringObjectNamespacestringObjectNamespace*string= 'default'#(e.g 'service', 'pod'...)
removalPolicyRemovalPolicyremoval_policyRemovalPolicyremovalPolicyRemovalPolicyRemovalPolicyRemovalPolicyRemovalPolicyRemovalPolicy= RemovalPolicy.DESTROY#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
Properties
Methods
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#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#with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#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