Bastion Servers (Jump Hosts)



A bastion server, or jump host, is a virtual machine that provides secure access to resources that are isolated within a private network (VPC). This is useful for managing resources like databases or Redis clusters that don't have a public endpoint.

Connections to the bastion server are established using SSM Session Manager, which leverages your IAM permissions for authentication. This eliminates the need to expose any ports, providing a highly secure way to access your private resources.

Basic usage

resources:
  myBastion:
    type: bastion

Example of a bastion server configuration.

Connecting to a bastion server

You can start an interactive shell session on a bastion server using the bastion:session command:

stacktape bastion:session --stage <<stage>> --region <<region>> --bastionResource <<bastionResourceName>>

Creating a bastion tunnel

For resources that don't have a public endpoint, like a database, you can use a bastion tunnel to access them from your local machine. The bastion:tunnel command creates a secure pathway from a port on your local machine to the port of the target resource, using the bastion server as an intermediary.

stacktape bastion:tunnel --stage <<stage>> --region <<region>> --bastionResource <<bastionResourceName>> --resourceName <<nameOfTargetResource>>

Once the tunnel is established, Stacktape will print the local endpoint that you can use to connect to the resource.

Tunnel example

A diagram showing a bastion tunnel to a database

resources:
  myBastion:
    type: bastion

  myDatabase:
    type: relational-database
    properties:
      # database is only accessible from withing VPC
      accessibility:
        accessibilityMode: vpc
      engine:
        type: postgres
        properties:
          version: '16.2'
          primaryInstance:
            instanceSize: db.t3.micro
      credentials:
        masterUserPassword: my_secret_pass

A bastion server with a database that is only accessible within the VPC.

To create a tunnel to the database, you would run:

stacktape bastion:tunnel --stage <<stage>> --bastionResource myBastion --resourceName myDatabase

The terminal output after starting a tunnel

Bastion tunneling is supported for the following resource types:

  • relational-database
  • redis-cluster
  • application-load-balancer
  • private-service (when using an application load balancer)

Using a bastion with scripts

You can also use bastion servers with scripts. For more information, see the documentation on bastion scripts and local scripts with bastion tunneling.

scripts:
  migrateDb:
    type: local-script-with-bastion-tunneling
    properties:
      executeScript: migrate.ts
      connectTo:
        - myDatabase

hooks:
  afterDeploy:
    - scriptName: migrateDb

resources:
  myBastion:
    type: bastion

  myDatabase:
    type: relational-database
    properties:
      # database is only accessible from withing VPC
      accessibility:
        accessibilityMode: vpc
      engine:
        type: postgres
        properties:
          version: '16.2'
          primaryInstance:
            instanceSize: db.t3.micro
      credentials:
        masterUserPassword: my_secret_pass

A Stacktape configuration that uses a bastion tunnel for a migration script.

Instance size

By default, bastion servers use a t3.micro instance, which is eligible for the AWS Free Tier. You can specify a different instance size using the instanceSize property. For a full list of available instance types, see the AWS documentation.

resources:
  myBastion:
    type: bastion
    properties:
      instanceSize: c5.large

Custom commands on launch

You can run a custom set of commands when the bastion server is launched using the runCommandsAtLaunch property. This is useful for installing dependencies or performing other setup tasks.

Use to install CLI tools, database clients, or other dependencies. Warning: changing this list after creation replaces the instance — any data on the old instance is lost.

resources:
  myBastion:
    type: bastion
    properties:
      runCommandsAtLaunch:
        - yum update
        - yum install postgresql.x86_64 -y

All bastion hosts use the latest Amazon Linux 2023 operating system.

SSM sessions

Stacktape uses SSM Session Manager to provide secure access to bastion servers. This eliminates the need to manage SSH keys or open additional network ports, making it more secure than traditional SSH access.

Pricing

The price of a bastion server depends on its instance size. The default t3.micro instance is free for the first 12 months as part of the AWS Free Tier. After that, it costs approximately $7.50 per month.

API reference

BastionAPI reference
typeRequired
No description

Type: string "bastion"

properties.instanceSizeDefault: t3.micro

EC2 instance type. t3.micro is sufficient for SSH tunneling and basic admin tasks.

Type: string

properties.runCommandsAtLaunch

Shell commands to run when the instance starts (as root — no sudo needed).

Type: Array of string

Use to install CLI tools, database clients, or other dependencies. Warning: changing this list after creation replaces the instance — any data on the old instance is lost.

properties.logging

Log retention settings for system, security, and audit logs. Logs are sent to CloudWatch.

Type: BastionLoggingConfig

overrides

Escape hatch to modify the underlying CloudFormation resources Stacktape creates.

Type: Object

Use dot-notation paths to override specific properties on any child resource. Find resource logical IDs with stacktape stack-info --detailed.

overrides:
  MyDbInstance:
    Properties.StorageEncrypted: true
BastionLoggingConfigAPI referenceParent:Bastion
messagesDefault: retentionDays: 30

System messages (/var/log/messages) — startup info, kernel messages, service logs.

Type: BastionLogging

secureDefault: retentionDays: 180

Auth logs (/var/log/secure) — SSH login attempts, authentication events.

Type: BastionLogging

auditDefault: retentionDays: 365

Audit logs (/var/log/audit/audit.log) — detailed security events from the Linux audit system.

Type: BastionLogging

BastionLoggingAPI referenceParent:BastionLoggingConfig
disabled

Disable this log type. Stops sending to CloudWatch.

Type: boolean

retentionDays

Days to keep logs in CloudWatch before automatic deletion.

Type: number ENUM

Possible values: 13571430609012015018036540054573118273653

logForwarding

Forward logs to an external service (Datadog, Highlight.io, or any HTTP endpoint).

Type: HttpEndpointLogForwarding or HighlightLogForwarding or DatadogLogForwarding

Uses Kinesis Data Firehose (~$0.03/GB). Failed deliveries go to a backup S3 bucket.