客户可能希望部署 AppStream 2.0 队列,并可选择按容量和非高峰时间计划进行扩展。在一天中的任何时间为用户提供对 AppStream 实例的访问权限。
有两种类型的缩放扩缩, 计划扩缩和容量扩缩。 这一系列解决方案提供了配置两种扩缩类型的选项,它们并不相互排斥,可以一起使用以获得最大的灵活性和成本控制。计划扩缩是通过可扩缩目标资源中的配置选项实现的。并且在这个表格中使用cron格式设置相关时间点来改变队列容量。容量扩展由 CloudWatch 指标上设置的警报驱动。这些警报与扩展策略(Scale-In 和 Scale-Out)交互,然后根据策略中配置的扩缩规则对可扩缩目标队列容量进行更改。
图 1. 计划扩缩
图 2. 容量扩缩
解决方案组件
所提供的解决方案旨在部署 AppStream 堆栈和支持资源,以拥有将根据提供的变量扩展的正在运行的堆栈和队列。使用了以下 AWS 资源:
- IAM 角色(分配给 AppStream 队列实例)
- 安全组(分配给 AppStream 队列实例)
- 应用流堆栈
- AppStream 队列
- 应用程序自动缩放可扩展目标
- 应用程序自动扩展扩展策略
- 缩减策略(定义缩减容量变化)
- 横向扩展策略(定义横向扩展容量变化)
- CloudWatch 警报
- 缩减警报(触发缩减策略)
- 横向扩展警报(触发横向扩展策略)
- 容量警报(用于监控通知)
CloudFormation 解决方案
下列是一个AppStream堆栈部署的例子
Stack:
Type: AWS::AppStream::Stack
Properties :
ApplicationSettings :
Enabled: True
SettingsGroup: !Sub "${AWS::StackName}"
Description : !Sub "${AWS::StackName} Appstream Stack"
DisplayName : !Sub "${AWS::StackName}"
Name : !Sub "${AWS::StackName}"
StorageConnectors :
- ConnectorType: HOMEFOLDERS
Tags:
- Key: Name
Value: !Sub "${AWS::StackName}"
UserSettings :
- Action: CLIPBOARD_COPY_FROM_LOCAL_DEVICE
Permission: !If [ EnableClipboardFromCondition, "ENABLED", "DISABLED"]
- Action: CLIPBOARD_COPY_TO_LOCAL_DEVICE
Permission: !If [ EnableClipboardToCondition, "ENABLED", "DISABLED"]
- Action: FILE_DOWNLOAD
Permission: !If [ EnableFileDownloadCondition, "ENABLED", "DISABLED"]
- Action: FILE_UPLOAD
Permission: !If [ EnableFileUploadCondition, "ENABLED", "DISABLED"]
- Action: PRINTING_TO_LOCAL_DEVICE
Permission: !If [ EnablePrintingCondition, "ENABLED", "DISABLED"]
下列是一个AppStream队列部署的例子
Fleet:
Type: AWS::AppStream::Fleet
Properties:
ComputeCapacity:
DesiredInstances: !Ref DesiredInstances
Description: !Sub "${AWS::StackName} Appstream Fleet"
DisconnectTimeoutInSeconds : !Ref DisconnectTimeout
DisplayName: !Sub "${AWS::StackName}"
EnableDefaultInternetAccess: False
FleetType: !Ref FleetType
ImageArn : !Ref ImageArn
IamRoleArn: !GetAtt IamRole.Arn
InstanceType: !Ref InstanceType
MaxUserDurationInSeconds: !Ref MaxUserDuration
Name: !Sub "${AWS::StackName}"
Tags:
- Key: Name
Value: !Sub "${AWS::StackName}"
VpcConfig :
SecurityGroupIds:
- !Ref SecurityGroup
SubnetIds: !Ref Subnets
下列是一个AppStream队列计划扩缩部署的例子
ScalableTarget:
DependsOn:
- Fleet
Type: AWS::ApplicationAutoScaling::ScalableTarget
Properties:
MaxCapacity: !Ref MaxInstances
MinCapacity: !Ref MinInstances
ResourceId: !Sub "fleet/${AWS::StackName}"
RoleARN: !Sub "arn:aws:iam::${AWS::AccountId}:role/aws-service-role/appstream.application-autoscaling.amazonaws.com/AWSServiceRoleForApplicationAutoScaling_AppStreamFleet"
ScalableDimension: appstream:fleet:DesiredCapacity
ServiceNamespace: appstream
ScheduledActions:
-
Schedule: !Ref ScaleInSchedule
ScheduledActionName: !Sub "${AWS::StackName}-scalein-schedule"
ScalableTargetAction:
MinCapacity: !Ref OffPeakMinInstances
MaxCapacity: !Ref OffPeakMaxInstances
Timezone: !Ref Timezone
-
Schedule: !Ref ScaleOutSchedule
ScheduledActionName: !Sub "${AWS::StackName}-scaleout-schedule"
ScalableTargetAction:
MinCapacity: !Ref MinInstances
MaxCapacity: !Ref MaxInstances
Timezone: !Ref Timezone
SuspendedState:
DynamicScalingInSuspended: false
DynamicScalingOutSuspended: false
ScheduledScalingSuspended: false
参数名称 |
说明 |
默认值 |
DesiredInstances |
队列的初始所需实例数量 |
n/a |
MinInstances |
高峰时段的最小队列规模 |
n/a |
MaxInstances |
高峰时段的最大队列规模 |
n/a |
OffPeakMinInstances |
非高峰时段的最小队列规模 |
n/a |
OffPeakMaxInstances |
非高峰时段的最大队列规模 |
n/a |
AlarmArn |
现有的 SNS Arn用于容量通知 |
n/a |
CapacityAlarmThreshold |
触发警报的容量阈值 |
80 |
ScaleInSchedule |
按计划缩放 默认值以cron 格式 |
cron(0 18 ? * MON-FRI *) |
ScaleOutSchedule |
按计划扩展默认值以cron 格式 |
cron(0 8 ? * MON-FRI *) |
下列是一个AppStream队列容量扩缩部署的例子
ScalableTarget:
DependsOn:
- Fleet
Type: AWS::ApplicationAutoScaling::ScalableTarget
Properties:
MaxCapacity: !Ref MaxInstances
MinCapacity: !Ref MinInstances
ResourceId: !Sub "fleet/${AWS::StackName}"
RoleARN: !Sub "arn:aws:iam::${AWS::AccountId}:role/aws-service-role/appstream.application-autoscaling.amazonaws.com/AWSServiceRoleForApplicationAutoScaling_AppStreamFleet"
ScalableDimension: appstream:fleet:DesiredCapacity
ServiceNamespace: appstream
SuspendedState:
DynamicScalingInSuspended: false
DynamicScalingOutSuspended: false
ScheduledScalingSuspended: false
ScalingOutPolicy:
DependsOn:
- ScalableTarget
Type: AWS::ApplicationAutoScaling::ScalingPolicy
Properties:
PolicyName: !Sub "${AWS::StackName}-scale-out"
PolicyType: StepScaling
ScalingTargetId: !Ref ScalableTarget
StepScalingPolicyConfiguration:
AdjustmentType: !Ref ScaleOutAdjustmentType
Cooldown: 120
MetricAggregationType: Average
StepAdjustments:
- MetricIntervalLowerBound : 0
ScalingAdjustment : !Ref ScaleOutAdjustmentValue
ScalingInPolicy:
DependsOn:
- ScalableTarget
Type: AWS::ApplicationAutoScaling::ScalingPolicy
Properties:
PolicyName: !Sub "${AWS::StackName}-scale-in"
PolicyType: StepScaling
ScalingTargetId: !Ref ScalableTarget
StepScalingPolicyConfiguration:
AdjustmentType: !Ref ScaleInAdjustmentType
Cooldown: 120
MetricAggregationType: Average
StepAdjustments:
- MetricIntervalUpperBound : 0
MetricIntervalLowerBound : -5
ScalingAdjustment : !Ref ScaleInAdjustmentValue
- MetricIntervalUpperBound : -5
ScalingAdjustment : !Ref ScaleInAdjustmentValue
ScaleOutCapacityAlarm:
DependsOn:
- ScalingOutPolicy
Type: AWS::CloudWatch::Alarm
Properties:
ActionsEnabled: true
AlarmActions:
- !Ref ScalingOutPolicy
AlarmDescription: String
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: Fleet
Value: !Sub "${AWS::StackName}"
EvaluationPeriods: 3
MetricName: CapacityUtilization
Namespace: AWS/AppStream
Period: 60
Statistic: Average
Threshold: !Ref ScaleOutThreshold
ScaleInCapacityAlarm:
DependsOn:
- ScalingInPolicy
Type: AWS::CloudWatch::Alarm
Properties:
ActionsEnabled: true
AlarmActions:
- !Ref ScalingInPolicy
AlarmDescription: String
ComparisonOperator: LessThanThreshold
Dimensions:
- Name: Fleet
Value: !Sub "${AWS::StackName}"
EvaluationPeriods: 5
MetricName: CapacityUtilization
Namespace: AWS/AppStream
Period: 120
Statistic: Average
Threshold: !Ref ScaleInThreshold
CapacityAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
ActionsEnabled: true
AlarmActions:
- Fn::If:
- HasAlarmCondition
- !Ref AlarmArn
- !Ref AWS::NoValue
OKActions:
- Fn::If:
- HasAlarmCondition
- !Ref AlarmArn
- !Ref AWS::NoValue
AlarmDescription: String
ComparisonOperator: GreaterThanThreshold
Dimensions:
- Name: Fleet
Value: !Ref Fleet
EvaluationPeriods: 5
MetricName: CapacityUtilization
Namespace: AWS/AppStream
Period: 120
Statistic: Average
Threshold: !Ref CapacityAlarmThreshold
参数名称 |
说明 |
默认值 |
DesiredInstances |
队列的初始所需实例数量 |
n/a |
MinInstances |
高峰时段的最小队列规模 |
n/a |
MaxInstances |
高峰时段的最大队列规模 |
n/a |
AlarmArn |
现有的 SNS Arn用于容量通知 |
n/a |
CapacityAlarmThreshold |
触发警报的容量阈值 |
80 |
ScaleOutAdjustmentType |
向外扩展时的调整更改类型 |
[PercentChangeInCapacity, ChangeInCapacity] |
ScaleOutAdjustmentValue |
调整值与类型结合使用 |
1 |
ScaleOutThreshold |
触发横向扩展的阈值百分比 |
60 |
ScaleInAdjustmentType |
缩放时的调整更改类型 |
[PercentChangeInCapacity, ChangeInCapacity] |
ScaleInAdjustmentValue |
调整值与类型结合使用 |
1 |
ScaleInThreshold |
触发缩放的阈值百分比 |
40 |
本篇作者