--- AWSTemplateFormatVersion: '2010-09-09' Parameters: ECSClusterName: Type: String Description: Enter ECS EC2 cluster name for installing the sample Memcached workload ECSNetworkMode: Type: String AllowedValues: - 'bridge' - 'host' Default: bridge Description: ECS Network Mode for the Task TaskRoleName: Type: String Description: Enter the ECS task role name to be created for Memcached ECS task definition ExecutionRoleName: Type: String Description: Enter the ECS execution role name to be created for Memcached ECS task definition Conditions: IsBridgeNetworking: !Equals [ !Ref ECSNetworkMode, 'bridge' ] Resources: MemcachedECSExecutionRole: Type: AWS::IAM::Role Properties: RoleName: !Ref ExecutionRoleName Description: Allows ECS container agent makes calls to the Amazon ECS API on your behalf. AssumeRolePolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Principal: Service: ecs-tasks.amazonaws.com Action: sts:AssumeRole ManagedPolicyArns: - arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy - arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy MemcachedECSTaskRole: Type: AWS::IAM::Role Properties: RoleName: !Ref TaskRoleName Description: Allows ECS tasks to call AWS services on your behalf. AssumeRolePolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Principal: Service: ecs-tasks.amazonaws.com Action: sts:AssumeRole ManagedPolicyArns: - arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy ECSMemcachedTaskDefinition: Type: 'AWS::ECS::TaskDefinition' DependsOn: - MemcachedECSExecutionRole - MemcachedECSTaskRole Properties: Family: !Sub 'memcached-prometheus-demo-${ECSClusterName}-EC2-${ECSNetworkMode}' TaskRoleArn: !Ref MemcachedECSTaskRole ExecutionRoleArn: !Ref MemcachedECSExecutionRole NetworkMode: !Ref ECSNetworkMode ContainerDefinitions: - Name: memcached-0 Image: memcached:1.6.7 Essential: true MountPoints: [] PortMappings: - Protocol: tcp ContainerPort: 11211 HostPort: 11211 DockerLabels: app: memcached Environment: [] Secrets: [] LogConfiguration: LogDriver: awslogs Options: awslogs-create-group: 'True' awslogs-group: "/ecs/ecs-memcached-prometheus-demo" awslogs-region: !Ref AWS::Region awslogs-stream-prefix: "memcached-tutorial" - Name: memcached-exporter-0 Image: prom/memcached-exporter:v0.7.0 Command: !If - IsBridgeNetworking - ["--memcached.address=memcached-0:11211"] - !Ref 'AWS::NoValue' Essential: false MountPoints: [] PortMappings: - Protocol: tcp ContainerPort: 9150 HostPort: 9150 Links: - !If - IsBridgeNetworking - "memcached-0" - !Ref 'AWS::NoValue' DockerLabels: job: prometheus-memcached app_x: memcached_exporter Environment: [] Secrets: [] LogConfiguration: LogDriver: awslogs Options: awslogs-create-group: 'True' awslogs-group: "/ecs/ecs-memcached-prometheus-demo" awslogs-region: !Ref AWS::Region awslogs-stream-prefix: "memcached-exporter-tutorial" RequiresCompatibilities: - EC2 Cpu: '256' Memory: '512' ECSMemcachedService: Type: AWS::ECS::Service DependsOn: ECSMemcachedTaskDefinition Properties: Cluster: !Ref ECSClusterName DesiredCount: 1 LaunchType: EC2 SchedulingStrategy: REPLICA ServiceName: "memcached-prometheus-cloudwatch-agent-tutorial-ec2" TaskDefinition: !Ref ECSMemcachedTaskDefinition