Skip to content
This repository has been archived by the owner on May 30, 2022. It is now read-only.

Latest commit



75 lines (52 loc) · 2.54 KB

File metadata and controls

75 lines (52 loc) · 2.54 KB

Bastions on Demand

This is a fully functional example of how to create and destroy bastion instances on demand using Fargate.

For an in-depth guide to this example, check out "Bastions on Demand" on my site.


Before you being, you will need to install:

Everything in this repo assumes use of the default AWS profile. You can easily override that assumption with the AWS_PROFILE environment variable.

You can configure your credentials with aws configure.

You will also need to upload your public SSH key to your IAM user using either the AWS Console or the CLI (if you haven't already).


If you haven't previously configured a CloudWatch role for API Gateway, then use the api-gateway-logger module to do so now:

cd api-gateway-logger
terraform init
terraform plan -out plan
terraform apply plan && rm plan
cd ..

This is a global account setting, so you should only have to do it once. Note that destroying the module's resources with Terraform will remove the role, but it will not reset the CloudWatch role setting for API Gateway.

Now we're ready to create the service.

terraform init
./service/bin/  # Build the Lambda functions
terraform apply plan && rm plan

Once the Terraform successfully applies, fire up Docker (if you don't already have it running). Then, build and push the bastion image with:

./bastion/bin/  # Log into ECR
./bastion/bin/  # Build & tag the Docker image
./bastion/bin/   # Push the tagged image to ECR

Finally, we need to make certain the necessary Ruby dependencies are installed:

cd service
cd ..

You should now be able to create and destroy bastions with:


Once a bastion is running, you'll find its IP address in service/.bastion-ip.

You can ssh into the bastion with:

ssh ops@$(cat service/.bastion-ip)