Configuration and secrets
Configuration has three layers:
-
samconfig.tomlpicks the stack, the environment and whether triggers are on. -
template.yaml, mappingEnvironmentSettings, holds per-environment values and passes them to every function as environment variables. -
The
common/crmsecret in Secrets Manager holds credentials. It is shared with other applications.
Changing any of them is a pull request; the deploy workflow applies it.
samconfig.toml
| Setting | [dev] |
[prod] |
|---|---|---|
|
|
|
|
|
|
|
|
|
Both deploy to us-east-1 with resolve_s3 = true (the SAM managed artifact bucket) and
CAPABILITY_IAM. [dev.local_start_api] sets EnableTriggers=false for make run-local.
EnableTriggers
EnableTriggers controls every event consumer of the stack:
| Resource | true |
false |
|---|---|---|
Kinesis event source mapping |
created |
not created |
CRM SNS subscription and invoke permission |
created |
not created |
Watchdog schedule |
|
|
|
serves requests |
serves requests |
stateDiagram-v2
direction LR
Dark: EnableTriggers=false (API only)
Live: EnableTriggers=true (API + consumers)
[*] --> Dark: first deploy
Dark --> Live: old consumers stopped, start position set
Live --> Dark: rollback
Turn it on only once the deployment it replaces no longer consumes the same sources. Otherwise every rule action runs twice. See Zappa to SAM cutover.
Kinesis start position
EnvironmentSettings sets KinesisStartingPosition (LATEST, AT_TIMESTAMP or TRIM_HORIZON) and
KinesisStartingTimestamp (Unix seconds, used with AT_TIMESTAMP). They are read only when the mapping is
created, that is when EnableTriggers goes from false to true.
|
Don’t change them while the mapping exists. The change replaces the mapping, and Lambda allows only one
mapping per function and stream, so the deploy fails and rolls back. To restart at another position, deploy
with |
Environment variables
Set on every function from EnvironmentSettings:
| Variable | Production | Staging |
|---|---|---|
|
|
|
|
|
empty |
|
||
|
staging action tools API |
|
|
staging messaging API |
|
|
staging EventLogger API |
|
|
|
|
|
empty (search off) |
empty (search off) |
|
|
|
|
|
|
|
shared DSN |
shared DSN |
|
|
|
settings.get_settings() reads them once per process. Trailing slashes on URLs are optional.
The common/crm secret
settings.get_secret(key) reads a key from common/crm. With AWS_SECRETS_MANAGER=False (local
development, tests), pyb-flask-utils reads the same key from an environment variable instead.
| Key | Used for |
|---|---|
|
Verifying RSA-signed JWTs on |
|
Calling the internal API and the action tools API |
|
EventLogger key of instance 8001, used for CRM events by |
|
Segment analytics |
|
Optional; overrides the environment variable of the same name |
The secret is cached per process, so a new value reaches a function on its next cold start.
put-secret-value replaces the whole secret; merge new keys into the current value instead. The command is
in the cutover runbook.