[英]Running multiple ECS tasks based on same task definition but with different environment variables
I have a task to process large amount of data, so data is batched into lots of parts. 我有一个处理大量数据的任务,因此数据被分批到很多部分。 I have written the task definition for this type of work but now I know only how to set up them manually via registering multiple task definitions for each env.
我已经为这种类型的工作编写了任务定义,但现在我只知道如何通过为每个env注册多个任务定义来手动设置它们。
sample where each task has its own env BATCH_ID 示例每个任务都有自己的env BATCH_ID
aws ecs register-task-definition --cli-input-json file://taskdef1.json
aws ecs run-task --cluster $cluster --task-definition process_data_1
aws ecs register-task-definition --cli-input-json file://taskdef2.json
aws ecs run-task --cluster $cluster --task-definition process_data_2
It would be even nice to have some .manifest file of all task arns put for cluster. 将所有任务arns的一些.manifest文件放入群集中会更好。
Is there someway to run multiple similar ECS tasks with different env params in more elegant way then creating enormous amount of different taskdefs files? 有没有办法以更优雅的方式运行具有不同env参数的多个类似ECS任务,然后创建大量不同的taskdefs文件?
Thanks for any help and suggestions 感谢您的任何帮助和建议
You can override environmental variable when you run the task with --overrides
flag. 使用
--overrides
标志运行任务时,可以覆盖环境变量。 I use this all the time; 我经常用这个; you can either override an existing environmental variable (defined in task definition) or simply add a new one.
您可以覆盖现有的环境变量(在任务定义中定义),也可以只添加一个新变量。
--overrides
accepts only JSON (no shorthand syntax); --overrides
只接受JSON(没有简写语法); in your case, it would look like: 在你的情况下,它看起来像:
{
"containerOverrides": [
{
"name": "containerNameFromTaskDefinition",
"environment": [
{
"name": "BATCH_ID",
"value": "sampleBatchId"
}
]
}
]
}
and the command: 和命令:
aws ecs run-task --cluster $cluster --task-definition process_data_1 --overrides {"containerOverrides":[...]}
You can use --overrides
to override even more things of course: https://docs.aws.amazon.com/cli/latest/reference/ecs/run-task.html 您可以使用
--overrides
来覆盖更多的东西: https : --overrides
I may be misunderstanding the problem here, but could you just put the variable in your cli input .json and use sed to swap out the batch ID before you run the task? 我可能在这里误解了这个问题,但你可以把变量放在你的cli输入.json中,并在运行任务之前使用sed交换批处理ID吗? I've done this for application deployments when I need to swap out env vars.
当我需要换掉env变种时,我已经为应用程序部署做了这个。
First, put the variable you want to replace in your taskdef template file (like %BATCH_ID%) 首先,将要替换的变量放在taskdef模板文件中(如%BATCH_ID%)
Then do something like this: (NOTE: Bash script is off the top of my head and may need fixing) 然后做这样的事情:(注意:Bash脚本是我的头顶,可能需要修复)
sed 's/%BATCH_ID%/$BATCH_ID' generic_taskdef.json > process_data_$BATCH_ID.json
aws ecs register-task-definition --cli-input-json file://process_data_$BATCH_ID.json
aws ecs run-task --cluster $cluster --task-definition process_data_$BATCH_ID
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.