CDK construct library to create EC2 Spot Instances simply.
Project description
cdk-ec2-spot-simple
CDK construct library to create EC2 Spot Instances simply.
Install
TypeScript/JavaScript
npm install cdk-ec2-spot-simple
Python
pip install cdk-ec2-spot-simple
.NET
dotnet add package TksSt.Cdk.Ec2SpotSimple
Java
<dependency>
<groupId>st.tks.cdk</groupId>
<artifactId>ec2-spot-simple</artifactId>
</dependency>
Go
go get github.com/tksst/cdk-ec2-spot-simple-go/cdkec2spotsimple
Usage
To set up a spot instance with default parameters, simply use "SpotInstance" instead of "ec2.Instance".
import { SpotInstance } from "cdk-ec2-spot-simple"
import * as ec2 from "aws-cdk-lib/ec2"
// Simple usage
new SpotInstance(this, "DefaultConfigSpotInstance", {
// Required properties of "ec2.Instance"
vpc: ec2.Vpc.fromLookup(this, "defaultVPC", { isDefault: true });,
instanceType: ec2.InstanceType.of(ec2.InstanceClass.T3A, ec2.InstanceSize.NANO),
machineImage: new ec2.AmazonLinuxImage(),
});
// Advanced usage
new SpotInstance(this, "StoppableSpotInstance", {
// Required properties of "ec2.Instance"
vpc: ec2.Vpc.fromLookup(this, "defaultVPC", { isDefault: true });,
instanceType: ec2.InstanceType.of(ec2.InstanceClass.T3A, ec2.InstanceSize.NANO),
machineImage: new ec2.AmazonLinuxImage(),
// SpotInstance specific property
spotOptions: {
interruptionBehavior: ec2.SpotInstanceInterruption.STOP,
requestType: ec2.SpotRequestType.PERSISTENT,
maxPrice: 0.007,
},
});
Background
The Instance
construct in aws-cdk-lib/ec2
does not have any spot instance functionality.
This SpotInstance
construct creates LaunchTemplate
that is enabled spot request internally and associate with Instance
.
Also, SpotInstance
creates a Lambda-backed custom resource if the spot requiest type is PERSISTENT. That resource deletes the spot request when the stack is destroyed.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
cdk-ec2-spot-simple-2.0.1a1.tar.gz
(122.8 kB
view hashes)
Built Distribution
Close
Hashes for cdk-ec2-spot-simple-2.0.1a1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50d05c407113aad31c3fb5e5906914fd1aabc0256dbb590c4a89f72dc62d810f |
|
MD5 | 31c7c5cfd4c56d68b8e6a71320b73248 |
|
BLAKE2b-256 | b2d0866c0fecf760047fb7444c98199eeea07dbc8ff6ed3f4078ad79bd54a462 |
Close
Hashes for cdk_ec2_spot_simple-2.0.1a1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f64dadc7a5820d265a3b33623146201d7d3dc7be9fdf12611918d53c2335a400 |
|
MD5 | 0018481878e75d12f9a23d24b7370eb3 |
|
BLAKE2b-256 | a55d0fc924f574e99cb4928a4079d313063a0eeda8780521a1c19372da334ac2 |