Skip to main content
When using external services (AWS S3, OpenAI, etc.) in Sonamu projects, API keys are managed as environment variables. This guide explains how to securely store them without hardcoding in your code.
API keys should never be committed to Git! If leaked, immediately invalidate and reissue the keys.

Common API Keys

These are frequently used external service API keys in Sonamu.

AWS (S3 Storage)

.env
sonamu.config.ts:

OpenAI

.env
Usage example:

Optional External Service Integrations

Sonamu can integrate with various external services. Below are environment variable examples for commonly used services.
These services are not part of Sonamu’s default configuration. Add them only when needed for your project.

Environment-Specific Key Management

Never use production keys in development environments! Use separate keys for each environment.
.env.development
Characteristics:
  • Uses test mode keys
  • No or minimal charges
  • Limited permissions

Creating AWS IAM User

Access IAM Console

Create User

  1. Users → Add users 2. User name: sonamu-s3-user 3. Access type: Select Programmatic access

Set Permissions

Option 1: Attach Existing Policy
Option 2: Custom Policy (recommended)
sonamu-s3-policy.json
Enhance security by allowing only specific buckets and actions.

Issue Access Keys

After user creation completes:
  • Access key ID: your-aws-access-key-id
  • Secret access key: your-aws-secret-access-key
The secret access key is displayed only once! Save it to a secure location immediately.

Add to .env File

Issuing OpenAI API Key

Access OpenAI Platform

Create API Key

  1. API keys → Create new secret key 2. Name: sonamu-production 3. Permissions: All or Restricted (recommended)

Set Usage Limits

Settings → Billing → Set Usage limits
Unexpected charges may occur if you don’t set usage limits!

Save Key

Save to a secure location immediately after issuance (cannot be viewed again)

Security Best Practices

Regular Key Replacement

Recommended Frequency:
  • Production: Every 3 months
  • Staging: Every 6 months
  • Development: Yearly or as needed

Rotation Procedure

1

Create New Key

Create a new key while keeping the existing one active.
2

Deploy New Key

3

Monitor

Verify it works without errors for 24 hours
4

Delete Old Key

Deactivate/delete the old key if no issues
To perform key rotation without downtime, use a blue-green approach that maintains both new and old keys simultaneously.

Minimize IAM Policies

Separate Read-Only Keys

Immediate Actions

Invalidate Key Immediately

Issue and Deploy New Key

Issue a new key immediately and deploy to production

Check Usage History

Clean Git History

Cleaning Git history affects collaborating team members. Coordinate with your team before proceeding.

Leak Detection Tools

Development Environment

Production Environment

AWS Systems Manager Parameter Store:
HashiCorp Vault:

Key Usage Monitoring

AWS CloudWatch

OpenAI Usage Alerts

Test Environment Key Management

Use mocks in tests to avoid calling actual APIs. This reduces test costs and improves speed.

Troubleshooting

Symptoms:
Causes:
  1. Incorrect Access Key ID
  2. Key has been deleted or deactivated
  3. Typos (spaces, line breaks)
Solution:
Symptoms:
Causes:
  • API request limit exceeded (RPM, TPM)
Solution:
Symptoms:
Causes:
  • IAM policy missing required permissions
  • Blocked by bucket policy
Solution:

Next Steps

.env Setup

Learn environment variable basics

Database Credentials

Safely manage DB connection information

Storage Configuration

Configure S3 storage

Session Settings

Check session and security settings