

# Spot Instance support for your Elastic Beanstalk environment
Spot Instance support

This topic describes the configuration options that are available for you to manage the capacity and load balancing of Spot Instances in your Elastic Beanstalk environment. It also provides details and examples for the methods you can use to configure these options. You can use the [Elastic Beanstalk console](environments-cfg-autoscaling-configuration-approaches.md#environments-cfg-autoscaling-console), [namespace configuration options](environments-cfg-autoscaling-configuration-approaches.md#environments-cfg-autoscaling-namespace), the [AWS CLI](environments-cfg-autoscaling-configuration-approaches.md#environments-cfg-autoscaling-aws-cli), or the [EB CLI](environments-cfg-autoscaling-configuration-approaches.md#environments-cfg-autoscaling-ebcli) to manage the configuration options.

**Minimize Spot instance interruptions with Capacity Rebalancing**  
To help minimize the impact of Spot Instance interruptions to your application, you can enable the Capacity Rebalancing option included with Amazon EC2 Auto Scaling.

**Important**  
Demand for Spot Instances can vary significantly from moment to moment, and the availability of Spot Instances can also vary significantly depending on how many unused Amazon EC2 instances are available. It's always possible that your Spot Instance might be interrupted. 

When you enable Capacity Rebalancing, EC2 automatically attempts to replace Spot Instances in an Auto Scaling group before they are interrupted. To enable this feature use the Elastic Beanstalk console to [configure the Auto Scaling group](environments-cfg-autoscaling-configuration-approaches.md#environments-cfg-autoscaling-console). Alternatively, you can set the Elastic Beanstalk `EnableCapacityRebalancing` [configuration option](environments-cfg-autoscaling-configuration-approaches.md#environments-cfg-autoscaling-namespace) to `true` in the [aws:autoscaling:asg](command-options-general.md#command-options-general-autoscalingasg) namespace.

For more information, see [Capacity Rebalancing](https://docs.aws.amazon.com/autoscaling/ec2/userguide/capacity-rebalance.html) in the *Amazon EC2 Auto Scaling User Guide* and [Spot Instance Interruptions](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-interruptions.html) in the *Amazon EC2 User Guide*.

**Older Instance Types and Spot Instance Support**  
Some older AWS accounts might provide Elastic Beanstalk with default instance types that don't support Spot Instances. If you enable Spot Instance requests and you see the error None of the instance types you specified supports Spot, update your configuration with instance types that support Spot Instances. To choose Spot Instance types, use the [Spot Instance Advisor](https://aws.amazon.com/ec2/spot/instance-advisor/).

**Topics**
+ [

# Enabling Spot Instances for your environment
](environments-cfg-autoscaling-enable-spot.md)
+ [

# Spot Instance allocation strategy
](environments-cfg-autoscaling-spot-allocation-strategy.md)
+ [

# Managing On-Demand instances and Spot instances
](environments-cfg-autoscaling-spot-and-demand.md)
+ [

# Capacity configuration for your Elastic Beanstalk environment
](environments-cfg-autoscaling-configuration-approaches.md)

# Enabling Spot Instances for your environment
Enabling Spot Instances

To take advantage of Amazon EC2 Spot Instances, set the `EnableSpot` option for your environment. Your environment's Auto Scaling group then combines Amazon EC2 purchase options and maintains a mix of On-Demand and Spot Instances.

You can use the [Elastic Beanstalk console](environments-cfg-autoscaling-configuration-approaches.md#environments-cfg-autoscaling-console), [namespace configuration options](environments-cfg-autoscaling-configuration-approaches.md#environments-cfg-autoscaling-namespace), the [AWS CLI](environments-cfg-autoscaling-configuration-approaches.md#environments-cfg-autoscaling-aws-cli), or the [EB CLI](environments-cfg-autoscaling-configuration-approaches.md#environments-cfg-autoscaling-ebcli) to enable Spot Instance requests for your environment.

Before you enable Spot Instances for your environment, become familiar with the Auto Scaling, capacity, and load balancing configuration options that are available. Your application's requirements that are related to workload, impact of instance interruptions, and pricing, are all important considerations in your planning to enable Spot Instances. 

The topics that follow provide details about the Auto Scaling and capacity management options and how their combined use affects your environment. There are procedures and example configurations to inform and guide you about the various options and how to configure them. We also offer tools and features to help you manage your configuration and respond to events. You can schedule automated changes to your configuration based on predictable periods of traffic, configure triggers to respond to factors such as traffic volume, and configure Auto Scaling monitoring and health checks.

For more detailed information about Spot Instances, including explanation of key concepts and best practices, see [Spot Instances](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-spot-instances.html) in the *Amazon EC2 User Guide*.

**Important**  
The `EnableSpot` option setting can cause Elastic Beanstalk to migrate an existing environment with launch configurations to launch templates. Doing so requires the necessary permissions to manage launch templates. These permissions are included in our managed policy. If you use custom policies instead of our managed policies, environment creation or updates might fail when you update your environment configuration. For more information and other considerations, see [Migrating your Elastic Beanstalk environment to launch templates](environments-cfg-autoscaling-launch-templates.md).

# Spot Instance allocation strategy
Spot allocation strategy

You can select any one of the allocation strategies listed in this topic for your Elastic Beanstalk environment. Use the [Elastic Beanstalk console](environments-cfg-autoscaling-configuration-approaches.md#environments-cfg-autoscaling-console), [namespace configuration options](environments-cfg-autoscaling-configuration-approaches.md#environments-cfg-autoscaling-namespace), or the [AWS CLI](environments-cfg-autoscaling-configuration-approaches.md#environments-cfg-autoscaling-aws-cli), to set and configure Spot Instance allocation strategy and related attributes for your environment. 

Amazon EC2 applies an *allocation strategy* to manage and provision Spot instances for your environment. Each allocation strategy optimizes the allocated instances based on how it’s defined to handle available capacity, price, and selection of instance types. 

Amazon EC2 Auto Scaling provides the following allocation strategies for Spot Instances. 
+ **Capacity optimized** (default)
  + Requests Spot Instances from the pool, with *optimal capacity* for the number of instances that are launching.
  + This strategy works well for workloads where the possibility of service disruption must be minimized.
+ **Price capacity optimized**
  + Requests Spot Instances from the pools that have the *lowest chance of interruption* and the *lowest possible price*.
  + This is the preferable choice for most Spot workloads.
+ **Capacity optimized prioritized**
  + Requests Spot Instances based on *capacity availability first*, while honoring your choice of *instance type prioritization* on a best-effort basis. You can provide a list of instance types, ordered by priority, when you configure Spot Instance options for Elastic Beanstalk.
  + This strategy is good for workloads that require minimal service disruption, and a specific instance type prioritization matters.
+ **Lowest price** 
  + Requests Spot Instances from the *lowest priced pool* with available instances.
  + It's important to take precaution when using this strategy, since it only considers instance price and not capacity availability, which will result in high interruption rates.

For more details about each allocation strategy, see [ Allocation strategies for multiple instance types](https://docs.aws.amazon.com/autoscaling/ec2/userguide/allocation-strategies.html) in the *Amazon EC2 Auto Scaling User Guide*. 

To help you understand which allocation strategy is best suited to meet your environment's requirements, see [ Choose the appropriate Spot allocation strategy ](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-fleet-allocation-strategy.html#ec2-fleet-allocation-use-cases) in the *Amazon EC2 User Guide*.

# Managing On-Demand instances and Spot instances
On-Demand and Spot instances

You can launch and automatically scale a fleet of On-Demand Instances and Spot Instances within a single Auto Scaling group. The following options can be used in tandem to configure how the Auto Scaling service manages Spot Instances and On-Demand Instances in your environment. 

You can configure these options for your environment using the [Elastic Beanstalk console](environments-cfg-autoscaling-configuration-approaches.md#environments-cfg-autoscaling-console), [namespace configuration options](environments-cfg-autoscaling-configuration-approaches.md#environments-cfg-autoscaling-namespace), the [AWS CLI](environments-cfg-autoscaling-configuration-approaches.md#environments-cfg-autoscaling-aws-cli), or the [EB CLI](environments-cfg-autoscaling-configuration-approaches.md#environments-cfg-autoscaling-ebcli). 

These options are part of the [aws:ec2:instances](command-options-general.md#command-options-general-ec2instances) namespace:
+ `EnableSpot` ‐ When set to `true` this setting enables Spot Instance requests for your environment. 
+ `SpotFleetOnDemandBase` ‐ Sets the minimum number of On-Demand Instances that your Auto Scaling group provisions before considering Spot Instances as your environment scales up.
+ `SpotFleetOnDemandAboveBasePercentage` ‐ The percentage of On-Demand Instances as part of additional capacity that your Auto Scaling group provisions beyond the `SpotOnDemandBase` instances.

The previously listed options correlate with the following options in the [aws:autoscaling:asg](command-options-general.md#command-options-general-autoscalingasg) namespace:
+ `MinSize` ‐ The minimum number of instances that you want in your Auto Scaling group.
+ `MaxSize` ‐ The maximum number of instances that you want in your Auto Scaling group.

**Important**  
The `EnableSpot` option setting can cause Elastic Beanstalk to migrate an existing environment with launch configurations to launch templates. Doing so requires the necessary permissions to manage launch templates. These permissions are included in our managed policy. If you use custom policies instead of our managed policies, environment creation or updates might fail when you update your environment configuration. For more information and other considerations, see [Migrating your Elastic Beanstalk environment to launch templates](environments-cfg-autoscaling-launch-templates.md).

## Applying both sets of namespace options
Applying both namespace options

The following points describe how the combination of these option settings affects the scaling for your environment.
+ Only `MinSize` determines your environment’s initial capacity—the number of instances you want running at a minimum. 
+  `SpotFleetOnDemandBase` doesn't affect initial capacity. When Spot is enabled, this option determines how many On-Demand Instances are provisioned before any Spot Instances are considered. 
+ Consider when `SpotFleetOnDemandBase` is less than `MinSize`. You'll still get exactly `MinSize` instances as initial capacity. At least `SpotFleetOnDemandBase` of them must be On-Demand Instances. 
+ Consider when `SpotFleetOnDemandBase` is greater than `MinSize`. As your environment scales out, you're guaranteed to get at least an additional amount of instances equal to the difference between the two values. In other words, you're guaranteed to get at least an additional `(SpotFleetOnDemandBase - MinSize)` instances that are On-Demand before satisfying the `SpotFleetOnDemandBase` requirement.

**Single-instance environments**  
In production environments, Spot Instances are particularly useful as part of a scalable, load-balanced environment. We don't recommend using Spot in a single-instance environment. If Spot Instances aren't available, you might lose the entire capacity (a single instance) of your environment. You may still wish to use a Spot Instance in a single instance environment for development or testing. When you do, be sure to set both `SpotFleetOnDemandBase` and `SpotFleetOnDemandAboveBasePercentage` to zero. Any other settings result in an On-Demand Instance.

## Examples of scaling options settings
Examples

The following examples demonstrate different scenarios of setting the various scaling options. All examples assume a load-balanced environment with Spot Instance requests enabled.

**Example 1: On-Demand and Spot as part of initial capacity**  <a name="environments-cfg-autoscaling-spot-example1"></a>


**Option settings**  

|  **Option**  |  **Namespace**  |  **Value**  | 
| --- | --- | --- | 
|  `MinSize`  |  `aws:autoscaling:asg`  |  `10`  | 
|  `MaxSize`  |  `aws:autoscaling:asg`  |  `24`  | 
|  `SpotFleetOnDemandBase`  |  `aws:ec2:instances`  |  `4`  | 
|  `SpotFleetOnDemandAboveBasePercentage`  |  `aws:ec2:instances`  |  `50`  | 

In this example, the environment starts with ten instances, of which seven are On-Demand (four base, and 50% of the six above base) and three are Spot. The environment can scale out up to 24 instances. As it scales out, the portion of On-Demand in the part of the fleet above the four base On-Demand instances is kept at 50%, up to a maximum of 24 instances overall, of which 14 are On-Demand (four base, and 50% of the 20 above base) and ten are Spot.



**Example 2: All On-Demand initial capacity**  <a name="environments-cfg-autoscaling-spot-example1"></a>


**Option settings**  

|  **Option**  |  **Namespace**  |  **Value**  | 
| --- | --- | --- | 
|  `MinSize`  |  `aws:autoscaling:asg`  |  `4`  | 
|  `MaxSize`  |  `aws:autoscaling:asg`  |  `24`  | 
|  `SpotFleetOnDemandBase`  |  `aws:ec2:instances`  |  `4`  | 
|  `SpotFleetOnDemandAboveBasePercentage`  |  `aws:ec2:instances`  |  `50`  | 

In this example, the environment starts with four instances, all of which are On-Demand. The environment can scale out up to 24 instances. As it scales out, the portion of On-Demand in the part of the fleet above the four base On-Demand instances is kept at 50%, up to a maximum of 24 instances overall, of which 14 are On-Demand (four base, and 50% of the 20 above base) and ten are Spot.

**Example 3: Additional On-Demand base beyond initial capacity**  <a name="environments-cfg-autoscaling-spot-example1"></a>


**Option settings**  

|  **Option**  |  **Namespace**  |  **Value**  | 
| --- | --- | --- | 
|  `MinSize`  |  `aws:autoscaling:asg`  |  `3`  | 
|  `MaxSize`  |  `aws:autoscaling:asg`  |  `24`  | 
|  `SpotFleetOnDemandBase`  |  `aws:ec2:instances`  |  `4`  | 
|  `SpotFleetOnDemandAboveBasePercentage`  |  `aws:ec2:instances`  |  `50`  | 

In this example, the environment starts with three instances, all of which are On-Demand. The environment can scale out up to 24 instances. The first additional instance above the initial three is On-Demand, to complete the four base On-Demand instances. As it scales out further, the portion of On-Demand in the part of the fleet above the four base On-Demand instances is kept at 50%, up to a maximum of 24 instances overall, of which 14 are On-Demand (four base, and 50% of the 20 above base) and ten are Spot.

# Capacity configuration for your Elastic Beanstalk environment
Configuration

This topic describes the different approaches to configure Auto Scaling capacity for your Elastic Beanstalk environment. You can use the Elastic Beanstalk console, the EB CLI, the AWS CLI, or namespace options.

**Important**  
The `EnableSpot` option setting can cause Elastic Beanstalk to migrate an existing environment with launch configurations to launch templates. Doing so requires the necessary permissions to manage launch templates. These permissions are included in our managed policy. If you use custom policies instead of our managed policies, environment creation or updates might fail when you update your environment configuration. For more information and other considerations, see [Migrating your Elastic Beanstalk environment to launch templates](environments-cfg-autoscaling-launch-templates.md).

## Configuration using the console
Console

You can configure the capacity management of an Auto Scaling group by editing **Capacity** on the environment's **Configuration** page in the [Elastic Beanstalk console](environments-console.md).

**To configure Auto Scaling group capacity in the Elastic Beanstalk console**

1. Open the [Elastic Beanstalk console](https://console.aws.amazon.com/elasticbeanstalk), and in the **Regions** list, select your AWS Region.

1. In the navigation pane, choose **Environments**, and then choose the name of your environment from the list.

1. In the navigation pane, choose **Configuration**.

1. In the **Capacity** configuration category, choose **Edit**.

1. In the **Auto Scaling group** section, configure the following settings.
   + **Environment type** – Select **Load balanced**.
   + **Min instances** – The minimum number of EC2 instances that the group should contain at any time. The group starts with the minimum count and adds instances when the scale-up trigger condition is met.
   + **Max instances** – The maximum number of EC2 instances that the group should contain at any time.
**Note**  
If you use rolling updates, be sure that the maximum instance count is higher than the [**Minimum instances in service** setting](using-features.rollingupdates.md#rollingupdates-configure) for rolling updates.
   + **Fleet composition** – The default is **On-Demand Instances**. To enable *Spot Instance* requests, select **Combined purchase options and instances**.
**Important**  
The `EnableSpot` option setting can cause Elastic Beanstalk to migrate an existing environment with launch configurations to launch templates. Doing so requires the necessary permissions to manage launch templates. These permissions are included in our managed policy. If you use custom policies instead of our managed policies, environment creation or updates might fail when you update your environment configuration. For more information and other considerations, see [Migrating your Elastic Beanstalk environment to launch templates](environments-cfg-autoscaling-launch-templates.md).

     The following options are enabled if you select to enable *Spot Instance* requests:
     + **Spot allocation strategy** – Determines the method used to manage and provision the Spot Instances in your environment, based on available capacity, price, and selection of instance types. Select from *Capacity optimized* (default), *Price capacity optimized*, *Capacity optimized prioritized*, or *Lowest price*. For a description of each allocation strategy and more information, see [Spot Instance allocation strategy](environments-cfg-autoscaling-spot-allocation-strategy.md).
     + **Maximum spot price** – For recommendations about maximum price options for Spot Instances, see [Spot Instance pricing history](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-spot-instances-history.html) in the *Amazon EC2 User Guide*.
     + **On-Demand base** – The minimum number of On-Demand Instances that your Auto Scaling group provisions before considering Spot Instances as your environment scales out.
     + **On-Demand above base** – The percentage of On-Demand Instances as part of any additional capacity that your Auto Scaling group provisions beyond the On-Demand base instances.
**Note**  
The options **On-Demand base** and **On-Demand above base** correlate to the **Min** and **Max** *Instances* options listed earlier. For more information about these options and examples, see [Spot Instance support for your Elastic Beanstalk environment](environments-cfg-autoscaling-spot.md). 
     + **Capacity Rebalancing** – This option is only relevant when there is at least one Spot Instance in your Auto Scaling group. When this feature is enabled, EC2 automatically attempts to replace Spot Instances in the Auto Scaling group before they're interrupted, minimizing Spot Instance interruptions to your applications. For more information, see [Capacity Rebalancing](https://docs.aws.amazon.com/autoscaling/ec2/userguide/capacity-rebalance.html) in the *Amazon EC2 Auto Scaling User Guide*
   + **Architecture** – The processor architecture for your EC2 instances. The processor architecture determines the EC2 Instance types that become available in the next field.
   + **Instance types** – The types of Amazon EC2 instance launched to run your application. For details, see [Instance types](using-features.managing.ec2.console.md#using-features.managing.ec2.instancetypes).
   + **AMI ID** – The machine image that Elastic Beanstalk uses to launch Amazon EC2 instances in your environment. For details, see [AMI ID](using-features.managing.ec2.console.md#using-features.managing.ec2.customami).
   + **Availability Zones** – Choose the number of Availability Zones to spread your environment's instances across. By default, the Auto Scaling group launches instances evenly across all usable zones. To concentrate your instances in fewer zones, choose the number of zones to use. For production environments, use at least two zones to ensure that your application is available in case one Availability Zone goes out.
   + **Placement** (optional) – Choose the Availability Zones to use. Use this setting if your instances need to connect to resources in specific zones, or if you have purchased [reserved instances](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts-on-demand-reserved-instances.html), which are zone-specific. If you launch your environment in a custom VPC, you cannot configure this option. In a custom VPC, you choose Availability Zones for the subnets that you assign to your environment.
   + **Scaling cooldown** – The amount of time, in seconds, to wait for instances to launch or terminate after scaling, before continuing to evaluate triggers. For more information, see [Scaling Cooldowns](https://docs.aws.amazon.com/autoscaling/ec2/userguide/Cooldown.html).

1. To save the changes choose **Apply** at the bottom of the page.

## Configuration using namespace options
Namespace options

Elastic Beanstalk provides [configuration options](command-options.md) for Auto Scaling settings in two namespaces: [`aws:autoscaling:asg`](command-options-general.md#command-options-general-autoscalingasg) and [`aws:ec2:instances`](command-options-general.md#command-options-general-ec2instances).

### The aws:autoscaling:asg namespace


The [`aws:autoscaling:asg`](command-options-general.md#command-options-general-autoscalingasg) namespace provides options for overall scale and availability.

The following [configuration file](ebextensions.md) example configures the Auto Scaling group to use two to four instances, specific availability zones, and a cooldown period of 12 minutes (720 seconds). It enables [Capacity Rebalancing](https://docs.aws.amazon.com/autoscaling/ec2/userguide/capacity-rebalance.html) for Spot Instances. This `EnableCapacityRebalancing` option only takes effect if `EnableSpot` is set to `true` in the [`aws:ec2:instances`](command-options-general.md#command-options-general-ec2instances) namespace, as shown in the configuration file example following this one.

```
option_settings:
  aws:autoscaling:asg:
    Availability Zones: Any
    Cooldown: '720'
    Custom Availability Zones: 'us-west-2a,us-west-2b'
    MaxSize: '4'
    MinSize: '2'
    EnableCapacityRebalancing: true
```

### The aws:ec2:instances namespace


**Note**  
When you update your environment configuration and remove one or more instance types from the `InstanceTypes` option, Elastic Beanstalk terminates any Amazon EC2 instances running on any of the removed instance types. Your environment's Auto Scaling group then launches new instances, as necessary to complete the desired capacity, using your current specified instance types.

The [`aws:ec2:instances`](command-options-general.md#command-options-general-ec2instances) namespace provides options related to your environment's instances, including Spot Instance management. It complements [`aws:autoscaling:launchconfiguration`](command-options-general.md#command-options-general-autoscalinglaunchconfiguration) and [`aws:autoscaling:asg`](command-options-general.md#command-options-general-autoscalingasg).

The following [configuration file](ebextensions.md) example configures the Auto Scaling group to enable Spot Instance requests for your environment. It designates three possible instance types that can be used. At least one On-Demand Instance is used for baseline capacity, and a sustained 33% of On-Demand Instances is used for any additional capacity. 

The configuration sets the [spot allocation strategy](environments-cfg-autoscaling-spot-allocation-strategy.md) to `capacity-optimized-prioritized`. This particular allocation strategy prioritizes the instance launches from the pool based on the order of the instance types specified in the `InstanceTypes` option. If `SpotAllocationStrategy` is not specified it defaults to `capacity-optimized`.

```
option_settings:
  aws:ec2:instances:
    EnableSpot: true
    InstanceTypes: 't2.micro,t3.micro,t3.small'    
    SpotAllocationStrategy: capacity-optimized-prioritized
    SpotFleetOnDemandBase: '1'
    SpotFleetOnDemandAboveBasePercentage: '33'
```

To choose Spot Instance types, use the [Spot Instance Advisor](https://aws.amazon.com/ec2/spot/instance-advisor/).

**Important**  
The `EnableSpot` option setting can cause Elastic Beanstalk to migrate an existing environment with launch configurations to launch templates. Doing so requires the necessary permissions to manage launch templates. These permissions are included in our managed policy. If you use custom policies instead of our managed policies, environment creation or updates might fail when you update your environment configuration. For more information and other considerations, see [Migrating your Elastic Beanstalk environment to launch templates](environments-cfg-autoscaling-launch-templates.md).

## Configuration using the AWS CLI
AWS CLI

This section provides examples of how you can use the AWS CLI [create-environment](https://docs.aws.amazon.com/cli/latest/reference/elasticbeanstalk/create-environment.html) command to configure your environment with the Auto Scaling and Capacity options described in these sections. You'll notice the namespace settings for [`aws:autoscaling:asg`](command-options-general.md#command-options-general-autoscalingasg) and [`aws:ec2:instances`](command-options-general.md#command-options-general-ec2instances), as described in the previous [namespace configuration options](#environments-cfg-autoscaling-namespace) section are also configured with this example.

The AWS Command Line Interface provides commands to create and configure Elastic Beanstalk environments. With the `--option-settings` option, you can pass in namespace options that are supported by Elastic Beanstalk. This means that the [namespace configuration options](#environments-cfg-autoscaling-namespace) described previously can be passed into applicable AWS CLI commands to configure your Elastic Beanstalk environment.

**Note**  
You can also use the [update-environment](https://docs.aws.amazon.com/cli/latest/reference/elasticbeanstalk/update-environment.html) command with `--option-settings` to add or update namespace options. If you need to remove any namespace options from your environment use the **update-environment** command with `--options-to-remove`.

The following example creates a new environment. Refer to the previous topic [namespace configuration options](#environments-cfg-autoscaling-namespace) for more context about the options that are passed in.

The fist option listed, `IamInstanceProfile` in the [aws:autoscaling:launchconfiguration](command-options-general.md#command-options-general-autoscalinglaunchconfiguration) namespace, is the Elastic Beanstalk [instance profile](concepts-roles-instance.md). It's required when you create a new environment.

**Example — create-environment with Auto Scaling options (namespace options inline)**  

```
aws elasticbeanstalk create-environment \
--region us-east-1 \
--application-name my-app \
--environment-name my-env \
--solution-stack-name "64bit Amazon Linux 2023 v4.3.0 running Python 3.12" \
--option-settings \
Namespace=aws:autoscaling:launchconfiguration,OptionName=IamInstanceProfile,Value=aws-elasticbeanstalk-ec2-role
Namespace=aws:autoscaling:asg,OptionName=Availability Zones,Value=Any \
Namespace=aws:autoscaling:asg,OptionName=Cooldown,Value=720 \
Namespace=aws:autoscaling:asg,OptionName=Custom Availability Zones,Value=us-west-2a,us-west-2b \
Namespace=aws:autoscaling:asg,OptionName=MaxSize,Value=4 \
Namespace=aws:autoscaling:asg,OptionName=MinSize,Value=2 \
Namespace=aws:autoscaling:asg,OptionName=EnableCapacityRebalancing,Value=true \
Namespace=aws:ec2:instances,OptionName=EnableSpot,Value=true \
Namespace=aws:ec2:instances,OptionName=InstanceTypes,Value=t2.micro,t3.micro,t3.small \
Namespace=aws:ec2:instances,OptionName=SpotAllocationStrategy,Value=capacity-optimized-prioritized \
Namespace=aws:ec2:instances,OptionName=SpotFleetOnDemandBase,Value=1 \
Namespace=aws:ec2:instances,OptionName=SpotFleetOnDemandAboveBasePercentage,Value=33
```





**Important**  
The `EnableSpot` option setting can cause Elastic Beanstalk to migrate an existing environment with launch configurations to launch templates. Doing so requires the necessary permissions to manage launch templates. These permissions are included in our managed policy. If you use custom policies instead of our managed policies, environment creation or updates might fail when you update your environment configuration. For more information and other considerations, see [Migrating your Elastic Beanstalk environment to launch templates](environments-cfg-autoscaling-launch-templates.md).





As an alternative, use an `options.json` file to specify the namespace options instead of including them inline.

**Example —create-environment with Auto Scaling options (namespace options in `options.json` file)**  

```
aws elasticbeanstalk create-environment \
--region us-east-1 \
--application-name my-app \
--environment-name my-env \
--solution-stack-name "64bit Amazon Linux 2023 v4.3.0 running Python 3.12"
--option-settings file://options.json
```

**Example**  

```
### example options.json ###
[
    {
        "Namespace": "aws:autoscaling:launchconfiguration",
        "OptionName": "IamInstanceProfile",
        "Value": "aws-elasticbeanstalk-ec2-role"
    },
    {
        "Namespace": "aws:autoscaling:asg",
        "OptionName": "Availability Zones",
        "Value": "Any"
    },
    {
        "Namespace": "aws:autoscaling:asg",
        "OptionName": "Cooldown",
        "Value": "720"
    },
    {
        "Namespace": "aws:autoscaling:asg",
        "OptionName": "Custom Availability Zones",
        "Value": "us-west-2a,us-west-2b"
    },
    {
        "Namespace": "aws:autoscaling:asg",
        "OptionName": "MaxSize",
        "Value": "4"
    },
    {
        "Namespace": "aws:autoscaling:asg",
        "OptionName": "MinSize",
        "Value": "2"
    },
    {
        "Namespace": "aws:autoscaling:asg",
        "OptionName": "EnableCapacityRebalancing",
        "Value": "true"
    },
    {
        "Namespace": "aws:ec2:instances",
        "OptionName": "EnableSpot",
        "Value": "true"
    },
    {
        "Namespace": "aws:ec2:instances",
        "OptionName": "InstanceTypes",
        "Value": "t2.micro,t3.micro,t3.small"
    },
    {
        "Namespace": "aws:ec2:instances",
        "OptionName": "SpotAllocationStrategy",
        "Value": "capacity-optimized-prioritized"
    },
    {
        "Namespace": "aws:ec2:instances",
        "OptionName": "SpotFleetOnDemandBase",
        "Value": "1"
    },
    {
        "Namespace": "aws:ec2:instances",
        "OptionName": "SpotFleetOnDemandAboveBasePercentage",
        "Value": "33"
    }
]
```

## Configuration using the EB CLI
EB CLI

When creating an environment using the [**eb create**](eb3-create.md) command, you can specify a few options that are related to your environment's Auto Scaling group. These are some of the options that help you control the capacity of your environment.

`--single`  
Creates the environment with one Amazon EC2 instance and no load balancer. If you don't use this option, a load-balancer is added to the environment that's created.

`--enable-spot`  
Enables Spot Instance requests for your environment.  
The `enable-spot` option setting can cause Elastic Beanstalk to migrate an existing environment with launch configurations to launch templates. Doing so requires the necessary permissions to manage launch templates. These permissions are included in our managed policy. If you use custom policies instead of our managed policies, environment creation or updates might fail when you update your environment configuration. For more information and other considerations, see [Migrating your Elastic Beanstalk environment to launch templates](environments-cfg-autoscaling-launch-templates.md).
The following options for the [**eb create**](eb3-create.md) command can only be used with `--enable-spot`.    
`--instance-types`  
Lists the Amazon EC2 instance types that you want your environment to use.  
`--spot-max-price`  
The maximum price per unit hour, in US dollars, that you're willing to pay for a Spot Instance. For recommendations about maximum price options for Spot Instances, see [Spot Instance pricing history](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-spot-instances-history.html) in the *Amazon EC2 User Guide*.  
`--on-demand-base-capacity`  
The minimum number of On-Demand Instances that your Auto Scaling group provisions before considering Spot Instances as your environment scales up.  
`--on-demand-above-base-capacity`  
The percentage of On-Demand Instances as part of additional capacity that your Auto Scaling group provisions that's more than the number of instances that's specified by the `--on-demand-base-capacity` option.

The following example creates an environment and configures the Auto Scaling group to enable Spot Instance requests for the new environment. For this example, three possible instance types can be used.

```
$ eb create --enable-spot --instance-types "t2.micro,t3.micro,t3.small"
```

**Important**  
There is another similarly named option that's called `--instance-type` (no “s”) that the EB CLI only recognizes when processing On-Demand Instances. Don't use `--instance-type` (no "s") with the `--enable-spot` option. If you do, the EB CLI ignores it. Instead use `--instance-types` (with "s") with the `--enable-spot` option. 