我正在尝试根据 CloudWatch 警报(命名空间 - AWS/SQS,指标名称 - ApproximateNumberOfMessagesVisible)在 AWS ECS 中自动扩展 Fargate 服务。我设法在 AWS 控制台中做到了这一点,但不是通过代码(在 Pulumi 中)。
我对代码的建议如下:
const vpc = new awsx.ec2.Vpc("vpc", {
subnets: [{ type: "public" }],
});
const my_cluster = new awsx.ecs.Cluster("my-cluster", { vpc });
const task = new awsx.ecs.FargateTaskDefinition(...)
const my_fargateService = new awsx.ecs.FargateService(
"my-fargateService",
{
cluster: my_cluster,
taskDefinition: task,
desiredCount: 0,
}
);
const sqs_queue = new aws.sqs.Queue(
"fargateServiceQueque"
);
const autoscaling_Policy1 = new aws.autoscaling.Policy("autoscaling_Policy1", {
policyType: "StepScaling",
adjustmentType: "ExactCapacity",
stepAdjustments: [{
metricIntervalUpperBound: 1,
scalingAdjustment: 0
}],
// I think problem here
autoscalingGroupName: autoScalingGroupFromFargateService.name // ???
});
const sqs_less_than_1 = new aws.cloudwatch.MetricAlarm("sqs_less_than_1_message_visible", {
comparisonOperator: "LessThanThreshold",
evaluationPeriods: "2",
metricName: "approximateNumberOfMessagesVisible",
namespace: "AWS/SQS",
period: "120",
statistic: "Maximum",
threshold: "1",
dimensions: {
QueueName: sqs_queue.name,
},
alarmDescription: "This metric monitors number of messages in sqs queue",
alarmActions: [] // I think it should be -> [autoscaling_Policy1.arn],
});
问题 - 我不知道如何从 my_fargateService 检索自动缩放组(“autoScalingGroupFromFargateService.name”)。