Search code examples
amazon-web-servicesaws-cdk

AWS CDK - Use FARGATE_SPOT with ApplicationLoadBalancedFargateService


I'm using ApplicationLoadBalancedFargateService in my AWS-CDK project (using Java).

I would like to configure the service to spin up only FARGATE_SPOT instances, but I haven't find any way to do it. Is there any way to do it?


Solution

  • I think I found the solution:

        Cluster cluster = new Cluster(...);
        cluster.enableFargateCapacityProviders();
    
        ApplicationLoadBalancedFargateService fargateService = new ApplicationLoadBalancedFargateService(
                this,
                "FargateService",
                ApplicationLoadBalancedFargateServiceProps.builder()
                        .cluster(cluster)
                        .capacityProviderStrategies(
                                singletonList(CapacityProviderStrategy.builder()
                                        .capacityProvider("FARGATE_SPOT")
                                        .weight(1)
                                        .build()
                                ))
                        ....
                        .build());