1 Respuesta
- Más nuevo
- Más votos
- Más comentarios
1
Here is an example for Java SDK
Modify your stack to include a CfnOutput for the Load Balancer's DNS name:
package com.myorg;
import software.amazon.awscdk.core.*;
import software.amazon.awscdk.services.ec2.Vpc;
import software.amazon.awscdk.services.ecs.Cluster;
import software.amazon.awscdk.services.ecs.patterns.ApplicationLoadBalancedFargateService;
import software.amazon.awscdk.services.ecs.ContainerImage;
public class FargateStack extends Stack {
public FargateStack(final Construct scope, final String id, final StackProps props) {
super(scope, id, props);
Vpc vpc = Vpc.Builder.create(this, "MyVpc").maxAzs(3).build();
Cluster cluster = Cluster.Builder.create(this, "MyCluster").vpc(vpc).build();
ApplicationLoadBalancedFargateService fargateService = ApplicationLoadBalancedFargateService.Builder.create(this, "MyFargateService")
.cluster(cluster)
.cpu(256)
.desiredCount(1)
.taskImageOptions(
ApplicationLoadBalancedTaskImageOptions.builder()
.image(ContainerImage.fromRegistry("amazon/amazon-ecs-sample"))
.build())
.memoryLimitMiB(512)
.publicLoadBalancer(true)
.build();
// Export the Load Balancer DNS name
CfnOutput.Builder.create(this, "ServiceUrl")
.exportName("MyFargateServiceUrl") // This is the key name you will use to import in other stacks
.value(fargateService.getLoadBalancer().getLoadBalancerDnsName())
.build();
}
}
public class MyApp extends App {
public static void main(final String[] args) {
App app = new App();
new FargateStack(app, "MyFargateStack", new StackProps.builder().build());
app.synth();
}
}
Use the Exported URL in Another Service or Stack
import software.amazon.awscdk.core.Fn;
public class AnotherServiceStack extends Stack {
public AnotherServiceStack(final Construct scope, final String id, final StackProps props) {
super(scope, id, props);
// Import the URL
String importedUrl = Fn.importValue("MyFargateServiceUrl");
// Use the imported URL here for whatever needs it
System.out.println("Imported Service URL: " + importedUrl);
}
}
Contenido relevante
- OFICIAL DE AWSActualizada hace un año
- OFICIAL DE AWSActualizada hace 3 años
- OFICIAL DE AWSActualizada hace 10 meses