fresh-wire-95028
10/05/2021, 5:43 PMconst fgService = new awsx.ecs.FargateService('blah', {
...
});
const autoScaleTarget = new aws.appautoscaling.Target(`appautoscaling-target-api-${stack}`, {
resourceId: `service/${apiClusterName}/${apiServiceName}`, <----- ???
});
bored-oyster-3147
10/05/2021, 5:45 PM'd won't work. you will need to do interpolation within an
.apply(...)`billowy-army-68599
10/05/2021, 5:47 PMfresh-wire-95028
10/05/2021, 5:53 PMexport declare class FargateService extends ecs.Service {
readonly taskDefinition: FargateTaskDefinition;
constructor(name: string, args: FargateServiceArgs, opts?: pulumi.ComponentResourceOptions);
}
bored-oyster-3147
10/05/2021, 5:54 PMFargateService
extends the ecs.Service
resource from the core pulumi-aws
provider. Which should have a name
property. You can use that after declaring the service if you allowed pulumi to generate a suffixfargateService.service.name
?fresh-wire-95028
10/05/2021, 6:05 PMbillowy-army-68599
10/05/2021, 6:11 PMfresh-wire-95028
10/05/2021, 6:14 PMfargateService.service.name
?
It seems to output the following. Should I await the promise? or is there a better way of going about using it?
OutputImpl {
__pulumiOutput: true,
resources: [Function (anonymous)],
allResources: [Function (anonymous)],
isKnown: Promise { <pending> },
isSecret: Promise { <pending> },
promise: [Function (anonymous)],
toString: [Function (anonymous)],
toJSON: [Function (anonymous)]
}
bored-oyster-3147
10/05/2021, 6:24 PM.apply(...)
delegate in order to transform the value of the output to your desired result, a lot like a Promise.then(...)
function. So your resourceId
parameter could look something like this:
const fgService = new awsx.ecs.FargateService('blah', {
...
});
const autoScaleTarget = new aws.appautoscaling.Target(`appautoscaling-target-api-${stack}`, {
resourceId: fgService.service.name.apply(serviceName => `service/${apiClusterName}/${serviceName}`),
});
If apiClusterName
is also an output than there is another function you would use to get those 2 outputs into a single apply delegate.billowy-army-68599
10/05/2021, 6:27 PMfresh-wire-95028
10/05/2021, 7:30 PMapply
thing:
pulumi.all([fgService.service.name, cluster.cluster.name]).apply(([serviceName, clusterName]) => console.log(`service/${clusterName}/${serviceName}`));
outputs service/api-cluster-development-564b394/api-svc-development-4a8c1f0
which looks correct.
However...when I do:
const autoScaleTarget = new aws.appautoscaling.Target(`appautoscaling-target-api-${stack}`, {
// max/min task instances
maxCapacity: 10,
minCapacity: 1,
resourceId: pulumi.all([fgService.service.name, cluster.cluster.name]).apply(([serviceName, clusterName]) => `service/${clusterName}/${serviceName}`),
scalableDimension: 'ecs:service:DesiredCount',
serviceNamespace: 'ecs',
});
new aws.appautoscaling.Policy(`appautoscaling-policy-api-${stack}`, {
policyType: 'TargetTrackingScaling',
resourceId: autoScaleTarget.resourceId,
scalableDimension: autoScaleTarget.scalableDimension,
serviceNamespace: autoScaleTarget.serviceNamespace,
targetTrackingScalingPolicyConfiguration: {
predefinedMetricSpecification: {
predefinedMetricType: 'ECSServiceAverageCPUUtilization',
},
// scale so that we use 20% CPU
targetValue: 20,
},
});
I get the following error:
aws:appautoscaling:Policy (appautoscaling-policy-api-development):
error: 1 error occurred:
* Failed to create scaling policy: ObjectNotFoundException: No scalable target registered for service namespace: ecs, resource ID: service/api-cluster-development-564b394/api-svc-development-4a8c1f0, scalable dimension: ecs:service:DesiredCount
which is weird, because the target didn't throw the error with the same resourceId
bored-oyster-3147
10/05/2021, 8:07 PMresourceId
that you said got logged and in the errorfresh-wire-95028
10/05/2021, 9:02 PMimport * as pulumi from '@pulumi/pulumi';
import * as aws from '@pulumi/aws';
import * as awsx from '@pulumi/awsx';
interface IAutoScaleFargateServiceOpts {
iamRole: aws.iam.Role,
service: awsx.ecs.FargateService
cluster: awsx.ecs.Cluster
serviceName: string
maxCount: number
minCount: number
CPUThreshold: number
memoryThreshold: number
}
export default ({
iamRole,
service,
cluster,
serviceName,
maxCount,
minCount,
CPUThreshold,
memoryThreshold,
}: IAutoScaleFargateServiceOpts) => {
const stack = pulumi.getStack();
const autoScaleTarget = new aws.appautoscaling.Target(`appautoscaling-target-${serviceName}-${stack}`, {
// max/min task instances
maxCapacity: maxCount,
minCapacity: minCount,
roleArn: iamRole.arn,
resourceId: pulumi.interpolate`service/${cluster.cluster.name}/${service.service.name}`,
scalableDimension: 'ecs:service:DesiredCount',
serviceNamespace: 'ecs',
});
const cpuScalingPolicy = new aws.appautoscaling.Policy(`appautoscaling-policy-cpu-api-${stack}`, {
policyType: 'TargetTrackingScaling',
resourceId: autoScaleTarget.resourceId,
scalableDimension: autoScaleTarget.scalableDimension,
serviceNamespace: autoScaleTarget.serviceNamespace,
targetTrackingScalingPolicyConfiguration: {
predefinedMetricSpecification: {
predefinedMetricType: 'ECSServiceAverageCPUUtilization',
},
// scale so that we use max x% CPU
targetValue: CPUThreshold,
},
});
const memoryScalingPolicy = new aws.appautoscaling.Policy(`appautoscaling-policy-memory-api-${stack}`, {
policyType: 'TargetTrackingScaling',
resourceId: autoScaleTarget.resourceId,
scalableDimension: autoScaleTarget.scalableDimension,
serviceNamespace: autoScaleTarget.serviceNamespace,
targetTrackingScalingPolicyConfiguration: {
predefinedMetricSpecification: {
predefinedMetricType: 'ECSServiceAverageMemoryUtilization',
},
// scale so that we use max x% Memory
targetValue: memoryThreshold,
},
});
return {
cpuScalingPolicy,
memoryScalingPolicy,
};
};
bored-oyster-3147
10/05/2021, 9:17 PMfresh-wire-95028
10/05/2021, 9:22 PMbillowy-army-68599
10/05/2021, 9:41 PMbored-oyster-3147
10/05/2021, 9:48 PMNamePrefix
resource argument instead of relying on pulumi using the pulumi name. Then your resource name in AWS GUI can differ from your pulumi namefresh-wire-95028
10/06/2021, 8:17 PMbillowy-army-68599
10/06/2021, 8:30 PMfresh-wire-95028
10/06/2021, 8:35 PM