import * as pulumi from "@pulumi/pulumi" ; import * as aws from "@pulumi/aws" ; import * as awsx from "@pulumi/awsx" ; const config = new pulumi . Config ( "aws" ) ; const providerOpts = { provider : new aws . Provider ( "prov" , { region : < aws . Region > config . require ( "envRegion" ) } ) } ; const cluster = new awsx . ecs . Cluster ( "testing" , { } , providerOpts ) ; const loadBalancer = new awsx . elasticloadbalancingv2 . ApplicationLoadBalancer ( "nginx" , { external : true } , providerOpts ) ; const targetGroup = loadBalancer . createTargetGroup ( "nginx" , { port : 80 , targetType : "instance" } ) ; const nginxListener = targetGroup . createListener ( "nginx" , { port : 80 , external : true } ) ; const service = new awsx . ecs . EC2Service ( "nginx" , { cluster , taskDefinitionArgs : { networkMode : "bridge" , containers : { nginx : { image : "nginx" , memory : 128 , portMappings : [ nginxListener ] , } , } , } , desiredCount : 2 , } , providerOpts ) ; const autoScalingGroup = cluster . createAutoScalingGroup ( "testing-1" , { subnetIds : awsx . ec2 . Vpc . getDefault ( providerOpts ) . publicSubnetIds , targetGroups : [ targetGroup ] , templateParameters : { minSize : 5 , } , launchConfigurationArgs : { instanceType : "m5.large" , associatePublicIpAddress : true , } , } ) ; const requestCountScalingPolicy = autoScalingGroup . scaleToTrackRequestCountPerTarget ( "onHighRequest" , { targetValue : 5 , estimatedInstanceWarmup : 120 , targetGroup : targetGroup , } ) ; const stepScalingPolicy = autoScalingGroup . scaleInSteps ( "scale-in-out" , { metric : awsx . ecs . metrics . memoryUtilization ( { service , unit : "Percent" , statistic : "Average" } ) , adjustmentType : "PercentChangeInCapacity" , steps : { upper : [ { value : 60 , adjustment : 10 } , { value : 70 , adjustment : 30 } ] , lower : [ { value : 40 , adjustment : - 10 } , { value : 30 , adjustment : - 30 } ] } , } ) ; export const nginxEndpoint = nginxListener . endpoint ;