是否可以在Elastic Beanstalk中使用T2 Unlimited实例?

时间:2018-04-06 10:47:33

标签: amazon-web-services elastic-beanstalk

我正在尝试使用Elastic Beanstalk的T2 Unlimited实例。在实例启动后我不想配置它,所以我想知道是否有人知道EB配置是否完全可以吗?

4 个答案:

答案 0 :(得分:6)

我找到了解决方案。如果其他人遇到同样的问题,请将其发布在此处:

  1. 创建一个IAM策略,允许弹性beanstalk环境中的ec2实例修改实例信用规范并将其附加到弹性beanstalk ec2角色。
  2. {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Sid": "InstanceCreditPolicy",
                "Effect": "Allow",
                "Action": [
                    "ec2:ModifyInstanceCreditSpecification",
                    "ec2:DescribeInstanceCreditSpecifications"
                ],
                "Resource": "*"
            }
        ]
    }
    
    1. 创建eb扩展程序(.ebextensions/01-set-instance-credit-unlimited.config
    2. commands:
        set-instance-credit-unlimited:
          command: |
            aws ec2 modify-instance-credit-specification --region <your_region> --instance-credit-specification '[{"InstanceId": "'"$(wget -q -O - http://169.254.169.254/latest/meta-data/instance-id)"'","CpuCredits": "unlimited"}]'
      

答案 1 :(得分:1)

如果您正在使用解决方案堆栈 - “运行Node.js的64位Amazon Linux 2017.03 v4.1.1”,除了创建用户 steinim 描述的策略之外,您还需要使用这两个改为配置文件:

1)upgrade-awscli.config

commands: 
  modify-instance-credit-specification:
    command: "sudo pip install --upgrade awscli"

2)t2-unlimited-test.config

commands: 
  modify-instance-credit-specification:
    command: "aws ec2 modify-instance-credit-specification --region us-west-2 --instance-credit-specification '[{\"InstanceId\": \"'\"$(wget -q -O - http://169.254.169.254/latest/meta-data/instance-id)\"'\",\"CpuCredits\": \"unlimited\"}]'"

答案 2 :(得分:0)

对于正在寻找PowerShell版本的@steinim答案的任何人,就是这样:

$InstanceID = wget http://169.254.169.254/latest/meta-data/instance-id -UseBasicParsing
$Credit = New-Object -TypeName Amazon.EC2.Model.InstanceCreditSpecificationRequest
$Credit.InstanceId = $InstanceID
$Credit.CpuCredits = "unlimited"
Edit-EC2InstanceCreditSpecification -InstanceCreditSpecification $Credit

因此,您的.ebextensions/01-set-instance-credit-unlimited.config文件将如下所示:

files:
  "c:/scripts/Enable-T2Unlimited.ps1":
    content: |
      Import-Module AWSPowerShell
      $InstanceID = wget http://169.254.169.254/latest/meta-data/instance-id -UseBasicParsing
      $Credit = New-Object -TypeName Amazon.EC2.Model.InstanceCreditSpecificationRequest
      $Credit.InstanceId = $InstanceID
      $Credit.CpuCredits = "unlimited"
      Edit-EC2InstanceCreditSpecification -InstanceCreditSpecification $Credit
commands:
  01_Enable_T2_Unlimited:
    command: powershell c:\\scripts\\Enable-T2Unlimited.ps1
    ignoreErrors: false
    waitAfterCompletion: 0

答案 3 :(得分:0)

我一直在寻找答案,但是我注意到t3 EC2实例默认情况下启用了无限制模式[1],并且比t2实例便宜。因此,如果您在EB env中使用t3实例类型,那就很好了,不需要其他EB env配置。

[1] https://aws.amazon.com/blogs/aws/new-t3-instances-burstable-cost-effective-performance/https://aws.amazon.com/ec2/instance-types/t3/