Database Guardrails

Stacktape database guardrails are preventive policy definitions that restrict which database engines, instance sizes, and accessibility modes your team can deploy. Each definition has a type identifier and a properties object describing what is allowed or blocked for database resources in the stack. The deletion protection guardrail targets relational databases specifically, the VPC-only guardrail applies to relational databases and OpenSearch, and the engine and instance restriction guardrails apply to databases that use engine types and instance sizes respectively.

Guardrails are preventive — non-matching values are blocked, preventing non-compliant configurations from being applied. They are distinct from alarms, which are reactive and notify you about runtime problems after deployment.

Stacktape defines four database-specific guardrail types:

GuardrailType identifierKey propertyApproach
Engine restrictiondatabase-engine-restrictionallowedEnginesAllowlist
Instance restrictiondatabase-instance-restrictionallowedInstanceSizesAllowlist
VPC-only databasesrequire-vpc-databasesenabledBoolean toggle
Deletion protectionrequire-deletion-protectionenabledBoolean toggle

Guardrails are managed at the organization level in the Stacktape Console — they are not defined in your stacktape.ts config file. For how to set up and manage guardrails, see the guardrails overview. For other guardrail categories, see deployment guardrails, security guardrails, and resource limit guardrails.

Engine restriction

The database-engine-restriction guardrail controls which database engine types can be provisioned. It uses an allowlist — the allowedEngines property lists permitted engine type strings, and any database whose engine type is not in the list is blocked. This is the most common database guardrail, used to standardize on a single engine family across an organization.

Guardrail definition shape (configured in the Stacktape Console):

{
  type: 'database-engine-restriction',
  properties: {
    allowedEngines: ['postgres', 'aurora-postgresql']
  }
}

The allowedEngines property accepts an array of engine type identifier strings. The type definition gives postgres and aurora-postgresql as examples. Use the exact engine type identifiers supported by your relational database configuration.

Allowlist vs blocklist: Engine restriction uses an allowlist — you permit certain engines, and everything else is blocked. This is the safer default for standardization: when new engine types become available, they are blocked until you deliberately add them to the list.

When to enable: Your organization wants to standardize on a database engine family (e.g., PostgreSQL only) or prevent teams from using engines that carry additional licensing costs. Setting allowedEngines to ['postgres', 'aurora-postgresql'] lets teams choose between single-instance RDS PostgreSQL and Aurora PostgreSQL — while blocking other engine families.

When to skip: Small teams or early-stage projects where engine flexibility matters more than standardization. If your team already follows a strong convention, a guardrail may add overhead without benefit.

If you're standardizing on PostgreSQL, include every PostgreSQL-compatible engine identifier your teams use in the allowlist, so they can choose the deployment model that fits their workload without hitting a guardrail. See the relational database page for the supported engine identifiers.

Instance restriction

The database-instance-restriction guardrail allows teams to provision only reviewed database instance sizes. It uses an allowlist — any provisioned RDS or Aurora instance size not listed in allowedInstanceSizes is blocked. This fails safely when AWS introduces a new size instead of silently permitting it.

Guardrail definition shape (configured in the Stacktape Console):

{
  type: 'database-instance-restriction',
  properties: {
    allowedInstanceSizes: ['db.t4g.medium', 'db.r6g.large']
  }
}

The allowedInstanceSizes property accepts an array of exact database instance size strings. Serverless Aurora engines do not select an instance size and are therefore unaffected by this guardrail.

Why an allowlist: A short reviewed list expresses the actual organizational decision. A blocklist is easy to bypass accidentally with another large class and automatically permits every future AWS size. Legacy blockedInstanceSizes definitions remain enforced, but newly saved policies use the allowlist.

When to enable: You want to prevent cost surprises from oversized instance classes. Large memory-optimized instances (such as db.r5.4xlarge and above) can cost significantly more than smaller instances that handle the same workloads adequately. Blocking expensive sizes proactively is simpler than reviewing every deployment manually.

When to skip: Teams with existing cost review processes, or organizations that exclusively use serverless database engines (which scale capacity automatically). Also less relevant when every database configuration is reviewed before deployment.

Each allowed size must be listed exactly. Review this list when your organization adopts a new database family or size.

VPC-only databases

The require-vpc-databases guardrail enforces that relational databases and OpenSearch domains use VPC-only accessibility with no public internet access. DynamoDB is not checked because it is already accessed through AWS service endpoints rather than a per-table public/private setting. Aurora DSQL currently uses its public service endpoint in Stacktape, so dsql-database fails this guardrail closed until Stacktape can manage the required PrivateLink endpoint. When enabled is true, any covered resource without a supported VPC-only path is blocked.

Guardrail definition shape (configured in the Stacktape Console):

{
  type: 'require-vpc-databases',
  properties: {
    enabled: true
  }
}

For the accessibility modes available on databases and how to configure them, see the relational database documentation.

When to enable: Production environments, regulated industries, or any organization handling sensitive data — PII, financial records, or health information. Most compliance frameworks (SOC 2, HIPAA, PCI-DSS) require databases to be unreachable from the public internet. Enabling this guardrail ensures no team can accidentally expose a database.

When to skip: Organizations where any development stack still needs direct local database access without a VPN or bastion. Guardrails currently apply organization-wide, so this policy cannot be enabled only for production.

Tradeoff: VPC-only databases remove public internet access, meaning workloads that need database connectivity must be configured for VPC networking. A bastion host can provide local access to VPC-only databases during development.

Deletion protection

The require-deletion-protection guardrail enforces that all relational databases and Aurora DSQL databases have deletionProtection set to true. When enabled is true, any of these databases without explicit deletion protection is blocked.

Guardrail definition shape (configured in the Stacktape Console):

{
  type: 'require-deletion-protection',
  properties: {
    enabled: true
  }
}

AWS RDS and Aurora DSQL deletion protection prevent a database resource from being accidentally deleted. The guardrail ensures your team always has this flag active — every relational or DSQL database in the stack must include deletionProtection: true in its configuration.

When to enable: Any production environment, or as a blanket policy to prevent accidental database deletion. The cost of losing production data far outweighs the minor friction of managing the protection flag explicitly.

When to skip: Development and testing stages where databases are ephemeral and frequently recreated. Enforcing deletion protection on short-lived dev databases adds friction without meaningful benefit.

Tradeoff: With this guardrail active, you cannot deploy a relational or DSQL database without deletionProtection: true in its configuration.

Combining database guardrails

Database guardrails work independently and can be enabled simultaneously to enforce a comprehensive database policy. A typical production setup enables all four: standardize on PostgreSQL engines, allow reviewed instance sizes, require VPC isolation, and enforce deletion protection.

When multiple guardrails are active, a stack must satisfy every one of them that applies to its resources.

GuardrailWhat it prevents
Engine restrictionNon-standard engine types (e.g., MySQL when only PostgreSQL is allowed)
Instance restrictionUnreviewed instance sizes
VPC-only databasesPublicly accessible databases
Deletion protectionAccidentally deletable relational and DSQL databases

Recommended starting point: Enable VPC-only databases and deletion protection first — they provide the highest-value safety net for production with minimal configuration overhead. They prevent the two most costly mistakes: data exposure and accidental deletion. Add engine restriction once your team has standardized on an engine family, and instance restriction once cost control across teams becomes a priority.

The following database configuration satisfies all four guardrails — it uses a PostgreSQL engine, an allowed instance size, VPC-only accessibility, and deletion protection:

export default defineConfig(() => {
  const mainDatabase = new RelationalDatabase({
    engine: new RdsEnginePostgres({
      version: '16',
      primaryInstance: {
        instanceSize: 'db.t4g.micro'
      }
    }),
    credentials: {
      masterUserPassword: $Secret('database', 'password')
    },
    accessibility: {
      accessibilityMode: 'vpc'
    },
    deletionProtection: true
  });

  return { resources: { mainDatabase } };
});

Database Guardrails FAQ

Why isn't my database guardrail in my stacktape.ts config file?

Database guardrails are managed at the organization level in the Stacktape Console — they are not defined in your stacktape.ts config file. Your config defines the database; the guardrail (configured separately in the Console) decides whether that database is allowed to deploy. See the guardrails overview for the full setup and management workflow.

Why do engine and instance restrictions use allowlists?

Both restrictions fail closed. allowedEngines and allowedInstanceSizes require a deliberate review before a new engine or instance size can be deployed. This is safer than trying to enumerate every expensive size in a blocklist. Older blockedInstanceSizes policies remain supported so an upgrade does not silently remove protection.

Should I use engine restriction or resource type restriction?

The resource-type-restriction guardrail (covered in resource limit guardrails) blocks an entire resource type — for example, preventing anyone from provisioning a relational-database at all. The database-engine-restriction guardrail is more granular: it permits relational databases but limits which engine types they can use. Use engine restriction when you want teams to deploy databases but need them standardized on specific engines.

What happens when a guardrail blocks my deployment?

The deployment is rejected before any non-compliant database reaches AWS — guardrails are preventive, so the blocked configuration is never applied. Update the database configuration to match the guardrail (for example, switch to an allowed engine, pick an allowed instance size, set accessibilityMode: 'vpc', or add deletionProtection: true), then deploy again.

Which database guardrails should I enable first?

Enable VPC-only databases and deletion protection first — they provide the highest-value safety net for production with minimal friction, preventing the two most costly mistakes: data exposure and accidental deletion. Add engine restriction once your team has standardized on an engine family, and instance restriction once cost control across teams becomes a priority. The guardrails work independently, so you can enable them incrementally.

Can a guardrail control my database costs?

Indirectly, yes. The database-instance-restriction guardrail permits only reviewed instance sizes, preventing an unapproved large class from deploying. It does not monitor spend or compare current AWS prices — for ongoing cost tracking see the managing costs overview.