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

问题描述 投票:5回答:3

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

amazon-web-services elastic-beanstalk
3个回答
6
投票

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

  1. 创建一个IAM策略,允许弹性beanstalk环境中的ec2实例修改实例信用规范并将其附加到弹性beanstalk ec2角色。
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "InstanceCreditPolicy",
            "Effect": "Allow",
            "Action": [
                "ec2:ModifyInstanceCreditSpecification",
                "ec2:DescribeInstanceCreditSpecifications"
            ],
            "Resource": "*"
        }
    ]
}
  1. 创建一个eb扩展名(.ebextensions/01-set-instance-credit-unlimited.config
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
投票

如果您正在使用解决方案堆栈 - “运行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\"}]'"

0
投票

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

$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
© www.soinside.com 2019 - 2024. All rights reserved.