首页 > 解决方案 > AWS CodeDeploy 与 Spot 和按需实例混合的 Autoscaling 启动模板

问题描述

可以将自动缩放组配置为使用启动模板而不是启动配置。我想使用它,因为当我使用启动配置配置自动缩放组时,我无法设置混合实例策略(按需 + 现场实例)。

我已经使用这样的配置创建了启动模板(名称'test'):

    AMI Ubuntu 16, 
    some security groups and IAM Role with EC2, AutoScaling and CodeDeploy full access 
    and all other settings in default *Not specified* state.

    Launch Template ID lt-0e1111
    Default Version Number 1
    Launch Template Name test
    Owner arn:aws:iam::11111111:user/itsp
    Version  1 (Default)
    Name  test
    Created by arn:aws:iam::179961111910:user/itsp
    Description Not specified
    Date Created February 8, 2019 at 12:47:54 AM UTC+3
    AMI ID ami-0bf1924ed30c48a6a
    Availability Zone Not specified
    Security Groups Not specified
    Instance Type t2.nano
    Key pair name itsp
    Security Group Ids sg-07e746cf0e4935b84,sg-0a45f7e6ac321614d,sg-27bf6d4b

    Advanced Details:
    Purchasing option Not specified
    Spot request type Not specified
    Spot interruption behavior Not specified
    IAM Instance Profile Not specified
    Stop - Hibernate behavior Not specified
    Monitoring Not specified
    EBS-optimized instance Not specified
    Tenancy Host ID Not specified
    RAM Disk ID Not specified
    User Data Not specified
    Elastic Inference Accelerator Not specified
    Maximum Spot price Not specified
    Spot expiry date -
    Spot block duration Not specified
    Shutdown behavior Not specified
    Termination Protection Not specified
    Placement Group Name Not specified
    Tenancy Not specified
    Tenancy Affinity Not specified
    Kernel ID Not specified
    Elastic Graphics Not specified

然后我正在使用该启动模板创建一个 AutoScaling 组。这是我的自动缩放组配置:

Launch Template test
Launch Template Version 1
Launch Template Description -
Instance Types -
Spot Diversity 0
Optional On-Demand Base 0
On-Demand Percentage 0%
Desired Capacity 1 
Min 1 
Max 1
Availability Zone(s) eu-central-1a
Subnet(s) subnet-53075e38
Classic Load Balancers -
Target Groups -
Health Check Type EC2
Health Check Grace Period 300
Instance Protection - 
Termination Policies Default
Suspended Processes -
Placement Groups -
Default Cooldown 300
Enabled Metrics -
Creation Time Fri Feb 08 00:50:16 GMT+300 2019
Service-Linked Role arn:aws:iam::11111111111:role/aws-service-role/autoscaling.amazonaws.com/AWSServiceRoleForAutoScaling

当我选择时,似乎设置了这样的配置

*Fleet Composition - Adhere to the launch template
The launch template determines the instance type and purchase option (On-Demand or Spot).* 

选项和我的 lauch 模板配置如上所述。

所以我的自动缩放组中没有斑点。

然后我用这样的配置在其中配置一个 CodeDeploy 应用程序“Application”和 DeploymentGroup“DG_TEST”:

Deployment type Blue/green
Service role ARN arn:aws:iam::11111111111111:role/CodeDeployRole
Deployment configuration CodeDeployDefault.AllAtOnce
Rollback enabled -
Environment configuration: Amazon EC2 Auto Scaling groups -> Name 'test'

好的,在设置完所有内容后,我将 Autoscaling 组中的所需实例计数设置为 1,并在我的“测试”组中生成新的按需实例。

我现在开始使用 AWS CLI 命令进行蓝绿部署:

aws deploy create-deployment --application-name Application --s3-location bucket=codedeploybucket,key=application,bundleType=zip --deployment-group-name DG_TEST

我可以看到我的绿色舰队中出现了具有相同 lauch 模板的新自动缩放组。

所以我们只是检查了我们所有的服务是否按预期工作。


现在我想稍微调整一下我的自动缩放组配置,以便在其中混合按需和现场实例:

Fleet Composition - Combine purchase options and instances
Choose a mix of On-Demand Instances and Spot Instances and multiple instance types. Spot Instances are automatically launched at the lowest price available.
Instance Types:
t2.nano (1vCPUs, 0.5GiB)
t2.small (1vCPUs, 2GiB)
t2.micro (1vCPUs, 1GiB)
Maximum Spot Price - Use default (recommended)
Spot Allocation Strategy - Diversify Spot Instances across your 2 lowest priced instance types per Availability Zone
Optional On-Demand Base - Designate the first 0 instances as On-Demand
On-Demand Percentage 50% On-Demand and 50% Spot
Desired Capacity 1
Min 1
Max 1

我保存它并尝试相同的 AWS CLI 命令

aws deploy create-deployment --application-name Application --s3-location bucket=codedeploybucket,key=application,bundleType=zip --deployment-group-name DG_TEST

现在我的部署失败了,并出现了这样的评论:

The following validation error occurred: Valid requests must contain either LaunchTemplate, LaunchConfigurationName, InstanceId or MixedInstancesPolicy parameter. (Service: AmazonAutoScaling; Status Code: 400; Error Code: ValidationError; Request ID: 11111114-2b2b-11e9-93b7-11111111111)

另一个奇怪的事情是,如果我将 Launch Templae 配置为仅使用点:

Launch Template ID lt-00dc4c187d1111159
Default Version Number   1
Launch Template Name test2
Owner
arn:aws:iam::179961111910:user/itsp
Version     1 (Default)
Name  test2
Created by  arn:aws:iam::179961111910:user/itsp
Description Not specified
Date Created    February 8, 2019 at 1:14:13 AM UTC+3
AMI ID    ami-0bf1924ed30c48a6a
Availability Zone    Not specified
Security Groups   Not specified
Instance Type    t2.micro
Key pair name    itsp
Security Group Ids    sg-0a45f7e6ac321614d,sg-07e746cf0e4935b84,sg-27bf6d4b

Advanced details
Purchasing option    spot
Spot request type    one-time
Spot interruption behavior    Not specified
IAM Instance Profile    CodeDeployRole (arn:aws:iam::1111111111:instance-profile/CodeDeployRole)
Stop - Hibernate behavior    Not specified
Monitoring    Not specified
EBS-optimized instance   Not specified
Tenancy Host ID    Not specified
RAM Disk ID    Not specified
User Data    Not specified
Elastic Inference Accelerator    Not specified
Maximum Spot price    Not specified
Spot expiry date    -
Spot block duration    Not specified
Shutdown behavior    Not specified
Termination Protection    Not specified
Placement Group Name    Not specified
Tenancy    Not specified
Tenancy Affinity    Not specified
Kernel ID    Not specified
Elastic Graphics    Not specified

并在我的自动缩放组中使用该选项:

*Fleet Composition - Adhere to the launch template
    The launch template determines the instance type and purchase option (On-Demand or Spot).* 

然后在相同的部署命令之后,我在 CodeDeploy 中收到另一个错误(部署失败的原因):

The IAM role arn:aws:iam::179966034910:role/CodeDeployRole does not give you permission to perform operations in the following AWS service: AmazonAutoScaling. Contact your AWS administrator if you need help. If you are an AWS administrator, you can grant permissions to your users or groups by creating IAM policies.

绝对不是这种情况,因为我在 CodeDeploy 中的角色拥有完整的 EC2、Autoscaling 和 CodeDeploy 访问权限。


我做错了什么还是错误?如何使用启动模板使用 codedeploy 配置混合自动缩放组(按需+现货实例)?提前致谢!

标签: amazon-web-servicesamazon-ec2aws-cliautoscalingaws-code-deploy

解决方案


在使用CodeDeployLaunchTemplates时,我遇到了类似的问题。
看起来 CodeDeploy 仍然不支持 LaunchTemplates。

我们必须坚持LaunchConfigurations。它们仍然不支持版本控制,但在大多数情况下,它们几乎相同:/

在将 LaunchConfigurations 迁移到 LaunchTemplates 时,我找不到 AWS 在哪里记录了这个小不兼容问题……但可以在此处找到更多信息。

纯粹的!


推荐阅读