AWSTemplateFormatVersion: 2010-09-09 Description: Creating Webapp service Parameters: ECSCluster: Type: String VPC: Type: String PublicSubnet1: Type: String PublicSubnet2: Type: String PublicALB: Type: String ALBPrivateCNAME: Type: String SecurityGroup: Type: String Resources: taskdefinition: Type: 'AWS::ECS::TaskDefinition' Properties: RequiresCompatibilities: - "FARGATE" Cpu: 256 Memory: 1GB ContainerDefinitions: - Name: webapp Cpu: 10 Environment: - Name: NAME_SERVICE_HOST Value: !Ref ALBPrivateCNAME - Name: NAME_SERVICE_PORT Value: "8082" - Name: NAME_SERVICE_PATH Value: /resources/names - Name: GREETING_SERVICE_HOST Value: !Ref ALBPrivateCNAME - Name: GREETING_SERVICE_PORT Value: "8081" - Name: GREETING_SERVICE_PATH Value: /resources/greeting Image: arungupta/webapp Memory: 500 PortMappings: - ContainerPort: 8080 # LogConfiguration: # LogDriver: awslogs # Options: # awslogs-group: webapp # awslogs-region: !Ref AWS::Region # awslogs-stream-prefix: webapp NetworkMode: awsvpc # ExecutionRoleArn: arn:aws:iam::016309051001:role/ecsTaskExecutionRole # TaskRoleArn: arn:aws:iam::016309051001:role/ecsTaskExecutionRole service: Type: 'AWS::ECS::Service' DependsOn: listener Properties: Cluster: !Ref ECSCluster DesiredCount: 1 HealthCheckGracePeriodSeconds: 60 LaunchType: FARGATE LoadBalancers: - TargetGroupArn: !Ref targetgroup002 ContainerPort: 8080 ContainerName: webapp NetworkConfiguration: AwsvpcConfiguration: AssignPublicIp: ENABLED SecurityGroups: - !Ref SecurityGroup Subnets: - !Ref PublicSubnet1 - !Ref PublicSubnet2 TaskDefinition: !Ref taskdefinition ServiceName: webapp targetgroup002: Type: AWS::ElasticLoadBalancingV2::TargetGroup Properties: HealthCheckIntervalSeconds: 60 UnhealthyThresholdCount: 10 HealthCheckPath: / Name: webapp Port: 8080 Protocol: HTTP VpcId: !Ref VPC TargetType: ip listener: Type: AWS::ElasticLoadBalancingV2::Listener Properties: DefaultActions: - Type: forward TargetGroupArn: Ref: targetgroup002 LoadBalancerArn: !Ref PublicALB Port: 80 Protocol: HTTP