21

How can I change the instance type of an existing Elastic Beanstalk application?

Currently I am changing it in the web interface: enter image description here

I tried changing it with the command line tool: eb setenv InstanceType=t2.medium

It didn't throw an error, but also didn't change the instance type.

ustroetz
  • 5,802
  • 16
  • 47
  • 74

3 Answers3

31

The setenv command is for changing Environment Variables. Hence the command you tried is bash equivalent of:

export InstanceType=t2.medium

And doesnt really do anything for your beanstalk environment.

You can create an environment using the -i option during create

eb create -i t2.micro

Or, you can use eb config to edit a currently running environment. This will open up a text editor. Look for the section that looks like:

aws:autoscaling:launchconfiguration:
    IamInstanceProfile: aws-elasticbeanstalk-ec2-role
    EC2KeyName: aws
    InstanceType: t1.micro

And edit the t1.micro to t2.micro. (save and quit)


But just to make your life easier, you can save the below as .elasticbeanstalk/saved_configs/default.cfg.yml and the CLI will use all these settings on all future creates.

AWSConfigurationTemplateVersion: 1.1.0.0
OptionSettings:
  aws:elb:loadbalancer:
    CrossZone: true
  aws:elasticbeanstalk:command:
    BatchSize: '30'
    BatchSizeType: Percentage
  aws:autoscaling:launchconfiguration:
    IamInstanceProfile: aws-elasticbeanstalk-ec2-role
    EC2KeyName: aws
    InstanceType: t2.micro
  aws:elb:policies:
    ConnectionDrainingEnabled: true
  aws:autoscaling:updatepolicy:rollingupdate:
    RollingUpdateType: Health
    RollingUpdateEnabled: true
  aws:elb:healthcheck:
    Interval: '30'
Nick Humrich
  • 14,905
  • 8
  • 62
  • 85
  • Where in the documentation can I find the `-i` option for `eb create`? – ustroetz Apr 10 '15 at 07:23
  • 2
    There is always `eb create --help`. But if you really want a web doc: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-create.html – Nick Humrich Apr 10 '15 at 13:41
  • `eb config` seems to display the CloudFormation configuration and not EB – gileri Sep 17 '17 at 16:55
  • @eric elastic beanstalk uses cloudformation. So yes, the configuration of a EB enviroment, is essentially just a cloudformation template. – Nick Humrich Nov 27 '17 at 20:31
  • @NickHumrich Could you please help with an off-topic question.. is it possible to define cloudformation capabilities (like CAPABILITY_NAMED_IAM) in ebextensions configs ? – akskap Aug 16 '19 at 13:39
6

More scriptable way:

aws elasticbeanstalk update-environment --environment-name "your-env-name" --option-settings "Namespace=aws:autoscaling:launchconfiguration,OptionName=InstanceType,Value=t2.micro"
arcusfelis
  • 61
  • 1
  • 2
  • 1
    This was very useful when our 1 chosen instance type suddenly wasn't available in all our subnets. The EB UI refused to show the configuration page to change it and the CLI was the only way to change instance type and recover that environment. – carl_kibler Mar 04 '22 at 19:31
6

The accepted solution didn't work for me in 2020.

As of today (26th, February 2020), in my .ebextensions/02_python.config I had to add the following under option_settings:

option_settings:
  # ...

  aws:ec2:instances:
    InstanceTypes: 'm5.large'

Reference: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.managing.as.html#environments-cfg-autoscaling-namespace.instances

Ruben Alves
  • 166
  • 4
  • 12