Getting Started / Hands-on / ...
Save on Compute Costs for Applications Deployed Using AWS Elastic Beanstalk with Amazon EC2 Spot Instances
TUTORIAL
Overview
What you will accomplish
Prerequisites
Before starting this tutorial, you will need:
- An AWS account: If you don't already have an account, follow the Setting Up Your AWS Environment guide for a quick overview.
AWS experience
Time to complete
10 minutes
Cost to complete
Requires
Services used
Last updated
February 3, 2023
Step 1: Create an application using Elastic Beanstalk
1.1 — Log in to the AWS Management Console.
Already have an account? Log in to your account
1.2 — Open the Elastic Beanstalk console.
Choose Create Application to create and configure your application
1.4 — In the Platform section, select Node.js and leave the defaults for the Platform branch and Platform version.
Note: You might see a newer Platform version if we have updated the default since this tutorial was last published.
1.6 — It will take a few minutes while Elastic Beanstalk creates a collection of AWS resources including an Application Load Balancer and an Amazon EC2 Auto Scaling group, in addition to deploying your application code.
Step 2: Edit the compute environment to use EC2 Spot Instances
2.1 — By default, Elastic Beanstalk creates compute environments with an Auto Scaling group (ASG) with a single instance type and On-Demand purchase option.
In this section, you will modify the compute environment to use EC2 Spot Instances to achieve up to 90% cost savings off of the On-Demand prices.
To modify the compute environment, select Configuration in the left navigation pane under Samplenodejsapp-env.
2.4 — We will use both On-Demand Instances and Spot Instances in our Auto Scaling group using the MixedInstancesPolicy. Select Combine purchase options and instances for Fleet composition. Leave the Default for Maximum spot price.
For more information on the MixedInstancesPolicy, see the Amazon EC2 Auto Scaling API Reference.
2.5 — Because the sample application is stateless and fault tolerant and can handle an instance being interrupted, we will mostly use Spot Instances, with a small number of On-Demand Instances to provide a consistent baseline of compute. Set the On-Demand base to 3. Set the On-Demand above base to 0%, which means anything above the three On-Demand base Instances will run Spot Instances.
2.6 — Selecting Instance types is an important part of following best practices when using EC2 Spot Instances with Auto Scaling groups. Because Spot Instances are spare On-Demand capacity and their availability at any given moment is dynamic and continually changes in real time, it’s important to be flexible with multiple instance families, sizes, and generations, and to use multiple Availability Zones. Set the Instance types to t2.large, t3a.large, t3.large, m5a.large, m5.large, m4.large, m6i.large, and m6a.large.
Note the instance types availability varies in Regions and if you don’t see an instance in the list, please select another instance that has similar specs.
Hint: You can go to EC2 Console > Instance types to find a list of instance types that meets your criteria by applying filters like vCPUs and Memory.
Step 5: Clean up resources
5.1 — Although the Amazon EC2 Spot Instances are typically 70% to 90% less expensive than an On-Demand EC2 instance, it is still a good idea to clean up and delete resources once you have completed the tutorial.
Delete the Elastic Beanstalk application by selecting Applications > the application sample-nodejs-app -> Actions menu -> Delete application.
Enter the application name sample-nodejs-app to confirm and choose Delete.
Conclusion
Congratulations! You have successfully deployed your sample application on EC2 Spot Instances for a portion of the compute to take advantage of the steep savings of up to 90% off of the On-Demand pricing.
Next steps
If you want to learn more about Amazon EC2 Spot Instances, visit the Amazon EC2 Spot Instances product page to explore documentation, videos, blogs, and more.
Spot Instances workshops
Want to learn more about Spot Instances? Check out the self-guided Spot Instance workshops to learn more about additional use cases for Spot Instances.
To learn more about Spot Instance support in the Auto Scaling group for your Elastic Beanstalk environment using Elastic Beanstalk console, the EB CLI, or configuration options, review the documentation.