Skip to content

Instantly share code, notes, and snippets.

@robbyt
Last active January 6, 2016 04:56
Show Gist options
  • Save robbyt/0a65e7552b85bcfab258 to your computer and use it in GitHub Desktop.
Save robbyt/0a65e7552b85bcfab258 to your computer and use it in GitHub Desktop.
Update the ECS agent from ElasticBeanstalk
{
"commands": {
"01ecsupdate": {"command": ".os-config/scripts/ecs-agent-update.sh"},
"99completed": {"command": "logger -t update-ecs-agent completed"}
}
}
#!/bin/bash
# install this to .os-config/scripts/ecs-agent-update.sh
ECS_INIT_VER=`curl -sS http://localhost:51678/v1/metadata | jq -r .Version`
echo $ECS_INIT_VER | grep '1.6.0'
if [ $? -eq 0 ]
then
echo "Found outdated version of ECS agent"
NEEDS_UPDATE=1
else
echo "ECS agent is newer than 1.6.0"
NEEDS_UPDATE=0
fi
if [ $NEEDS_UPDATE -eq 1 ]
then
EB_CONFIG_ECS_CLUSTER=`/opt/elasticbeanstalk/bin/get-config container -k ecs_cluster`
CONTAINER_ID=`curl -sS http://localhost:51678/v1/metadata | jq -r .ContainerInstanceArn`
echo "Starting ECS agent update..."
aws ecs update-container-agent --cluster $EB_CONFIG_ECS_CLUSTER --container-instance $CONTAINER_ID
echo "ECS agent update has started, goodbye."
exit 0
else
echo "Not updating ECS agent, goodbye."
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment