DEV Community

t.okazaki
t.okazaki

Posted on

Launch an AWS Spot Fleet instance using Terraform

Today, I share a way to launch an AWS instance using Terraform, which has following features:

  • Use EC2 Spot fleet instance which is cheaper than the on-demand instance.
  • Use AWS Session Manager to connect to the instance, so that you don't need to prepare the SSH setting. Also you don't need any bastion host to connect the instance.

Alt Text

Example

You can download the Terraform code on my Github repository.
Terraform example

I made these code with Terraform version v0.12.25.

Download the repository and type following command.

$ cd terraform-examples/spot-ssm-example
$ terraform init
$ terraform plan -var-file=aws.tfvars
$ terraform apply -var-file=aws.tfvars
Enter fullscreen mode Exit fullscreen mode

After that you can connect the instance via Session Manager console in AWS console.You find the way on following short video and AWS document.

References:

AWS EC2 Spot instance document

AWS System Manager Session Manager document

Top comments (0)