Skip to content

Instantly share code, notes, and snippets.

@pahud
Last active April 24, 2024 18:20
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save pahud/9affaa353f52e734a638b1329f7ca3d0 to your computer and use it in GitHub Desktop.
Save pahud/9affaa353f52e734a638b1329f7ca3d0 to your computer and use it in GitHub Desktop.
ECS Task export/import
# export the task def
family='TaskDefName'
$ aws ecs describe-task-definition --task-definition $family \
--query "taskDefinition.{family:family, taskRoleArn:taskRoleArn, executionRoleArn:executionRoleArn, networkMode:networkMode, containerDefinitions:containerDefinitions, volumes:volumes, placementConstraints:placementConstraints, requiresCompatibilities:requiresCompatibilities, cpu:cpu, memory:memory, tags:tags, pidMode:pidMode, ipcMode:ipcMode, proxyConfiguration:proxyConfiguration}" | jq 'del(.[] | nulls)' > taskDef.json
# import the task def into newFamily task family
$ aws ecs register-task-definition --cli-input-json file://taskDef.json --family newFamily
# one-liner
aws ecs describe-task-definition --task-definition $family \
--query "taskDefinition.{family:family, taskRoleArn:taskRoleArn, executionRoleArn:executionRoleArn, networkMode:networkMode, containerDefinitions:containerDefinitions, volumes:volumes, placementConstraints:placementConstraints, requiresCompatibilities:requiresCompatibilities, cpu:cpu, memory:memory, tags:tags, pidMode:pidMode, ipcMode:ipcMode, proxyConfiguration:proxyConfiguration}" | jq 'del(.[] | nulls)' | xargs -0 aws ecs register-task-definition --family newFamily --cli-input-json
# convert the taskDef.json to taskDef.yaml
docker run -v ${PWD}:/workdir mikefarah/yq yq r taskDef.json > taskDef.yaml
@tomw1808
Copy link

tomw1808 commented Apr 5, 2023

convert the taskDef.json to taskDef.yaml

07:37:56 initCommand [WARN] JSON file output is now JSON by default (instead of yaml). Use '-oy' or '--output-format=yaml' for yaml output

docker run -v ${PWD}:/workdir mikefarah/yq -oy taskDef.json > taskDef.yaml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment