1 回答
- 最新
- 投票最多
- 评论最多
0
Here's some sample code that addresses this use case. Create a custom metric using the SQS ApproximateNumberOfMessagesVisible metric to set up alarms. This alarm is used to trigger the ECS service autoscaling policy (using step scaling in in the sample code).
const service = new ecs.FargateService(this, "myFargateSvc", {
cluster: props.cluster,
taskDefinition: taskDef,
desiredCount: 0,
assignPublicIp: false,
serviceName: 'example-service'
})
// Grant permissions to consume messages off queue
props.queue.grantConsumeMessages(service.taskDefinition.taskRole)
// Generating metric
let scalingMetric = new cw.MathExpression({
expression: "messagesVisible",
usingMetrics: {
messagesVisible: props.queue.metricApproximateNumberOfMessagesVisible()
}
})
// Scaling based on Queue Depth
const scalingTarget = service.autoScaleTaskCount({ maxCapacity: 100, minCapacity: 0 });
scalingTarget.scaleOnMetric('QueueMessagesScaling', {
metric: scalingMetric,
scalingSteps: [
{ lower: 0, upper: 0, change: -10 },
{ lower: 1, upper: 10, change: +1 },
{ lower: 10, change: +5 },
{ lower: 30, change: +10 },
{ lower: 50, change: +50 }],
cooldown: Duration.minutes(5)
})
已回答 8 个月前
相关内容
- AWS 官方已更新 1 年前
- AWS 官方已更新 1 年前
- AWS 官方已更新 3 年前
- AWS 官方已更新 2 年前
Thank you for your answer!
if i want to scale by 1 task every new 50 messages on the queue how can I do that? change: +1 change: +1 change: +1 ...... or change: +1 change: +2 change: +4 change: +4 ..... ...