2.2.0 • Published 2 years ago
cdk-ec2-spot-simple v2.2.0
cdk-ec2-spot-simple
CDK construct library to create EC2 Spot Instances simply.
Install
TypeScript/JavaScript
npm install cdk-ec2-spot-simplepnpm add cdk-ec2-spot-simpleyarn add cdk-ec2-spot-simplePython
pip install cdk-ec2-spot-simple.NET
dotnet add package TksSt.Cdk.Ec2SpotSimpleJava
<dependency>
<groupId>st.tks.cdk</groupId>
<artifactId>ec2-spot-simple</artifactId>
</dependency>Go
go get github.com/tksst/cdk-ec2-spot-simple-go/cdkec2spotsimple/v2Usage
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/aws-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
}
});API document
Background
The Instance construct in aws-cdk-lib/aws-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.
2.2.0
2 years ago
2.1.0
2 years ago
2.0.4
2 years ago
2.0.3
3 years ago
2.0.2
3 years ago
2.0.1
3 years ago
2.0.1-alpha.1
3 years ago
2.0.0-alpha.2
3 years ago
1.0.0
3 years ago
1.0.0-alpha.4
3 years ago
1.0.0-alpha.3
3 years ago
1.0.0-alpha.2
3 years ago