Skip to content

Environment Variables

Complete reference for environment variables used to configure Pika Platform at runtime.

Pika Platform uses environment variables for:

  • AWS configuration
  • Service endpoints
  • Authentication secrets
  • Feature toggles
  • Development vs production settings
VariableTypeDescriptionExample
AWS_REGIONstringAWS region for deploymentus-east-1
AWS_ACCOUNTstringAWS account ID (optional, auto-detected if not set)123456789012
VariableTypeDescriptionExample
WEBAPP_URLstringRequired. Full URL of the web app including porthttps://chat.example.com or http://localhost:3000
PIKA_S3_BUCKETstringRequired. S3 bucket for file uploads and storagemy-company-pika-files
STAGEstringRequired. Deployment stagedev, staging, prod
ENVstringRequired. Environment name (usually same as STAGE)dev, staging, prod
VariableTypeDescriptionExample
CHAT_API_IDstringRequired. API Gateway ID for chat APIabc123def456
CHAT_ADMIN_API_IDstringRequired. API Gateway ID for admin APIxyz789uvw012
CONVERSE_FUNCTION_URLstringRequired. Lambda function URL for converse APIhttps://xxx.lambda-url.us-east-1.on.aws/
VariableTypeDescriptionExample
TAG_DEFINITIONS_TABLEstringRequired. DynamoDB table name for tag definitionspika-dev-tag-definitions
VariableTypeDescriptionExample
PIKA_SERVICE_PROJ_NAME_KEBAB_CASEstringRequired. Pika service project namemy-company
PIKA_CHAT_PROJ_NAME_KEBAB_CASEstringRequired. Pika chat project namemy-company-chat
VariableTypeDescriptionExample
KMS_COOKIE_KEY_ALIASstringAuto-generated. KMS key alias for cookie encryptionalias/my-company-chat-dev
KEY_REFRESH_INTERVAL_HOURSnumberAuto-set. Hours between key rotations24
MAX_KEY_VERSIONSnumberAuto-set. Maximum key versions to maintain3
COOKIE_MAX_AGE_HOURSnumberAuto-set. Cookie expiration in hours72

The system automatically retrieves:

  • jwtSecret from SSM Parameter Store path: /pika/{projectName}/{stage}/jwt-secret
VariableTypeDefaultDescription
DEBUGstring-Enable debug logging (e.g., pika:*)
PIKA_DEBUGbooleanfalseEnable Pika-specific debug output
NODE_ENVstringproductionNode environment (development, production)

Feature flags are typically configured in pika-config.ts rather than environment variables. However, you can override them for specific deployments:

VariableTypeDescription
DISABLE_TRACESbooleanDisable traces feature
DISABLE_USER_MEMORYbooleanDisable user memory feature
DISABLE_INSIGHTSbooleanDisable session insights
.env.local
# For local development only
# AWS Configuration
AWS_REGION=us-east-1
AWS_PROFILE=my-profile # Optional: AWS CLI profile to use
# Chat App
WEBAPP_URL=http://localhost:3000
STAGE=local
ENV=local
# Will be set by CDK outputs after first deployment:
# PIKA_S3_BUCKET=my-company-pika-local-files
# CHAT_API_ID=abc123
# CHAT_ADMIN_API_ID=xyz789
# CONVERSE_FUNCTION_URL=https://...
# TAG_DEFINITIONS_TABLE=pika-local-tag-definitions
# Project Names (from pika-config.ts)
PIKA_SERVICE_PROJ_NAME_KEBAB_CASE=my-company
PIKA_CHAT_PROJ_NAME_KEBAB_CASE=my-company-chat
# Development
DEBUG=pika:*
NODE_ENV=development

In production, environment variables are typically set by:

  1. AWS CDK - Most variables are automatically configured by the CDK stack
  2. ECS Task Definition - For container-based deployments
  3. Lambda Environment - For serverless functions
  4. Systems Manager Parameter Store - For secrets and sensitive config

The following variables are automatically set by CDK during deployment:

// From PikaChatConstruct
const environmentVariables = {
STAGE: props.stage,
ENV: props.stage,
AWS_REGION: cdk.Aws.REGION,
AWS_ACCOUNT_ID: cdk.Aws.ACCOUNT_ID,
CHAT_API_ID: apiId,
CHAT_ADMIN_API_ID: chatAdminApiId,
WEBAPP_URL: props.domainName ? `https://${props.domainName}` : 'unknown',
PIKA_S3_BUCKET: pikaS3Bucket,
CONVERSE_FUNCTION_URL: converseFnUrl,
TAG_DEFINITIONS_TABLE: tagDefinitionsTableName,
PIKA_SERVICE_PROJ_NAME_KEBAB_CASE: props.pikaServiceProjNameKebabCase,
PIKA_CHAT_PROJ_NAME_KEBAB_CASE: props.projNameKebabCase,
KMS_COOKIE_KEY_ALIAS: generateKmsKeyAliasName(props.projNameKebabCase, props.stage),
KEY_REFRESH_INTERVAL_HOURS: '24',
MAX_KEY_VERSIONS: '3',
COOKIE_MAX_AGE_HOURS: '72'
};

Pika Platform loads environment variables in this order (later sources override earlier ones):

  1. Default system environment
  2. .env file (if present)
  3. .env.local file (if present, git-ignored)
  4. .env.{STAGE} file (e.g., .env.prod)
  5. Explicit environment variables from deployment system

The application validates required environment variables at startup. If any required variable is missing, the application will fail to start with a clear error message:

Error: Environment variable AWS_REGION is not set.

❌ Do not store these as environment variables:

  • JWT secrets (use Parameter Store)
  • Database passwords (use Secrets Manager)
  • API keys for external services (use Secrets Manager)
  • OAuth client secrets (use Secrets Manager)

✅ These are safe as environment variables:

  • AWS region
  • Service URLs
  • Feature flags
  • Non-sensitive configuration
import { getFromEnv } from 'pika-shared/util/server-utils';
// Required variable (throws if missing)
const region = getFromEnv('AWS_REGION');
// Optional variable with default
const debug = getFromEnv('DEBUG', 'false');
const stage = process.env.STAGE || 'dev';
const awsRegion = process.env.AWS_REGION || 'us-east-1';
import { SSMClient, GetParameterCommand } from '@aws-sdk/client-ssm';
const ssmClient = new SSMClient({ region: process.env.AWS_REGION });
const response = await ssmClient.send(
new GetParameterCommand({
Name: `/pika/${projectName}/${stage}/jwt-secret`,
WithDecryption: true
})
);
const jwtSecret = response.Parameter?.Value;

Error: Environment variable AWS_REGION is not set

Solution: Set AWS_REGION in your environment or .env file:

Terminal window
export AWS_REGION=us-east-1
# or
AWS_REGION=us-east-1 pnpm dev

Error: Authentication redirects fail or cookies don't work

Solution: Ensure WEBAPP_URL matches exactly how users access your app:

  • Local: http://localhost:3000 (no trailing slash)
  • Production: https://chat.example.com (no trailing slash)

Error: CHAT_API_ID or other API variables not set

Solution: These are set by CDK after deployment. Either:

  1. Deploy the stack first: cd services/pika && cdk deploy
  2. Copy values from AWS Console to your .env.local file

The complete AppConfig interface that loads these environment variables:

interface AppConfig {
isLocal: boolean; // Auto-detected
awsRegion: string; // From AWS_REGION
awsAccount: string; // From AWS_ACCOUNT or auto-detected
redirectCallbackUriPath: string; // Hardcoded in config
jwtSecret: string; // Retrieved from SSM at runtime
webappUrl: string; // From WEBAPP_URL
pikaS3Bucket: string; // From PIKA_S3_BUCKET
stage: string; // From STAGE
chatApiId: string; // From CHAT_API_ID
chatAdminApiId: string; // From CHAT_ADMIN_API_ID
converseFunctionUrl: string; // From CONVERSE_FUNCTION_URL
tagDefinitionsTable: string; // From TAG_DEFINITIONS_TABLE
// ... additional fields
}