Skip to content
v2.274.0

VirtualNode L2 construct ​

VirtualNode represents a newly defined AppMesh VirtualNode.

Any inbound traffic that your virtual node expects should be specified as a listener. Any outbound traffic that your virtual node expects to reach should be specified as a backend. [disable-awslint:no-grants]

Example ​

ts
// Cloud Map service discovery is currently required for host ejection by outlier detection
const vpc = new ec2.Vpc(this, 'vpc');
const namespace = new cloudmap.PrivateDnsNamespace(this, 'test-namespace', {
    vpc,
    name: 'domain.local',
});
const service = namespace.createService('Svc');

declare const mesh: appmesh.Mesh;
const node = mesh.addVirtualNode('virtual-node', {
  serviceDiscovery: appmesh.ServiceDiscovery.cloudMap(service),
  listeners: [appmesh.VirtualNodeListener.http({
    outlierDetection: {
      baseEjectionDuration: Duration.seconds(10),
      interval: Duration.seconds(30),
      maxEjectionPercent: 50,
      maxServerErrors: 5,
    },
  })],
});
python
# mesh: appmesh.Mesh
# Cloud Map service discovery is currently required for host ejection by outlier detection
vpc = ec2.Vpc(self, "vpc")
namespace = cloudmap.PrivateDnsNamespace(self, "test-namespace",
    vpc=vpc,
    name="domain.local"
)
service = namespace.create_service("Svc")
node = mesh.add_virtual_node("virtual-node",
    service_discovery=appmesh.ServiceDiscovery.cloud_map(service),
    listeners=[appmesh.VirtualNodeListener.http(
        outlier_detection=appmesh.OutlierDetection(
            base_ejection_duration=Duration.seconds(10),
            interval=Duration.seconds(30),
            max_ejection_percent=50,
            max_server_errors=5
        )
    )]
)
java
Mesh mesh;
// Cloud Map service discovery is currently required for host ejection by outlier detection
Vpc vpc = new Vpc(this, "vpc");
PrivateDnsNamespace namespace = PrivateDnsNamespace.Builder.create(this, "test-namespace")
        .vpc(vpc)
        .name("domain.local")
        .build();
Service service = namespace.createService("Svc");
VirtualNode node = mesh.addVirtualNode("virtual-node", VirtualNodeBaseProps.builder()
        .serviceDiscovery(ServiceDiscovery.cloudMap(service))
        .listeners(List.of(VirtualNodeListener.http(HttpVirtualNodeListenerOptions.builder()
                .outlierDetection(OutlierDetection.builder()
                        .baseEjectionDuration(Duration.seconds(10))
                        .interval(Duration.seconds(30))
                        .maxEjectionPercent(50)
                        .maxServerErrors(5)
                        .build())
                .build())))
        .build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
Mesh mesh;
// Cloud Map service discovery is currently required for host ejection by outlier detection
var vpc = new Vpc(this, "vpc");
var namespace = new PrivateDnsNamespace(this, "test-namespace", new PrivateDnsNamespaceProps {
    Vpc = vpc,
    Name = "domain.local"
});
var service = namespace.CreateService("Svc");
var node = mesh.AddVirtualNode("virtual-node", new VirtualNodeBaseProps {
    ServiceDiscovery = ServiceDiscovery.CloudMap(service),
    Listeners = new [] { VirtualNodeListener.Http(new HttpVirtualNodeListenerOptions {
        OutlierDetection = new OutlierDetection {
            BaseEjectionDuration = Duration.Seconds(10),
            Interval = Duration.Seconds(30),
            MaxEjectionPercent = 50,
            MaxServerErrors = 5
        }
    }) }
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var mesh Mesh
// Cloud Map service discovery is currently required for host ejection by outlier detection
vpc := ec2.NewVpc(this, jsii.String("vpc"))
namespace := cloudmap.NewPrivateDnsNamespace(this, jsii.String("test-namespace"), &PrivateDnsNamespaceProps{
	Vpc: Vpc,
	Name: jsii.String("domain.local"),
})
service := namespace.CreateService(jsii.String("Svc"))
node := mesh.addVirtualNode(jsii.String("virtual-node"), &VirtualNodeBaseProps{
	ServiceDiscovery: appmesh.ServiceDiscovery_CloudMap(service),
	Listeners: []VirtualNodeListener{
		appmesh.VirtualNodeListener_Http(&HttpVirtualNodeListenerOptions{
			OutlierDetection: &OutlierDetection{
				BaseEjectionDuration: awscdk.Duration_Seconds(jsii.Number(10)),
				Interval: awscdk.Duration_*Seconds(jsii.Number(30)),
				MaxEjectionPercent: jsii.Number(50),
				MaxServerErrors: jsii.Number(5),
			},
		}),
	},
})

Initializer ​

ts
new VirtualNode(scope: Construct, id: string, props: VirtualNodeProps)
python
VirtualNode(scope: Construct, id: str, props: VirtualNodeProps)
java
new VirtualNode(Construct scope, String id, VirtualNodeProps props)
csharp
new VirtualNode(Construct scope, string id, VirtualNodeProps props)
go
NewVirtualNode(Scope Construct, Id *string, Props VirtualNodeProps)

Construct Props ​

accessLogoptionalAccessLogaccess_logoptionalAccessLogaccessLogoptionalAccessLogAccessLogoptionalAccessLogAccessLogoptionalAccessLog#
Access Logging Configuration for the virtual node.

Default: No access logging

backendDefaultsoptionalBackendDefaultsbackend_defaultsoptionalBackendDefaultsbackendDefaultsoptionalBackendDefaultsBackendDefaultsoptionalBackendDefaultsBackendDefaultsoptionalBackendDefaults#
Default Configuration Virtual Node uses to communicate with Virtual Service.

Default: No Config

backendsoptionalBackend[]backendsoptionaltyping.List[Backend]backendsoptionalList<Backend>BackendsoptionalBackend[]Backendsoptional*[]Backend#
Virtual Services that this is node expected to send outbound traffic to.

Default: No backends

listenersoptionalVirtualNodeListener[]listenersoptionaltyping.List[VirtualNodeListener]listenersoptionalList<VirtualNodeListener>ListenersoptionalVirtualNodeListener[]Listenersoptional*[]VirtualNodeListener#
Initial listener for the virtual node.

Default: No listeners

meshIMeshmeshIMeshmeshIMeshMeshIMeshMeshIMeshrequired#
The Mesh which the VirtualNode belongs to.
serviceDiscoveryoptionalServiceDiscoveryservice_discoveryoptionalServiceDiscoveryserviceDiscoveryoptionalServiceDiscoveryServiceDiscoveryoptionalServiceDiscoveryServiceDiscoveryoptionalServiceDiscovery#
Defines how upstream clients will discover this VirtualNode.

Default: No Service Discovery

virtualNodeNameoptionalstringvirtual_node_nameoptionalstrvirtualNodeNameoptionalStringVirtualNodeNameoptionalstringVirtualNodeNameoptional*string#
The name of the VirtualNode.

Default: A name is automatically determined

Properties ​

The environment this resource belongs to.
notes

For resources that are created and managed in a Stack (those created by creating new class instances like new Role(), new Bucket(), etc.), this is always the same as the environment of the stack they belong to.

For referenced resources (those obtained from referencing methods like Role.fromRoleArn(), Bucket.fromBucketName(), etc.), they might be different than the stack they were imported into.

Collection of grants for this Virtual Node.
meshIMeshmeshIMeshmeshIMeshMeshIMeshMeshIMeshrequired#
The Mesh which the VirtualNode belongs to.
nodeNodenodeNodenodeNodeNodeNodeNodeNoderequired#
The tree node.
PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringrequiredstatic#
Uniquely identifies this class.
stackStackstackStackstackStackStackStackStackStackrequired#
The stack in which this resource is defined.
virtualNodeArnstringvirtual_node_arnstrvirtualNodeArnStringVirtualNodeArnstringVirtualNodeArn*stringrequired#
The Amazon Resource Name belonging to the VirtualNode.
virtualNodeNamestringvirtual_node_namestrvirtualNodeNameStringVirtualNodeNamestringVirtualNodeName*stringrequired#
The name of the VirtualNode.
virtualNodeRefVirtualNodeReferencevirtual_node_refVirtualNodeReferencevirtualNodeRefVirtualNodeReferenceVirtualNodeRefVirtualNodeReferenceVirtualNodeRefVirtualNodeReferencerequired#
A reference to a VirtualNode resource.

Methods ​

addBackend(backend: Backend): voiddef add_backend(self, backend: Backend) -> Nonepublic void addBackend(Backend backend)public void AddBackend(Backend backend)func AddBackend(Backend Backend)#
Add a Virtual Services that this node is expected to send outbound traffic to.
addListener(listener: VirtualNodeListener): voiddef add_listener(self, listener: VirtualNodeListener) -> Nonepublic void addListener(VirtualNodeListener listener)public void AddListener(VirtualNodeListener listener)func AddListener(Listener VirtualNodeListener)#
Utility method to add an inbound listener for this VirtualNode.
notes

Note: At this time, Virtual Nodes support at most one listener. Adding more than one will result in a failure to deploy the CloudFormation stack. However, the App Mesh team has plans to add support for multiple listeners on Virtual Nodes and Virtual Routers.

applyCrossStackReferenceStrength(strength: ReferenceStrength): voiddef apply_cross_stack_reference_strength(self, strength: ReferenceStrength) -> Nonepublic void applyCrossStackReferenceStrength(ReferenceStrength strength)public void ApplyCrossStackReferenceStrength(ReferenceStrength strength)func ApplyCrossStackReferenceStrength(Strength ReferenceStrength)#
Override the cross-stack reference strength for this resource.
notes · 1 parameter

When set, any cross-stack reference to this resource will use the specified mechanism instead of the global default determined by the @aws-cdk/core:defaultCrossStackReferences context key. This is useful for selectively weakening specific references to avoid the "deadly embrace" problem without changing the app-wide default.

Parameters

  • strengthstrengthstrengthstrengthStrength — - The reference strength to use for this resource.
applyRemovalPolicy(policy: RemovalPolicy): voiddef apply_removal_policy(self, policy: RemovalPolicy) -> Nonepublic void applyRemovalPolicy(RemovalPolicy policy)public void ApplyRemovalPolicy(RemovalPolicy policy)func ApplyRemovalPolicy(Policy RemovalPolicy)#
Apply the given removal policy to this resource.
notes

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).

fromVirtualNodeArn(scope: Construct, id: string, virtualNodeArn: string): IVirtualNode@staticmethod def from_virtual_node_arn(scope: Construct, id: str, virtual_node_arn: str) -> IVirtualNodepublic static IVirtualNode fromVirtualNodeArn(Construct scope, String id, String virtualNodeArn)public static IVirtualNode FromVirtualNodeArn(Construct scope, string id, string virtualNodeArn)func FromVirtualNodeArn(Scope Construct, Id *string, VirtualNodeArn *string) IVirtualNodestatic#
Import an existing VirtualNode given an ARN.
fromVirtualNodeAttributes(scope: Construct, id: string, attrs: VirtualNodeAttributes): IVirtualNode@staticmethod def from_virtual_node_attributes(scope: Construct, id: str, attrs: VirtualNodeAttributes) -> IVirtualNodepublic static IVirtualNode fromVirtualNodeAttributes(Construct scope, String id, VirtualNodeAttributes attrs)public static IVirtualNode FromVirtualNodeAttributes(Construct scope, string id, VirtualNodeAttributes attrs)func FromVirtualNodeAttributes(Scope Construct, Id *string, Attrs VirtualNodeAttributes) IVirtualNodestatic#
Import an existing VirtualNode given its name.
grantStreamAggregatedResources(identity: IGrantable): Grantdef grant_stream_aggregated_resources(self, identity: IGrantable) -> Grantpublic Grant grantStreamAggregatedResources(IGrantable identity)public Grant GrantStreamAggregatedResources(IGrantable identity)func GrantStreamAggregatedResources(Identity IGrantable) Grant#
The use of this method is discouraged. Please use `grants.streamAggregatedResources()` instead.

[disable-awslint:no-grants]

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.

isOwnedResource(construct: IConstruct): boolean@staticmethod def is_owned_resource(construct: IConstruct) -> boolpublic static Boolean isOwnedResource(IConstruct construct)public static bool IsOwnedResource(IConstruct construct)func IsOwnedResource(Construct IConstruct) *boolstatic#
Returns true if the construct was created by CDK, and false otherwise.
isResource(construct: IConstruct): boolean@staticmethod def is_resource(construct: IConstruct) -> boolpublic static Boolean isResource(IConstruct construct)public static bool IsResource(IConstruct construct)func IsResource(Construct IConstruct) *boolstatic#
Check whether the given construct is a Resource.
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.