Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ziggythehamster/0befb3b3fda2f2ac9f568225a4b23114 to your computer and use it in GitHub Desktop.
Save ziggythehamster/0befb3b3fda2f2ac9f568225a4b23114 to your computer and use it in GitHub Desktop.
Amazon SSM Docker Inventory Collectors
#!/bin/sh
#
# This script will make an API call to Docker and use JQ to output a document that SSM can
# pick up as custom inventory.
# TODO: mounts
curl --unix-socket /var/run/docker.sock -H "Content-Type: application/json" "http:/v1.24/containers/json" | jq '{ SchemaVersion: "1.0", TypeName: "Custom:DockerContainers", Content: [.[] | { Id: .Id, Name: .Names[0] | ltrimstr("/"), State: .State, Status: .Status, Created: .Created | todateiso8601, BoundPorts: .Ports | [ .[] | select(.PublicPort != null) | [.IP, (.PublicPort | tostring), (.PrivatePort | tostring)] | join(":") ] | join(", "), NetworkMode: .HostConfig.NetworkMode, ECSTaskARN: .Labels["com.amazonaws.ecs.task-arn"], ECSTaskFamily: .Labels["com.amazonaws.ecs.task-definition-family"], ECSTaskVersion: .Labels["com.amazonaws.ecs.task-definition-version"] }] }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment