sample-with-aws-ssm/sample-with-aws-ssm.yaml [110:232]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      Cluster: !Ref JMSBridgeECSCluster
      LaunchType: FARGATE
      DeploymentConfiguration:
        MaximumPercent: 200
        MinimumHealthyPercent: 100
      DesiredCount: 1
      NetworkConfiguration:
        AwsvpcConfiguration:
          AssignPublicIp: ENABLED # to be able to download images from ECR
          SecurityGroups:
            - !Ref JMSBridgeSecurityGroup
          Subnets:
            - {'Fn::ImportValue': !Sub '${Stage}:JMS-BRIDGE:PublicSubnet1'}
            - {'Fn::ImportValue': !Sub '${Stage}:JMS-BRIDGE:PublicSubnet2'}
      TaskDefinition: !Ref JMSBridgeECSTaskDefinition

# Auto-scaling configuration

  ServiceAutoScalingRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
          - Effect: Allow
            Principal:
              Service: application-autoscaling.amazonaws.com
            Action: sts:AssumeRole
      Path: /
      Policies:
        - PolicyName: fargate-service-autoscaling
          PolicyDocument:
            Statement:
              - Effect: Allow
                Action:
                  - application-autoscaling:*
                  - cloudwatch:DescribeAlarms
                  - cloudwatch:PutMetricAlarm
                  - ecs:DescribeServices
                  - ecs:UpdateService
                Resource: '*'

  DefaultServiceScalingTarget:
    Type: AWS::ApplicationAutoScaling::ScalableTarget
    Properties:
      MinCapacity: 1
      MaxCapacity: 5
      ResourceId: !Sub service/${JMSBridgeECSCluster}/${JMSBridgeECSService.Name}
      RoleARN: !GetAtt ServiceAutoScalingRole.Arn
      ScalableDimension: ecs:service:DesiredCount
      ServiceNamespace: ecs

  DefaultServiceScaleOutPolicy:
    Type: AWS::ApplicationAutoScaling::ScalingPolicy
    Properties:
      PolicyName: ScaleOutPolicy
      PolicyType: StepScaling
      ScalingTargetId: !Ref DefaultServiceScalingTarget
      StepScalingPolicyConfiguration:
        AdjustmentType: ChangeInCapacity
        Cooldown: 60
        MetricAggregationType: Average
        StepAdjustments:
          - ScalingAdjustment: 1
            MetricIntervalLowerBound: 0

  DefaultServiceScaleInPolicy:
    Type: AWS::ApplicationAutoScaling::ScalingPolicy
    Properties:
      PolicyName: ScaleInPolicy
      PolicyType: StepScaling
      ScalingTargetId: !Ref DefaultServiceScalingTarget
      StepScalingPolicyConfiguration:
        AdjustmentType: ChangeInCapacity
        Cooldown: 60
        MetricAggregationType: Average
        StepAdjustments:
          - ScalingAdjustment: -1
            MetricIntervalUpperBound: 0

  DefaultServiceScaleOutAlarm:
    Type: AWS::CloudWatch::Alarm
    Properties:
      EvaluationPeriods: 3
      Statistic: Average
      TreatMissingData: notBreaching
      Threshold: 85
      AlarmDescription: Alarm to add capacity if CPU is high
      Period: 60
      AlarmActions:
        - !Ref DefaultServiceScaleOutPolicy
      Namespace: AWS/ECS
      Dimensions:
        - Name: ClusterName
          Value: !Ref JMSBridgeECSCluster
        - Name: ServiceName
          Value: !GetAtt JMSBridgeECSService.Name
      ComparisonOperator: GreaterThanThreshold
      MetricName: CPUUtilization

  DefaultServiceScaleInAlarm:
    Type: AWS::CloudWatch::Alarm
    Properties:
      EvaluationPeriods: 5
      Statistic: Average
      TreatMissingData: notBreaching
      Threshold: 40
      AlarmDescription: Alarm to reduce capacity if container CPU is low
      Period: 60
      AlarmActions:
        - !Ref DefaultServiceScaleInPolicy
      Namespace: AWS/ECS
      Dimensions:
        - Name: ClusterName
          Value: !Ref JMSBridgeECSCluster
        - Name: ServiceName
          Value: !GetAtt JMSBridgeECSService.Name
      ComparisonOperator: LessThanThreshold
      MetricName: CPUUtilization

Outputs:
  JMSBridgeECSClusterRef:
    Description: The name of the JMS bridge ECS cluster
    Value: !Ref JMSBridgeECSCluster
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



sample-with-env-variables/sample-with-env-variables.yaml [91:212]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      Cluster: !Ref JMSBridgeECSCluster
      LaunchType: FARGATE
      DeploymentConfiguration:
        MaximumPercent: 200
        MinimumHealthyPercent: 100
      DesiredCount: 1
      NetworkConfiguration:
        AwsvpcConfiguration:
          AssignPublicIp: ENABLED # to be able to download images from ECR
          SecurityGroups:
            - !Ref JMSBridgeSecurityGroup
          Subnets:
            - {'Fn::ImportValue': !Sub '${Stage}:JMS-BRIDGE:PublicSubnet1'}
            - {'Fn::ImportValue': !Sub '${Stage}:JMS-BRIDGE:PublicSubnet2'}
      TaskDefinition: !Ref JMSBridgeECSTaskDefinition

  # Auto-scaling configuration
  ServiceAutoScalingRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
          - Effect: Allow
            Principal:
              Service: application-autoscaling.amazonaws.com
            Action: sts:AssumeRole
      Path: /
      Policies:
        - PolicyName: fargate-service-autoscaling
          PolicyDocument:
            Statement:
              - Effect: Allow
                Action:
                  - application-autoscaling:*
                  - cloudwatch:DescribeAlarms
                  - cloudwatch:PutMetricAlarm
                  - ecs:DescribeServices
                  - ecs:UpdateService
                Resource: '*'

  DefaultServiceScalingTarget:
    Type: AWS::ApplicationAutoScaling::ScalableTarget
    Properties:
      MinCapacity: 1
      MaxCapacity: 5
      ResourceId: !Sub service/${JMSBridgeECSCluster}/${JMSBridgeECSService.Name}
      RoleARN: !GetAtt ServiceAutoScalingRole.Arn
      ScalableDimension: ecs:service:DesiredCount
      ServiceNamespace: ecs

  DefaultServiceScaleOutPolicy:
    Type: AWS::ApplicationAutoScaling::ScalingPolicy
    Properties:
      PolicyName: ScaleOutPolicy
      PolicyType: StepScaling
      ScalingTargetId: !Ref DefaultServiceScalingTarget
      StepScalingPolicyConfiguration:
        AdjustmentType: ChangeInCapacity
        Cooldown: 60
        MetricAggregationType: Average
        StepAdjustments:
          - ScalingAdjustment: 1
            MetricIntervalLowerBound: 0

  DefaultServiceScaleInPolicy:
    Type: AWS::ApplicationAutoScaling::ScalingPolicy
    Properties:
      PolicyName: ScaleInPolicy
      PolicyType: StepScaling
      ScalingTargetId: !Ref DefaultServiceScalingTarget
      StepScalingPolicyConfiguration:
        AdjustmentType: ChangeInCapacity
        Cooldown: 60
        MetricAggregationType: Average
        StepAdjustments:
          - ScalingAdjustment: -1
            MetricIntervalUpperBound: 0

  DefaultServiceScaleOutAlarm:
    Type: AWS::CloudWatch::Alarm
    Properties:
      EvaluationPeriods: 3
      Statistic: Average
      TreatMissingData: notBreaching
      Threshold: 85
      AlarmDescription: Alarm to add capacity if CPU is high
      Period: 60
      AlarmActions:
        - !Ref DefaultServiceScaleOutPolicy
      Namespace: AWS/ECS
      Dimensions:
        - Name: ClusterName
          Value: !Ref JMSBridgeECSCluster
        - Name: ServiceName
          Value: !GetAtt JMSBridgeECSService.Name
      ComparisonOperator: GreaterThanThreshold
      MetricName: CPUUtilization

  DefaultServiceScaleInAlarm:
    Type: AWS::CloudWatch::Alarm
    Properties:
      EvaluationPeriods: 5
      Statistic: Average
      TreatMissingData: notBreaching
      Threshold: 40
      AlarmDescription: Alarm to reduce capacity if container CPU is low
      Period: 60
      AlarmActions:
        - !Ref DefaultServiceScaleInPolicy
      Namespace: AWS/ECS
      Dimensions:
        - Name: ClusterName
          Value: !Ref JMSBridgeECSCluster
        - Name: ServiceName
          Value: !GetAtt JMSBridgeECSService.Name
      ComparisonOperator: LessThanThreshold
      MetricName: CPUUtilization

Outputs:
  JMSBridgeECSClusterRef:
    Description: The name of the JMS bridge ECS cluster
    Value: !Ref JMSBridgeECSCluster
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



