Skip to main content

Overview

The Secret resource stores sensitive values such as database passwords, API keys, and other credentials. Each secret is encrypted with a Customer Managed Key (CMK) and accepts simple strings or JSON objects.

Resource Class

Basic Usage

Simple Secret

Generated Password

JSON Secret

Configuration Options

Core Properties

Secret Value Options (use one)

Default Features

Every secret includes:
  • KMS encryption with Customer Managed Key
  • Automatic key creation with alias cmk/${id}
  • Key retention on stack deletion (RETAIN policy)
  • Import/export capabilities

Generated Passwords

Basic Password Generation

Database Password with Username

API Key Generation

Import/Export Pattern

Export for Cross-Stack Usage

Import Specific Field

Integration with Resources

With RDS

With ECS

With Lambda

KMS Encryption

Default CMK Creation

Access the CMK

Secret Rotation

Enable Rotation

Factory Pattern

Using StackBuilder

IAM Permissions

Grant Read Access

Custom Permissions

Outputs

The nested CustomerManagedKey construct creates the KMS key outputs. Export names key off the CMK construct id (${id}CustomerManagedKey), run through toPascalCase, so the value below is name = toPascalCase($CustomerManagedKey):

Complete Example

Best Practices

  1. Never hardcode secrets. Store them in Secrets Manager.
  2. Use generated passwords for databases.
  3. Rotate secrets every 30 to 90 days.
  4. Apply least-privilege IAM policies.
  5. Separate secrets by purpose. Do not mix unrelated secrets.
  6. Tag secrets for cost allocation and compliance.
  7. Monitor access with CloudTrail.

Cost Optimisation

Pricing

  • $0.40 per secret per month
  • $0.05 per 10,000 API calls

Cost Saving Tips

  1. Combine related secrets in JSON objects
  1. Cache secrets in Lambda functions
  2. Use Parameter Store for non-sensitive config

Security Considerations

Secret Value Security

Access Patterns

Troubleshooting

Next Steps

KMS Key

Configure the customer-managed key that encrypts each secret.

IAM Role

Grant roles least-privilege read access to secrets.

RDS Instance

Manage database credentials with generated secrets.

ECS Cluster

Inject secrets into container tasks at runtime.