Created
April 9, 2018 16:12
-
-
Save ncloudsbconnelly/70d839a873e93c6f9bfef89d4c1d42bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
taskdefinition: | |
Type: "AWS::ECS::TaskDefinition" | |
Properties: | |
ContainerDefinitions: | |
- | |
Name: "datadog-agent" | |
MountPoints: | |
- | |
SourceVolume: "docker_sock" | |
ContainerPath: "/var/run/docker.sock" | |
- | |
SourceVolume: "cgroup" | |
ContainerPath: "/host/sys/fs/cgroup" | |
- | |
SourceVolume: "proc" | |
ContainerPath: "/host/proc" | |
Image: "datadog/agent:latest" | |
Cpu: "10" | |
Memory: "256" | |
Essential: "true" | |
Environment: | |
- | |
Name: DD_API_KEY | |
Value: !Ref DDAPIKEY | |
- | |
Name: SD_BACKEND | |
Value: docker | |
Volumes: | |
- | |
Host: | |
SourcePath: "/var/run/docker.sock" | |
Name: "docker_sock" | |
- | |
Host: | |
SourcePath: "/proc/" | |
Name: "proc" | |
- | |
Host: | |
SourcePath: "/cgroup/" | |
Name: "cgroup" | |
Family: datadog-agent-task | |
UserData: | |
Fn::Base64: !Sub | | |
#!/bin/bash | |
yum install -y python-pip | |
pip-2.6 install awscli | |
yum install -y aws-cfn-bootstrap aws-cli jq | |
vgextend docker /dev/xvdcy | |
lvextend -L+100G /dev/docker/docker-pool | |
/opt/aws/bin/cfn-init -v --region ${AWS::Region} --stack ${AWS::StackName} --resource ECSLaunchConfiguration | |
/opt/aws/bin/cfn-signal -e 0 --region ${AWS::Region} --stack ${AWS::StackName} --resource ECSAutoScalingGroup | |
cluster=${ECSCluster} | |
task_def="datadog-agent-task" | |
touch /etc/ecs/ecs.config | |
echo ECS_CLUSTER=$cluster >> /etc/ecs/ecs.config | |
echo ECS_ENABLE_CONTAINER_METADATA=true >> /etc/ecs/ecs.config | |
start ecs | |
instance_arn=$( curl -f http://localhost:51678/v1/metadata | jq -re .ContainerInstanceArn | awk -F/ '{print $NF}') | |
az=$(curl -f http://169.254.169.254/latest/meta-data/placement/availability-zone) | |
region=$(curl http://169.254.169.254/latest/dynamic/instance-identity/document|grep region|awk -F\" '{print $4}') | |
echo "cluster=$cluster az=$az region=$region aws ecs start-task --cluster \ | |
$cluster --task-definition $task_def --container-instances $instance_arn --region $region" >> /etc/rc.local |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment