Skip to content

A daily developer tool (based on CDK) to create an Amazon EC2 Spot Instance and connect to the instance.

License

Notifications You must be signed in to change notification settings

dwchiang/aws-spot-one

Repository files navigation

aws-spot-one

Follow Pahud's Youtube video: EP22 - Building Highly Durable Spot Blocks with no Interruption with AWS CDK(4K 2160P)

Requirements

  • Installed AWS CLI v2.
  • Installed AWS CDK.
  • export AWS_DEFAULT_PROFILE=your-profile-name-here
  • Use default VPC.

Preparations

File: ec2-init-connect.sh and ec2-connect.sh:

  • Update your private key file path in prikey.
  • If you don't have a key pair, generate one: ssh-keygen -t rsa -b 4096 -C "[email protected]".

File: lib\aws-spot-one-stack.ts

  • Update blockDuration to your desired duration.
    • Also update fleet.expireAfter to your desired duration.
  • Update defaultInstanceType to your assigned instance type.

Executions

Get required packages and compile typescript to js.

npm install
npm run build

Bootstrap once per AWS account per region.

make bootstrap

Synth:

make synth

Diff:

make diff

Deploy:

make deploy

# You may need to press 'Y' if cdk involves creating IAM resources.

You will see the spot instance id after couple minutes. Then you can have an ssh connect to the new created spot instance:

./ec2-connect.sh {your_instance_id}

Destroy:

Normally you don't need to destory it, but it's an option.

make destroy

Clean:

If you are using multiple AWS/IAM accounts, you may need to clean up the cdk context (which is generated by cdk synth).

make clean

About

A daily developer tool (based on CDK) to create an Amazon EC2 Spot Instance and connect to the instance.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published