--- AWSTemplateFormatVersion: 2010-09-09 Parameters: Subnet3: Type: String Subnet4: Type: String PrivateALB: Type: String Cluster: Type: String ExecutionRole: Type: String DesiredCount: Type: Number Default: 1 LaunchType: Type: String Default: Fargate AllowedValues: - Fargate - EC2 TargetGroup001: Type: String SecurityGroup: Type: String Conditions: Fargate: !Equals [ !Ref LaunchType, "Fargate" ] EC2: !Equals [ !Ref LaunchType, "EC2" ] Resources: LogGroup: Type: AWS::Logs::LogGroup Properties: LogGroupName: !Sub /ecs/${AWS::StackName} FargateService: Type: AWS::ECS::Service Condition: Fargate Properties: Cluster: !Ref Cluster DesiredCount: !Ref DesiredCount HealthCheckGracePeriodSeconds: 60 TaskDefinition: !Ref TaskDefinition LaunchType: FARGATE NetworkConfiguration: AwsvpcConfiguration: AssignPublicIp: ENABLED SecurityGroups: - !Ref SecurityGroup Subnets: - !Ref Subnet3 - !Ref Subnet4 LoadBalancers: - ContainerName: name ContainerPort: 8082 TargetGroupArn: !Ref TargetGroup001 EC2Service: Type: AWS::ECS::Service Condition: EC2 Properties: Cluster: !Ref Cluster DesiredCount: !Ref DesiredCount TaskDefinition: !Ref TaskDefinition LaunchType: EC2 LoadBalancers: - ContainerName: name ContainerPort: 8082 TargetGroupArn: !Ref TargetGroup001 TaskDefinition: Type: AWS::ECS::TaskDefinition Properties: Family: !Sub ${AWS::StackName}-name RequiresCompatibilities: - !If [ Fargate, "FARGATE", "EC2" ] Memory: 1GB Cpu: 256 NetworkMode: !If [ Fargate, "awsvpc", "bridge" ] ExecutionRoleArn: !Ref ExecutionRole ContainerDefinitions: - Name: name Image: arungupta/name Essential: true Memory: 500 Cpu: 10 PortMappings: - ContainerPort: 8082 LogConfiguration: LogDriver: awslogs Options: awslogs-region: !Ref AWS::Region awslogs-group: !Ref LogGroup awslogs-stream-prefix: !Ref AWS::StackName Outputs: Service: Value: !If [ Fargate, !Ref FargateService, !Ref EC2Service ]