Secrets Manager, Parameter Store and AWS AppConfig for Developers: Secrets, Configuration and Feature Flags
Never Hard-Code Secrets
Secrets in Git or images get leaked. Passwords, API keys and tokens must not live in source code, container images, AMIs or plain environment variables checked into Git. Fetch them at runtime from a secure service using an IAM role.
| Service | Best for | Key features |
| AWS Secrets Manager | Database passwords, API keys, OAuth tokens that need rotation | Automatic rotation (Lambda), versioning, cross-Region replication, KMS encryption, resource policies, native RDS/Aurora/Redshift/DocumentDB rotation. Costs per secret per month + API calls |
| SSM Parameter Store | Configuration values and simple secrets | Free standard tier (up to 10,000 params, 4 KB each). Advanced tier (up to 8 KB, policies like expiration, more parameters, charges). String, StringList, **SecureString** (KMS). Hierarchies /app/prod/db/host. No built-in rotation |
| AWS AppConfig | Feature flags and runtime configuration deployed safely | Validators, gradual rollout, automatic rollback on CloudWatch alarm, caching agent/extension, works with Lambda, containers, EC2 |
Secrets Manager
python
import boto3, json
sm = boto3.client("secretsmanager")
sm.create_secret(Name="shop/db", SecretString=json.dumps({"username": "app", "password": "S3cret!x", "host": "db.example.internal"}))
val = sm.get_secret_value(SecretId="shop/db") # returns the AWSCURRENT version
creds = json.loads(val["SecretString"])
print(val["VersionId"], val["VersionStages"]) # ['AWSCURRENT']
| Concept | Meaning |
| Version stages | AWSCURRENT (in use), AWSPREVIOUS (last one), AWSPENDING (during rotation) |
| Rotation | A rotation Lambda has four steps: createSecret, setSecret (change it in the database), testSecret, finishSecret (move AWSCURRENT). AWS supplies ready templates for RDS. Set a schedule (for example every 30 days) |
| Replication | Copy a secret to other Regions for DR |
| Access control | IAM policy (secretsmanager:GetSecretValue), resource policy for cross-account, and kms:Decrypt if you use a customer managed key |
- Cache the secret in your function or app for a few minutes (or use the AWS Parameters and Secrets Lambda Extension) to reduce API calls, cost and latency
- After rotation, clients with cached old passwords fail. Handle
AccessDenied/authentication errors by refreshing the secret and retrying, or use the alternating-users rotation strategy
- In ECS, inject secrets with the
secrets field of the task definition
- RDS can manage the master password in Secrets Manager for you (
--manage-master-user-password)
Parameter Store
python
ssm = boto3.client("ssm")
ssm.put_parameter(Name="/shop/prod/db/host", Value="db.example.internal", Type="String", Overwrite=True)
ssm.put_parameter(Name="/shop/prod/api/key", Value="abc123", Type="SecureString", KeyId="alias/shop-app", Overwrite=True)
one = ssm.get_parameter(Name="/shop/prod/api/key", WithDecryption=True)["Parameter"]["Value"]
# Get everything under a path (paginate if many)
r = ssm.get_parameters_by_path(Path="/shop/prod/", Recursive=True, WithDecryption=True)
config = {p["Name"].split("/")[-1]: p["Value"] for p in r["Parameters"]}
- Use a hierarchy
/app/env/component/name and give roles access to a path in IAM: arn:aws:ssm:*:*:parameter/shop/prod/*
SecureString uses KMS. The caller needs ssm:GetParameter and kms:Decrypt
- Parameters keep version history and can be referenced from CloudFormation and Lambda environment variables (
{{resolve:ssm:/shop/prod/db/host}}) and public AWS parameters such as the latest AMI id
- Standard throughput is limited (default about 40 requests per second for
GetParameter; higher throughput can be enabled). Cache values
Secrets Manager vs Parameter Store
| Secrets Manager | Parameter Store |
| Primary use | Secrets that rotate | Configuration and simple secrets |
| Automatic rotation | Yes | No (you build it) |
| Cost | Per secret per month | Free standard tier |
| Max size | 64 KB | 4 KB (8 KB advanced) |
| Cross-account sharing | Resource policy supported | Advanced parameters can be shared via RAM |
| Cross-Region replication | Built in | Manual |
| Encryption | Always KMS | Optional (SecureString) |
Exam rule of thumb: 'Rotate database credentials automatically' → Secrets Manager. 'Cheapest way to store configuration or a secret' → Parameter Store. 'Roll out a feature or setting gradually with rollback' → AppConfig.
AWS AppConfig
AppConfig (part of Systems Manager) lets you change application behavior without deploying code. It validates configuration, rolls it out gradually, watches CloudWatch alarms, and rolls back automatically if they fire.
| Concept | Meaning |
| Application, environment, configuration profile | What app, where it runs (dev, prod), and where the data is (hosted store, S3, Parameter Store, Secrets Manager) |
| Feature flags profile | Boolean and attribute flags, targeting rules and variants |
| Validators | JSON Schema or a Lambda check before deployment |
| Deployment strategy | Example: AppConfig.Linear50PercentEvery30Seconds, canary, all at once, or custom (duration, growth, bake time during which alarms are watched) |
| Monitors | CloudWatch alarms that trigger rollback |
python
# Lambda: read configuration through the AppConfig Lambda extension (local HTTP cache, port 2772)
import json, urllib.request
def get_flags():
url = "http://localhost:2772/applications/shop/environments/prod/configurations/flags"
with urllib.request.urlopen(url) as r:
return json.loads(r.read())
def handler(event, context):
flags = get_flags()
if flags.get("new-checkout", {}).get("enabled"):
return {"path": "new"}
return {"path": "old"}
- The extension or agent caches configuration and polls for updates, so you do not call the AppConfig API on each request
- Use for feature flags, A/B limits, throttling values, allow lists and kill switches
- Compare: changing a Lambda environment variable requires a new deployment. AppConfig changes at runtime with safety checks
IAM Example for a Lambda Role
json
{
"Version": "2012-10-17",
"Statement": [
{"Effect": "Allow", "Action": "secretsmanager:GetSecretValue", "Resource": "arn:aws:secretsmanager:ap-south-1:111111111111:secret:shop/db-*"},
{"Effect": "Allow", "Action": ["ssm:GetParameter", "ssm:GetParametersByPath"], "Resource": "arn:aws:ssm:ap-south-1:111111111111:parameter/shop/prod/*"},
{"Effect": "Allow", "Action": "kms:Decrypt", "Resource": "arn:aws:kms:ap-south-1:111111111111:key/abcd-1234"},
{"Effect": "Allow", "Action": ["appconfig:GetLatestConfiguration", "appconfig:StartConfigurationSession"], "Resource": "*"}
]
}
Secret ARNs end with a random suffix, so use shop/db-* in policies.
Practice Tasks
- Store a database secret and read it from Lambda with caching
- Enable rotation for an RDS secret and watch the version stages change
- Create a Parameter Store hierarchy and load all parameters by path
- Create an AppConfig feature flag and roll it out linearly with an alarm monitor
- Remove
kms:Decrypt from the role and note the error you get
Conclusion
Never hard-code secrets. Use Secrets Manager for rotating credentials, Parameter Store for configuration and cheap secrets, and AppConfig for feature flags and safe runtime configuration rollouts. Grant least-privilege access with IAM (plus KMS decrypt), cache values, and handle rotation gracefully.
Quick Summary: no hard-coded secrets; service comparison; Secrets Manager; Parameter Store; compare table; AppConfig; IAM example.