Learn how to configure AWS resource tags for your Pika deployment to support cost allocation, resource organization, and compliance requirements.
What You'll Accomplish
Section titled “What You'll Accomplish”By the end of this guide, you will:
- Understand Pika's resource tagging system
- Configure tags in
pika-config.ts - Use dynamic placeholders for tag values
- Apply different tags to different stacks
- Customize tags programmatically
Prerequisites
Section titled “Prerequisites”- Pika project set up locally
- Basic understanding of AWS resource tags
- Familiarity with AWS CDK deployment
Understanding AWS Resource Tags
Section titled “Understanding AWS Resource Tags”AWS resource tags are key-value pairs that help you:
- Track costs: Allocate expenses by project, team, or environment
- Organize resources: Group related resources across services
- Implement governance: Enforce policies and access controls
- Enable automation: Target resources for scripts and operations
Pika's Tagging System
Section titled “Pika's Tagging System”Pika applies tags to all AWS resources in your CDK stacks using configuration from pika-config.ts.
Tag Categories
Section titled “Tag Categories”Tags are organized into three categories:
- Common tags - Applied to both Pika service and Pika Chat stacks
- Pika service tags - Applied only to backend stack (Lambda, DynamoDB, etc.)
- Pika Chat tags - Applied only to frontend stack (CloudFront, S3, etc.)
Special Resources: Inference Profiles
Section titled “Special Resources: Inference Profiles”Pika automatically creates named inference profiles for AWS Bedrock models to enable cost tracking. These inference profiles are also tagged with your stack tags (common + pikaServiceTags), plus an automatic component tag identifying the model.
Step 1: Configure Basic Tags
Section titled “Step 1: Configure Basic Tags”Edit your pika-config.ts file at the root of your project:
export const pikaConfig: PikaConfig = { pika: { // ... pika config }, pikaChat: { // ... pika chat config },
// Add resource tags stackTags: { common: { 'ManagedBy': 'Pika', 'Project': 'CustomerPortal', 'Team': 'Engineering' } }};These tags will be applied to all resources in both stacks.
Step 2: Use Dynamic Placeholders
Section titled “Step 2: Use Dynamic Placeholders”Pika supports dynamic placeholders that are replaced at CDK synth time:
Available Placeholders
Section titled “Available Placeholders”Deployment Context:
{stage}- Deployment stage (e.g., 'dev', 'prod'){timestamp}- Current timestamp (ISO 8601 format){accountId}- AWS account ID{region}- AWS region
Pika Service Project:
{pika.projNameL}- Project name (lowercase){pika.projNameKebabCase}- Project name (kebab-case){pika.projNameTitleCase}- Project name (TitleCase){pika.projNameCamel}- Project name (camelCase){pika.projNameHuman}- Project name (human-readable)
Pika Chat Project:
{pikaChat.projNameL}- Project name (lowercase){pikaChat.projNameKebabCase}- Project name (kebab-case){pikaChat.projNameTitleCase}- Project name (TitleCase){pikaChat.projNameCamel}- Project name (camelCase){pikaChat.projNameHuman}- Project name (human-readable)
Example with Placeholders
Section titled “Example with Placeholders”stackTags: { common: { 'app': 'pika', 'env': '{stage}', 'DeployedAt': '{timestamp}', 'AccountId': '{accountId}', 'Region': '{region}' }}Result when deployed to prod:
{ 'app': 'pika', 'env': 'prod', 'DeployedAt': '2025-01-15T10:30:00Z', 'AccountId': '123456789012', 'Region': 'us-east-1'}Step 3: Stack-Specific Tags
Section titled “Step 3: Stack-Specific Tags”Apply different tags to backend vs frontend stacks:
stackTags: { // Applied to both stacks common: { 'app': 'pika', 'env': '{stage}', 'Owner': 'platform-team@example.com' },
// Additional tags for Pika service stack only pikaServiceTags: { 'component': '{pika.projNameKebabCase}', 'type': 'backend', 'monitoring': 'datadog' },
// Additional tags for Pika Chat stack only pikaChatTags: { 'component': '{pikaChat.projNameKebabCase}', 'type': 'frontend', 'cdn': 'cloudfront' }}Step 4: Programmatic Customization
Section titled “Step 4: Programmatic Customization”For advanced scenarios, customize tags programmatically using CDK hooks.
Pika Service Stack
Section titled “Pika Service Stack”Edit services/pika/lib/stacks/custom-stack-defs.ts:
export class CustomStackDefs { /** * Modify tags before they are applied to the Pika service stack */ modifyStackTags(tags: Record<string, string>, stage: string): Record<string, string> { // Add custom logic const modifiedTags = { ...tags, 'CustomTag': 'CustomValue', 'Stage': stage.toUpperCase(), };
// Conditional tagging if (stage === 'prod') { modifiedTags['Backup'] = 'daily'; modifiedTags['CostCenter'] = 'production-ops'; }
return modifiedTags; }}Pika Chat Stack
Section titled “Pika Chat Stack”For Pika Chat, you can modify apps/pika-chat/infra/bin/pika-chat.ts directly in the applyStackTags function.
Common Patterns
Section titled “Common Patterns”Cost Allocation Tags
Section titled “Cost Allocation Tags”Track costs by project and environment:
stackTags: { common: { 'CostCenter': 'engineering', 'Project': 'CustomerPortal', 'Environment': '{stage}', 'Owner': 'team-platform@example.com' }}Compliance Tags
Section titled “Compliance Tags”Meet regulatory requirements:
stackTags: { common: { 'Compliance': 'HIPAA', 'DataClassification': 'Confidential', 'BackupRequired': 'true', 'EncryptionRequired': 'true' }}Multi-Team Organization
Section titled “Multi-Team Organization”Organize resources by team:
stackTags: { common: { 'Team': 'platform', 'Product': 'CustomerPortal', 'Environment': '{stage}' }, pikaServiceTags: { 'Subteam': 'backend', 'ServiceOwner': 'backend-team@example.com' }, pikaChatTags: { 'Subteam': 'frontend', 'ServiceOwner': 'frontend-team@example.com' }}Automation Tags
Section titled “Automation Tags”Enable automated operations:
stackTags: { common: { 'AutoShutdown': stage === 'dev' ? 'true' : 'false', 'BackupSchedule': stage === 'prod' ? 'daily' : 'weekly', 'MonitoringLevel': stage === 'prod' ? 'critical' : 'standard' }}Tag Validation
Section titled “Tag Validation”Pika automatically validates tags and warns about:
- Empty keys or values - Tags must have non-empty keys and values
- Invalid characters - AWS tag keys and values have character restrictions
- Tag limits - AWS has limits on number of tags per resource
Check console output during deployment for validation warnings:
pnpm run cdk:deploy
# Output:# Applied 5 tag(s) to stack PikaServiceStack-prod# Applied 6 tag(s) to stack PikaChatStack-prodVerify Tags in AWS Console
Section titled “Verify Tags in AWS Console”After deployment, verify tags are applied:
Using AWS Console
Section titled “Using AWS Console”- Navigate to any resource (Lambda function, S3 bucket, etc.)
- Go to the Tags tab
- Verify your configured tags are present
Using AWS CLI
Section titled “Using AWS CLI”# List tags for a Lambda functionaws lambda list-tags --resource arn:aws:lambda:REGION:ACCOUNT:function:FUNCTION_NAME
# List tags for an S3 bucketaws s3api get-bucket-tagging --bucket BUCKET_NAME
# List tags for a DynamoDB tableaws dynamodb list-tags-of-resource --resource-arn TABLE_ARNAWS Tag Best Practices
Section titled “AWS Tag Best Practices”Follow AWS tagging best practices:
- Use consistent naming: Establish a naming convention
- Document your strategy: Maintain a tagging strategy document
- Automate tagging: Use Pika's placeholders and hooks
- Review regularly: Audit tags periodically
- Enable cost allocation: Activate cost allocation tags in AWS Billing
Recommended Tag Keys
Section titled “Recommended Tag Keys”Common tag keys used across AWS:
Environment/env- Deployment environmentProject- Project nameOwner- Team or individual responsibleCostCenter- For financial trackingName- Resource name (often auto-generated)Application/app- Application identifierManagedBy- Management tool (e.g., "Pika", "Terraform")
Troubleshooting
Section titled “Troubleshooting”Tags Not Appearing
Section titled “Tags Not Appearing”Problem: Tags configured but not showing on resources
Solutions:
- Verify
stackTagssection exists inpika-config.ts - Check console output for tag application messages
- Ensure CDK deployment completed successfully
- Some resources may not support tags (check AWS docs)
Placeholder Not Replaced
Section titled “Placeholder Not Replaced”Problem: Placeholder like {stage} appears literally in tag value
Solutions:
- Verify placeholder syntax is correct
- Check that deployment includes required context (stage, etc.)
- Review console output for interpolation errors
Tag Limit Exceeded
Section titled “Tag Limit Exceeded”Problem: AWS rejects resources due to too many tags
Solutions:
- AWS allows up to 50 tags per resource
- Reduce number of tags in configuration
- Prioritize most important tags
Complete Example
Section titled “Complete Example”Here's a production-ready tagging configuration:
export const pikaConfig: PikaConfig = { pika: { projNameL: 'customer-portal-api', // ... rest of config }, pikaChat: { projNameL: 'customer-portal-web', // ... rest of config },
stackTags: { // Applied to all resources common: { 'Application': 'CustomerPortal', 'ManagedBy': 'Pika', 'Environment': '{stage}', 'CostCenter': 'engineering', 'Owner': 'platform-team@example.com', 'Project': 'CustomerPortal', 'DeployedAt': '{timestamp}', 'Region': '{region}' },
// Backend-specific tags pikaServiceTags: { 'Component': '{pika.projNameKebabCase}', 'Type': 'api', 'Runtime': 'nodejs22', 'MonitoringDashboard': 'https://monitoring.example.com/pika-service' },
// Frontend-specific tags pikaChatTags: { 'Component': '{pikaChat.projNameKebabCase}', 'Type': 'webapp', 'CDN': 'CloudFront', 'MonitoringDashboard': 'https://monitoring.example.com/pika-chat' } }};Next Steps
Section titled “Next Steps”- Deploy to AWS with CDK - Deploy your tagged infrastructure
- Track AI Model Costs - Use tags to analyze AI model costs in Cost Explorer
- Platform Settings Configuration - Configure other platform settings
- Stack Configuration Reference - Complete stackTags reference
See Also
Section titled “See Also”- Inference Profile Names - How Pika names inference profiles for cost tracking
- AWS Tagging Strategies - AWS official guide
- Cost Allocation Tags - Enable cost tracking
- CDK Tags - AWS CDK tagging documentation