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
pnpm add cdk-ec2-spot-simple
yarn add 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/v2
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/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.
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.1.0.tar.gz
(630.9 kB
view hashes)
Built Distribution
Close
Hashes for cdk-ec2-spot-simple-2.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | feaf19a74961cb4d48989a9c5f656eddb29de9ab756d672d49c89d10e5f7ba2a |
|
MD5 | c8a2e26d30b9a02cb2ff592237d652f4 |
|
BLAKE2b-256 | 171d0527f64774f757e8a1a1438e29b8751ad39f2a9380980957ca342d39dc57 |
Close
Hashes for cdk_ec2_spot_simple-2.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46faed28ac611a84b897c48ce7dd4bb74d853e7e83608a08390d06d5e10caea8 |
|
MD5 | 255a5e0e330bc706238f920fea656070 |
|
BLAKE2b-256 | 5695fdb34636bdb426049f13873a6f512f84c8c64fe54a54e54e28445ca3b4e9 |