Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use T2 Unlimited instances in Elastic Beanstalk?

I am trying to use T2 Unlimited instances with Elastic Beanstalk. I don't want to configure this after the instances have launched, so I am wondering if anyone knows if it's at all possible with EB configuration?

like image 930
Stein Inge Morisbak Avatar asked Apr 06 '18 10:04

Stein Inge Morisbak


2 Answers

I found a solution. Posting it here in case others run into the same issue:

  1. Create an IAM policy that allows the ec2 instances in your elastic beanstalk environment to modify instance credit specification and attach it to your elastic beanstalk ec2 role.
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "InstanceCreditPolicy",
            "Effect": "Allow",
            "Action": [
                "ec2:ModifyInstanceCreditSpecification",
                "ec2:DescribeInstanceCreditSpecifications"
            ],
            "Resource": "*"
        }
    ]
}
  1. Create an eb extension (.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"}]'
like image 171
Stein Inge Morisbak Avatar answered Sep 30 '22 18:09

Stein Inge Morisbak


In case you're using solution stack- "64bit Amazon Linux 2017.03 v4.1.1 running Node.js", in addition to creating the policy described by user steinim, you need to use these two config files instead:

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\"}]'"
like image 21
Deepak Mishra Avatar answered Sep 30 '22 16:09

Deepak Mishra