Security and Data Protection Guardrails

Stacktape security and data-protection guardrails express requirements that the CLI can verify before changing infrastructure: private database access, deletion protection, recoverable data stores, dead-letter queues, WAF, and redundant container services. Each guardrail has a type and a properties object that describes the requirement to enforce.

How security guardrails work

Security guardrails are policy definitions with a type and properties object that express requirements for resource configurations. This is fundamentally different from alarms, which reactively notify you when a running system behaves unexpectedly at runtime.

Each guardrail has a type and a properties object. For the security and data-protection guardrails on this page, require-* guardrails use an enabled boolean, and database-engine-restriction uses an allowedEngines allowlist. Other guardrail types use different property shapes. See the guardrails overview for the full list of all 18 guardrail types and their properties.

AspectGuardrailsAlarms
PurposePrevent non-compliant configurationsDetect runtime anomalies
TimingPolicy validation (preventive)Runtime (reactive)
ActionEnforces required settings or valuesSends notification

Security guardrail definitions

Each security guardrail is an object with a type string and a properties object. The five require-* guardrails use an enabled boolean toggle. The database-engine-restriction guardrail uses an allowedEngines allowlist. These guardrail definitions are managed separately from your stacktape.ts resource configuration — they are not added to your stacktape.ts file. The object shapes below illustrate the guardrail policy format.

// require-* guardrails — enabled toggle
{ type: 'require-vpc-databases', properties: { enabled: true } }
{ type: 'require-stack-termination-protection', properties: { enabled: true } }
{ type: 'require-deletion-protection', properties: { enabled: true } }
{ type: 'require-data-backups', properties: { enabled: true } }
{ type: 'require-dead-letter-queue', properties: { enabled: true } }
{ type: 'require-waf', properties: { enabled: true } }
{ type: 'require-multiple-container-instances', properties: { enabled: true } }
{ type: 'require-custom-domain', properties: { enabled: true } }

// Restriction guardrails — allowlist
{ type: 'database-engine-restriction', properties: { allowedEngines: ['postgres', 'aurora-postgresql'] } }

The GuardrailType union currently includes 18 guardrail types; see the guardrails overview for how the docs group them.

The examples below show the resource-side settings that correspond to each guardrail requirement. See the linked resource pages for full resource configuration details.

When to use

Enable security guardrails when your team needs to enforce compliance requirements without relying on code reviews alone to catch misconfigurations. They are most valuable for:

  • Multi-developer teams where anyone can deploy independently — guardrails prevent a developer from accidentally deploying an internet-exposed database or a queue without a dead-letter queue.
  • Compliance-regulated organizations (SOC 2, HIPAA, PCI-DSS) that mandate specific network isolation, data-protection, or encryption controls as baseline requirements.
  • Platform teams providing Stacktape to internal customers who shouldn't need to memorize every security baseline to deploy safely.

When NOT to use

Skip guardrails in early prototyping or single-developer projects where speed matters more than governance. In early prototypes or solo projects, guardrails may be unnecessary until you have shared production baselines to enforce. You can always enable guardrails later when the team grows or the project reaches production.

Require VPC databases

The require-vpc-databases guardrail enforces that, when enabled, relational databases and OpenSearch domains use VPC-only accessibility with no public internet access. DynamoDB does not have an equivalent per-table public accessibility setting and is not checked. Aurora DSQL currently uses its public service endpoint in Stacktape, so a stack containing dsql-database fails this guardrail closed until Stacktape supports its PrivateLink lifecycle.

When to enable: Enable when every stage in the organization should use private data services. VPC-only databases cannot be reached from the public internet, eliminating an entire class of network-based attack vectors. The tradeoff is that you need a bastion host or VPC-connected workloads to access the database for administration and debugging. Guardrails currently apply organization-wide rather than only to production.

When the default is fine: During early development or prototyping, internet-accessible databases are more convenient for local development and ad-hoc queries. The risk is low when the database holds no real data.

A compliant relational database configuration with VPC-only access:

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'
    }
  });

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

This example configures the database with VPC-only access and no public internet exposure. See the relational database page for all supported accessibility modes, engine versions, and instance sizes. See connecting resources for how workloads connect to VPC-only databases.

Require deletion protection

The require-deletion-protection guardrail requires all relational databases and Aurora DSQL databases to have deletionProtection set to true. AWS rejects deletion of a protected database — you must explicitly disable protection before removing it.

When to enable: Enable for any stage where accidental data loss is unacceptable — production, staging with real data, or shared development databases. The tradeoff is minimal: you must explicitly disable deletion protection before intentionally removing a database, which adds one deliberate step to prevent accidents.

When the default is fine: Skip for throwaway development stages where the database is recreated frequently and holds no important data.

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

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

Setting deletionProtection: true satisfies this guardrail. This is an AWS-level safeguard independent of Stacktape. When require-deletion-protection is enabled, every relational and DSQL database must set deletionProtection: true.

Require stack termination protection

The require-stack-termination-protection guardrail requires deploymentConfig.terminationProtection: true. CloudFormation rejects deletion of a protected stack regardless of whether deletion is attempted through Stacktape, AWS Console, or another AWS client.

When to enable: Enable when deleting the complete stack would cause a serious outage or data-loss event. To intentionally delete it, an administrator must first remove this guardrail, deploy with termination protection disabled, and then delete the stack. This deliberate two-step process is stronger than blocking only the Stacktape delete command.

{
  deploymentConfig: { terminationProtection: true },
  resources: { /* ... */ }
}

Require recoverable data stores

The require-data-backups guardrail checks the backup controls Stacktape can determine from configuration:

ResourceRequired configuration
Relational databaseautomatedBackupRetentionDays must not be 0; an omitted value uses the AWS non-zero default
Aurora DSQL databaseNot currently satisfiable: Stacktape cannot configure or verify its separate AWS Backup plan, so the guardrail fails closed
DynamoDB tableenablePointInTimeRecovery: true
EFS filesystembackupEnabled: true

When to enable: Enable when those resources can contain data that cannot simply be recreated. DynamoDB PITR and EFS backups add storage cost. The guardrail confirms controls that Stacktape can verify; it cannot prove that a restore has been tested or that the retention period meets your recovery objectives. An externally configured DSQL backup plan is not detectable from the stack configuration and therefore does not satisfy the guardrail yet.

Require dead-letter queue

The require-dead-letter-queue guardrail ensures every SQS queue in the stack has a redrivePolicy (dead-letter queue) configured. In AWS SQS, a dead-letter queue captures messages that fail processing repeatedly, preventing silent data loss in message-driven architectures. A queue that another queue in the stack names in redrivePolicy.targetSqsQueueName is the dead-letter queue itself and needs no redrivePolicy of its own, as deadLetterQueue in the example below shows. A queue that only queues in other stacks use as their dead-letter queue is not recognized and still needs its own redrivePolicy.

When to enable: Enable when your system processes messages representing real business events — orders, payments, notifications — where losing a message means losing data. Dead-letter queues give you a second chance to inspect and reprocess failed messages instead of having them silently disappear after exhausting retries.

When the default is fine: Skip for ephemeral or best-effort queues where occasional message loss is acceptable, such as analytics event buffers or non-critical notification streams.

export default defineConfig(() => {
  const deadLetterQueue = new SqsQueue({});

  const orderQueue = new SqsQueue({
    redrivePolicy: {
      targetSqsQueueName: 'deadLetterQueue',
      maxReceiveCount: 3
    }
  });

  return {
    resources: { deadLetterQueue, orderQueue }
  };
});

The redrivePolicy specifies which queue receives failed messages and how many receive attempts are allowed before a message is moved there. A maxReceiveCount of 3–5 is typical — low enough to catch persistent failures quickly, high enough to tolerate transient errors. See the SQS queue page for the full redrivePolicy structure. Monitor your dead-letter queue with alarms to get notified when messages land there.

Require WAF

The require-waf guardrail requires every directly configured application load balancer, plus load balancers generated for web and private services, to reference a configured web application firewall. Internally generated load balancers that do not expose a configurable firewall setting are ignored.

When to enable: Enable for public-facing applications that handle user input, authentication, or sensitive data. AWS WAF can defend against common web exploits including SQL injection and cross-site scripting. Most production APIs serving public traffic benefit from WAF.

When the default is fine: Skip for internal-only load balancers, development stages, or stages behind a separate security layer. Also consider skipping for very low-traffic applications where the per-request WAF cost isn't justified.

Cost tradeoff: AWS WAF charges per rule group and per million requests evaluated. The exact cost depends on the rules you configure and your traffic volume. For high-traffic production APIs, WAF is a standard best practice. For low-traffic internal tools, the cost may not be justified. Check current AWS WAF pricing for your region.

A compliant application load balancer configuration with a firewall attached:

export default defineConfig(() => {
  const apiFirewall = new WebAppFirewall({ scope: 'regional' });

  const loadBalancer = new ApplicationLoadBalancer({
    useFirewall: 'apiFirewall'
  });

  return {
    resources: { apiFirewall, loadBalancer }
  };
});

The useFirewall property references a web application firewall resource by name. When enabled, require-waf checks directly configured load balancers and those generated for web and private services. See the web application firewall page for WAF rule configuration.

Require multiple container instances

The require-multiple-container-instances guardrail requires scaling.minInstances of at least 2 for web services, private services, worker services, and user-defined multi-container workloads. It prevents a routine task or instance failure from leaving a service with no running copy. Fixed internal workloads, currently self-hosted Convex, are ignored because users cannot change their instance count.

Tradeoff: Two instances improve instance-level availability but double the minimum compute allocation compared with the default single instance. This rule does not by itself establish a complete availability target; application dependencies and capacity still matter.

Require custom domain

When enabled, the require-custom-domain guardrail requires public-facing web services and hosting buckets to have a custom domain configured. This is a delivery and branding standard, not a security boundary.

When to enable: Enable only when every stage in the organization needs URL stability, branding, and domain ownership. Custom domains give your users a predictable, professional endpoint, but guardrails currently apply organization-wide rather than only to production.

When the default is fine: Skip for development and staging stages where custom domains add DNS propagation delay and certificate provisioning time without adding value. Auto-generated URLs are perfectly adequate for internal testing.

A compliant web service configuration with a custom domain:

export default defineConfig(() => {
  const api = new WebService({
    packaging: new JsBundleImagePackaging({
      entryfilePath: './src/server.ts'
    }),
    resources: {
      cpu: 0.25,
      memory: 512
    },
    customDomains: [
      {
        domainName: 'api.example.com'
      }
    ]
  });

  return {
    resources: { api }
  };
});

When enabled, this guardrail requires public-facing web services and hosting buckets to have a custom domain configured. See the custom domains page for custom domain configuration.

Database engine restriction

The database-engine-restriction guardrail limits which database engine types can be used. You define an allowedEngines list — for example, ["postgres", "aurora-postgresql"]. Database engine types not included in allowedEngines are blocked.

When to enable: Enable when your organization needs to standardize on specific database engine types:

  • Enforce approved engines — restrict deployments to engine types your DBA team actively supports and has runbooks for. This reduces operational risk when incidents happen.
  • Standardize across teams — prevent teams from deploying database engine types your organization has not approved, keeping the technology stack consistent.
  • Meet compliance requirements — some compliance frameworks mandate specific database technologies or encryption capabilities available on certain engine types.

When the default is fine: Skip when your team is small enough that engine choice is a conversation rather than a policy, or when you're exploring different database technologies and don't want to constrain options prematurely.

This guardrail is also covered on the database guardrails page, which includes the related database-instance-restriction guardrail for controlling instance sizes.

Resource type restriction (security use)

The resource-type-restriction guardrail blocks the resource types listed in its blockedResourceTypes property — for example, ["open-search-domain", "redis"]. For broader deployment governance guardrails and the full property shape, see deployment guardrails.

Combining security guardrails

Most production organizations enable multiple security guardrails together. A typical production-security baseline combines network isolation, data protection, and web application firewall guardrails:

GuardrailWhat it enforcesRecommended for
require-vpc-databasesNetwork isolation for relational databases and OpenSearch; blocks DSQL until PrivateLink is supportedOrganizations requiring private access in every stage
require-stack-termination-protectionPrevent complete stack deletionLong-lived production stacks
require-deletion-protectionPrevent accidental database removalAll stages with persistent data
require-data-backupsRecoverable RDS, DynamoDB, and EFS data; blocks unverifiable DSQL backupsWorkloads with non-reproducible data
require-dead-letter-queueMessage durability for SQS queuesEvent-driven architectures
require-wafApplication-layer firewall on application load balancersPublic-facing APIs
require-multiple-container-instancesAt least two running container copiesAvailability-sensitive services
require-custom-domainStable, branded endpointsProduction web services
database-engine-restrictionApproved engine types onlyCompliance-regulated teams
resource-type-restrictionBlock non-approved resource typesSecurity-sensitive environments

These guardrails complement each other. VPC databases prevent network-level exposure. WAF adds application-level protection. Stack and database deletion protection stop accidental removal, while backups protect against corruption and accidental writes. Multiple container instances reduce single-task downtime. Custom domains ensure stable endpoints, and engine restrictions enforce your approved technology list.

Start with require-vpc-databases, stack termination protection, and data backups for long-lived production workloads. Add WAF, dead-letter queues, and multiple container instances where their explicit cost and operational tradeoffs match the workload.

This page covers security and data-protection guardrails. Stacktape includes additional guardrail types for deployment governance and resource limits:

  • Deployment guardrails — stage-restriction, region-restriction, command-restriction, and resource-type-restriction control where and how stacks can be deployed. See deployment guardrails.
  • Resource limit guardrails — function-memory-limit, function-timeout-limit, container-resource-limit, and resource-count-limit cap the size and count of compute resources. See resource limit guardrails.
  • Database guardrails — database-engine-restriction and database-instance-restriction control which database engines and instance sizes are allowed. See database guardrails.

For a high-level overview of all 18 guardrail types, see the guardrails overview.

Security and Data Protection Guardrails FAQ

What is VPC-only database accessibility?

VPC-only accessibility means the database has no public IP address and can only be reached from within the AWS VPC. Workloads running in the same VPC (such as Lambda functions or container workloads configured with connectTo) connect normally. For administration and debugging, use a bastion host or the bastion tunnel CLI command to create a secure tunnel from your local machine.

What does the require-waf guardrail actually protect against?

The guardrail itself only enforces that configurable application load balancers reference a web application firewall — the real protection depends on its rules. AWS WAF inspects incoming HTTP/HTTPS requests and blocks those matching your rules, with common rule sets defending against SQL injection, cross-site scripting (XSS), and bot traffic, plus rate limiting and geographic restrictions.

Do security guardrails add cost to my AWS bill?

Guardrails are configuration policy checks. Cost planning should focus on the resources you add to satisfy a policy — for example, AWS WAF charges per rule and per request evaluated, and custom domains require DNS configuration. VPC-only databases don't add direct cost, but workloads that need both VPC access and internet access may need additional networking configuration. Evaluate the cost of each required resource when planning which guardrails to enable.

When should I use guardrails instead of code reviews?

Use both — they serve different purposes. Code reviews catch logic errors, design issues, and context-dependent decisions requiring human judgment. Guardrails enforce binary policy requirements (VPC-only databases, deletion protection, dead-letter queues) that reviewers might miss under time pressure. Guardrails are especially valuable as teams grow, because policy enforcement doesn't depend on reviewer vigilance or familiarity with every security baseline.

What is the difference between deletion protection and backups?

Deletion protection and backups protect against different failure modes. Deletion protection, enforced by the require-deletion-protection guardrail, prevents the database instance itself from being removed via API calls — it's a safeguard against accidental resource removal. Backups (automated snapshots and point-in-time recovery) protect against data corruption or accidental data changes within a running database. Most production databases benefit from both. See the relational database page for backup configuration.

Can I restrict which database engines my team uses?

Yes. The database-engine-restriction guardrail lets you define an allowedEngines allowlist of permitted engine type identifiers, such as ["postgres", "aurora-postgresql"]. Any engine type not in the list is blocked at deploy time. See database guardrails for the full database-related guardrail set, including the database-instance-restriction guardrail for controlling instance sizes.