TikTok API (SKYN-7200) – AWS Secrets Manager¶
Application settings are loaded at import from AWS Secrets Manager using the shared
frontstory/fs_config package. The app reads
MySQL and admin API keys from secrets; S3 uses the instance/task IAM role
only (no access keys). Bucket names stay in config/cfg.py per environment.
Runtime¶
Set ENVIRONMENT to prd or stg (same path segment as in secret names). If unset, the
app defaults to prd so production deploys do not hit missing-config errors.
| Deploy target | ENVIRONMENT |
|---|---|
| Production | prd (default when variable omitted) |
| Staging | stg |
Docker Compose and CodeDeploy after_install can set /srv/tiktok-api/.env. For local
development, set ENVIRONMENT=stg (see .env.example).
Required secrets¶
All secrets must store valid JSON in SecretString.
1. Staging MySQL – /stg/mysql/tiktok¶
Shape:
{
"host": "<staging-mysql-host>",
"port": 3306,
"user": "<user>",
"password": "<password>",
"database": "tiktok"
}
2. Production MySQL – /prd/mysql/tiktok¶
Same keys as staging, production host/user/password.
3. Staging admin keys – /stg/tiktok-api/admin-api-keys¶
{
"get_key": "<value-for-GET-admin-routes>",
"post_key": "<value-for-POST-admin-routes>"
}
4. Production admin keys – /prd/tiktok-api/admin-api-keys¶
Same shape as staging, production values.
IAM¶
The TikTok API task/instance role must allow:
secretsmanager:GetSecretValueon the four secret ARNs (or onarn:aws:secretsmanager:<region>:<account>:secret:/stg/*and.../prd/*if you use a path-based resource policy).- Existing S3 permissions for
assets-stg.dadsnews.com/assets-prd.dadsnews.comvia role (no staticAKIAkeys).
Developers authenticate with AWS credentials or SSO that can call GetSecretValue on
staging secrets only (least privilege).
Docker builds and private fs_config¶
Same pattern as skynet-provider-api (spapi) in this org: requirements.txt uses
git+https://x-access-token:<PAT>@github.com/frontstory/fs_config.git@master so pip inside
docker build can clone without an interactive login. The Dockerfile installs git for that
install step. Rotate the PAT if it leaks; match the token used across other repos if you keep one
org-wide read token.
Populating secrets (manual CLI)¶
Replace placeholders; do not commit real values into git.
Staging MySQL
aws secretsmanager create-secret \
--name /stg/mysql/tiktok \
--secret-string '{"host":"HOST","port":3306,"user":"USER","password":"PASS","database":"tiktok"}' \
--region us-east-1
Production MySQL
aws secretsmanager create-secret \
--name /prd/mysql/tiktok \
--secret-string '{"host":"HOST","port":3306,"user":"USER","password":"PASS","database":"tiktok"}' \
--region us-east-1
Staging admin keys
aws secretsmanager create-secret \
--name /stg/tiktok-api/admin-api-keys \
--secret-string '{"get_key":"...","post_key":"..."}' \
--region us-east-1
Production admin keys
aws secretsmanager create-secret \
--name /prd/tiktok-api/admin-api-keys \
--secret-string '{"get_key":"...","post_key":"..."}' \
--region us-east-1
If a secret name already exists, create-secret fails; delete the secret in the AWS console
(or use a one-off put-secret-value from AWS CLI help) to change an existing value.
AWS CLI notes¶
- Use
create-secret --name <path>(not--secret-id). Example names:/stg/mysql/tiktok. SecretStringmust be valid JSON matching the shapes above.
Scripted provisioning¶
Use scripts/provision_tiktok_api_secrets.sh with environment variables set in your
shell (or a private, non-committed env file you source). The script never embeds
secrets in the repo; values only exist in your session when you run it.
See comments at the top of scripts/provision_tiktok_api_secrets.sh for the variable list.
Migrating from old cfg-*.py¶
Values previously in config/cfg-stg.py and config/cfg-prd.py map as follows:
MYSQL_SETTINGS→/stg|prd/mysql/tiktokADMIN_API_KEY_GET/ADMIN_API_KEY_POST→get_key/post_keyin/stg|prd/tiktok-api/admin-api-keys- S3: remove keys from app config; ensure IAM role can access the correct bucket; bucket
names remain in
config/cfg.py(S3_BY_ENV).
For a one-time copy-paste literal migration file (not for git), see
docs/SKYN-7200-secret-paste-values.local.md on your machine (it is gitignored if you
create it from this branch’s template). Delete it after creating the secrets in AWS.
After secrets exist in AWS and IAM is wired, deploy this branch; rotate any credentials that were ever committed to git.