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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cdk-ec2-spot-simple-2.2.0.tar.gz.
File metadata
- Download URL: cdk-ec2-spot-simple-2.2.0.tar.gz
- Upload date:
- Size: 691.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5affc8d3d7a2ece13a593336568514cc6e83158f3b9d23c16ddfab26eb930f0d
|
|
| MD5 |
a4aca2d51d65296dcab1f7b03195ecb7
|
|
| BLAKE2b-256 |
3140cb639917fe5a3ca8f05e23b58d85e6e8c75d0be1c2cd5e50bf0af3515578
|
File details
Details for the file cdk_ec2_spot_simple-2.2.0-py3-none-any.whl.
File metadata
- Download URL: cdk_ec2_spot_simple-2.2.0-py3-none-any.whl
- Upload date:
- Size: 689.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68bf200a147dc87c5aea3460a626e956b2e7a2464eda1f7f4cc5fb6da78dd977
|
|
| MD5 |
1767784179e3be2c1054347d31fbd769
|
|
| BLAKE2b-256 |
114e78f04d8f67d52076e8c9b49342407b02e6281fd46c7bfaa968a65cc241cd
|