gpt4 book ai didi

amazon-web-services - 你能通过 fargate 中的同一个容器将 desiredcount 缩小到 0 吗

转载 作者:行者123 更新时间:2023-12-05 02:52:13 27 4
gpt4 key购买 nike

我有一个 fargate 服务,其中一个任务运行一个容器。所以,我的容器是一个定制的管道,它基于 SQS 计数运行。因此,如果所有记录都已处理,那么我将停止容器中的管道。所以,我想知道的是,我可以将所需的服务计数设置为 0,而不是停止管道吗?(此服务是此容器任务的父级)

最佳答案

是的,您可以在流程完成后将欲望计数设置为零,但您需要考虑的事情很少。

  • 您的节点进程在完成操作后应该退出
  • Dockerfile 应该有一个有效的入口点,aws-cli
  • Fargate 服务应该有 ecs 服务更新操作

例如文件

FROM node:alpine
RUN apk add --no-cache python py-pip

RUN pip install awscli
RUN aws --version
WORKDIR /app
COPY app.js .
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT /entrypoint.sh

当 nodejs 进程从 SQS 完成时,将处理 nodejs 进程并将服务计数设置为 0 的入口点。

#!/bin/sh
# start the node process, but it should exit once it processes all SQS
node app.js
# once process is done, we are good to scale down the service
aws ecs update-service --cluster my-cluster --region us-west-2 --service my-http-service --desired-count 0

将在 1 分钟后退出的示例节点进程,app.js

function intervalFunc() {
console.log('Container will stop in 1 minutes');
}

setInterval(intervalFunc, 1500);
setTimeout((function() {
return process.exit(0);
}), 60000);

所以Docker镜像起着重要的作用,节点进程应该退出,否则它会继续运行。

关于amazon-web-services - 你能通过 fargate 中的同一个容器将 desiredcount 缩小到 0 吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62720021/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com