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/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/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
Built Distribution
Close
Hashes for cdk-ec2-spot-simple-2.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | de0adf76852131fc53a5e5e473d251a1c0e10c9a63a7578a890cbd1c0e6d45bd |
|
MD5 | e4dd75f335dd699ee37bcda7501d892a |
|
BLAKE2b-256 | 339cdc47aac550bda255855a8e9c850612a88c3e0a76832c5f92e0a5bb995381 |
Close
Hashes for cdk_ec2_spot_simple-2.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea13c0324001919fef2419051bd94f655f881def1ba461d0be6faac19a731d38 |
|
MD5 | 80ca42fcf5596a8cc5fb3a407b9b19f5 |
|
BLAKE2b-256 | abed19a21caa3284c59780340b8d9296a11524a72152337935b0033f72a94336 |