[![awscdk-jsii-template](https://img.shields.io/badge/built%20with-awscdk--jsii--template-blue)](https://github.com/pahud/awscdk-jsii-template)
[![NPM version](https://badge.fury.io/js/cdk-spot-one.svg)](https://badge.fury.io/js/cdk-spot-one)
[![PyPI version](https://badge.fury.io/py/cdk-spot-one.svg)](https://badge.fury.io/py/cdk-spot-one)
![Release](https://github.com/pahud/cdk-spot-one/workflows/Release/badge.svg)
# cdk-spot-one
One spot instance with EIP and defined duration. No interruption.
# Why
Sometimes we need an Amazon EC2 instance with static fixed IP for testing or development purpose for a duration of
time(probably hours). We need to make sure during this time, no interruption will occur and we don't want to pay
for on-demand rate. `cdk-spot-one` helps you reserve one single spot instance with pre-allocated or new
Elastic IP addresses(EIP) with defined `blockDuration`, during which time the spot instance will be secured with no spot interruption.
Behind the scene, `cdk-spot-one` provisions a spot fleet with capacity of single instance for you and it associates the EIP with this instance. The spot fleet is reserved as spot block with `blockDuration` from one hour up to six hours to ensure the high availability for your spot instance.
Multiple spot instances are possible by simply specifying the `targetCapacity` construct property, but we only associate the EIP with the first spot instance at this moment.
Enjoy your highly durable one spot instance with AWS CDK!
# Constructs
This library provides two major constructs:
## SpotInstance
* Create a spot instance **without** any fleet
* Does **NOT** support [Spot Block](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-requests.html#fixed-duration-spot-instances)
* Support `stop` or `hibernate` instance
Scenario: To leverage the `stop` or `hibernate` capabilities of the spot instance to persist the data in the ebs volume.
## SpotFleet
* Create a spot instance with a [Spot Fleet](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-fleet.html)
* Support [Spot Block](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-requests.html#fixed-duration-spot-instances)
* Does **NOT** support `stop` or `hibernate` instance
Scenario: To ensure the availability with no disruption with defined period up to 6 hours.
# Sample
## SpotInstance
```python
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
from cdk_spot_one import SpotInstance
# Default use Amazon Linux 2
SpotInstance(stack, "SpotInstance")
# Custom Id use Ubuntu 20.04 Arm64 Server.
SpotInstance(stack, "SpotInstanceUbuntu",
vpc=vpc,
custom_ami_id="ami-076d8ebdd0e1ec091", # ubuntu ami id.
default_instance_type=InstanceType("t4g.medium"),
key_name=key_name,
block_device_mappings=[{"device_name": "/dev/sda1", "ebs": {"volume_size": 20}}],
additional_user_data=["curl -fsSL https://get.docker.com -o get-docker.sh", "sudo sh get-docker.sh"]
)
```
## SpotFleet
```python
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
from cdk_spot_one import SpotFleet
# create the first fleet for one hour and associate with our existing EIP
fleet = SpotFleet(stack, "SpotFleet")
# configure the expiration after 1 hour
fleet.expire_after(Duration.hours(1))
# create the 2nd fleet with single Gravition 2 instance for 6 hours and associate with new EIP
fleet2 = SpotFleet(stack, "SpotFleet2",
block_duration=BlockDuration.SIX_HOURS,
eip_allocation_id="eipalloc-0d1bc6d85895a5410",
default_instance_type=InstanceType("c6g.large"),
vpc=fleet.vpc
)
# configure the expiration after 6 hours
fleet2.expire_after(Duration.hours(6))
# print the instanceId from each spot fleet
CfnOutput(stack, "SpotFleetInstanceId", value=fleet.instance_id)
CfnOutput(stack, "SpotFleet2InstanceId", value=fleet2.instance_id)
```
# Create spot instances without duration block
```python
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
fleet = SpotFleet(stack, "SpotFleet",
block_duration=BlockDuration.NONE
)
```
NOTE: This kind of spot instance will be interrupted by AWS. However the fleet is using type [maintain](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-fleet.html#spot-fleet-allocation-strategy), the fleet can be refulfilled.
# ARM64 and Graviton 2 support
`cdk-spot-one` selects the latest Amazon Linux 2 AMI for your `ARM64` instances. Simply select the instance types with the `defaultInstanceType` property and the `SpotFleet` will auto configure correct AMI for the instance.
```python
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
defaultInstanceType: new InstanceType('c6g.large')
```
# ECS Cluster support
See https://github.com/pahud/cdk-spot-one/issues/270#issuecomment-877152685
# SSH connect
By default the `cdk-spot-one` does not bind any SSH public key for you on the instance. You are encouraged to use `ec2-instance-connect` to send your public key from local followed by one-time SSH connect.
For example:
```sh
pubkey="$HOME/.ssh/aws_2020_id_rsa.pub"
echo "sending public key to ${instanceId}"
aws ec2-instance-connect send-ssh-public-key --instance-id ${instanceId} --instance-os-user ec2-user \
--ssh-public-key file://${pubkey} --availability-zone ${az}
```
## npx ec2-connect INSTANCE_ID
To connect to the instance, run `npx ec2-connect` as below:
```sh
$ npx ec2-connect i-01f827ab9de7b93a9
```
or
```sh
$ npx ec2-connect i-01f827ab9de7b93a9 ~/.ssh/other_public_key_path
```
If you are using different SSH public key(default is ~/.ssh/id_rsa.pub)
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
共17个文件
txt:4个
py:3个
pkg-info:2个
资源分类:Python库 所属语言:Python 资源全名:cdk-spot-one-0.6.282.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源推荐
资源详情
资源评论
收起资源包目录
cdk-spot-one-0.6.282.tar.gz (17个子文件)
cdk-spot-one-0.6.282
MANIFEST.in 23B
PKG-INFO 6KB
pyproject.toml 106B
LICENSE 11KB
src
cdk_spot_one.egg-info
PKG-INFO 6KB
requires.txt 261B
SOURCES.txt 434B
top_level.txt 13B
dependency_links.txt 1B
cdk_spot_one
py.typed 1B
_jsii
bin
ec2-connect 252B
__init__.py 524B
cdk-spot-one@0.6.282.jsii.tgz 42KB
__init__.py 89KB
setup.cfg 38B
setup.py 2KB
README.md 6KB
共 17 条
- 1
资源评论
挣扎的蓝藻
- 粉丝: 13w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功