aws-cdk documentation - elbv2

aws-cdk documentation - elbv2



I'm currently experimenting with the new aws-cdk, and I am finding that the documentation is quite lacking in examples.


aws-cdk



Would it be possible to provide more examples, especially around:



To be slightly more accurate:
I'm trying to build a NLB+TargetGroup+ASG on an existing VPC, and struggling on many syntax gotchas.


NLB+TargetGroup+ASG


VPC






Hi Jerome. For ELBv2 we don't have higher level constructs yet, so for now you'll have to use the cloudformation-level resources to write whatever you would write in CFN. As for ASG, you can call addUserData() on the AutoScalingGroup object.

– rix0rrr
Sep 10 '18 at 7:51


addUserData()


AutoScalingGroup




1 Answer
1



Here are some examples: For Java , These are what's inside the methods I created and does not include everything, also may not be best practice.


NetworkLoadBalancer networkLoadBalancer = new NetworkLoadBalancer(this, "NLB01", NetworkLoadBalancerProps.builder()
.withInternetFacing(false)

.withLoadBalancerName(new FnSub("$ProjectIDNLB").toString())
.withVpc(vpcNetworkRef)
.build());

AutoScalingGroupResource autoScalingGroupResource = new AutoScalingGroupResource(this, "AutoScalingGroup",
AutoScalingGroupResourceProps.builder()
.withAutoScalingGroupName(new FnSub("$ProjectID-ServerGroup"))
.withLaunchConfigurationName(launchConfigurationResource.getLaunchConfigurationName())
.withMinSize(minSizeParam.getValue().toString())
.withMaxSize(maxSizeParam.getValue().toString())
.withDesiredCapacity(desiredCapacityParam.getValue().toString())
.withTargetGroupArns(Collections.singletonList(targetGroupResource.getTargetGroupArn()))
.withVpcZoneIdentifier(subnets)
.withHealthCheckType("ELB")
.withHealthCheckGracePeriod(1020)
.build());

new LaunchConfigurationResource(this, "LaunchConfiguration",
LaunchConfigurationResourceProps.builder()
.withLaunchConfigurationName(new FnSub("$ProjectID-LaunchConfiguration"))
.withImageId(amiIDParam.getValue().toString())
.withKeyName(keyNameParam.getValue().toString())
.withSecurityGroups(securityGroupList)
.withInstanceType(instanceTypeParam.getValue().toString())
.withAssociatePublicIpAddress(false)
.build());
List<Object> defaultActionsList = new ArrayList<>();

defaultActionsList.add(ListenerResource.ActionProperty.builder()
.withTargetGroupArn(targetGroupResource.getRef().toString())
.withType("forward")
.build());

ListenerResource listenerResource = new ListenerResource(this, "Listener",
ListenerResourceProps.builder()
.withPort(80)
.withProtocol("TCP")
.withLoadBalancerArn(loadBalancerResource.getRef().toString())
.withDefaultActions(defaultActionsList)
.build());
listenerResource.addDependency( IDependable.builder()
.withDependencyElements(loadBalancerResource.getDependencyElements())
.build());

new TargetGroupResource(this, "TargetGroup",
TargetGroupResourceProps.builder()
.withHealthCheckIntervalSeconds(30) //FUTURE Parameter with limit as only [10,30] valid
.withHealthCheckProtocol("TCP")
.withHealthyThresholdCount(2)
.withPort(80)
.withProtocol("TCP")
.withUnhealthyThresholdCount(2)
.withVpcId(fnImportValueVpcId)
.withTargetGroupName("Target-Group")
.withTags(tagsTargetGroup.addTag("Owner", ownerParam.getValue().toString()))
.build());

TagList tagsNLB = new TagList();

LoadBalancerResource loadBalancerResource = new LoadBalancerResource(this, "NLB",
LoadBalancerResourceProps.builder()
.withLoadBalancerName("Network-Load-Balancer")
.withScheme("internal")
.withType("network")
.withTags(tagsNLB.addTag("Owner", ownerParam.getValue().toString()))
.withSubnets(subnets)
.build());

tagsNLB.addTag("Name", "NLB");

Output restAPIoutput =
new Output(this, "LoadBalancerArn", OutputProps.builder()
.withDescription("NLB")
.withExport(fnSubProjectID.toString())
.withValue(loadBalancerResource.getRef())
.build());



*Here is a function to create parameter *


private Parameter createParameter(String name, String type, String defaultTo, String description)
Parameter parameter =
new Parameter( this,name,
ParameterProps.builder()
.withType(type)
.withDefault(defaultTo)
.withDescription(description)
.build());
return parameter;



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

How do I collapse sections of code in Visual Studio Code for Windows?

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ