Security · Topic 4 of 6

Secrets and Sensitive Data

Keep secrets out of code with Secrets Manager and Parameter Store, and find, mask and limit access to PII and PHI with Macie, Comprehend and policies.

  • 4 min
In a nutshell
  • Never store secrets in code, source control or images.
  • Secrets Manager rotates secrets and shares them across accounts. Parameter Store does not rotate.
  • SecureString parameters and Secrets Manager secrets both use KMS, so the caller may also need kms:Decrypt.

What it is

Sensitive data comes in two forms. Secrets are credentials your application uses, such as database passwords, API keys and tokens. Sensitive data is information about people, such as personally identifiable information (PII) and protected health information (PHI).

For secrets, the rule is never to put them in code, environment files or container images. For sensitive data, you find it, mask or redact it, and limit who can read it.

Appneeds a passwordGetSecretValueSecrets Managerchecks IAM and KMSreturns secretAppuses it in memory

How it works

Secrets Manager and Parameter Store

FeatureAWS Secrets ManagerSystems Manager Parameter Store
Built forCredentials and API keysConfiguration values and some secrets
Automatic rotationYes, with a Lambda functionNo built in rotation
EncryptionAlways with KMSSecureString type uses KMS
Cross account sharingResource policy on the secretNot supported for standard parameters
Cost modelCharged per secretStandard parameters are free

Pick Secrets Manager when the question says rotate, or mentions database credentials. Pick Parameter Store for plain configuration, or when the least cost is the goal.

Secrets Manager details:

  • Your code calls GetSecretValue. The role needs secretsmanager:GetSecretValue, plus kms:Decrypt if the secret uses a customer managed key.
  • Rotation runs a Lambda function. Secrets Manager provides ready made rotation functions for supported Amazon RDS databases.
  • Versions carry staging labels. AWSCURRENT is the live value and AWSPREVIOUS is the one before it.
  • Caching the secret in your code (with the AWS provided caching components) cuts latency and API calls.
  • A resource policy lets another account read the secret, and the secret must then use a customer managed key that the other account can use.

Parameter Store details:

  • Types are String, StringList and SecureString.
  • Call GetParameter with WithDecryption set to true to read a SecureString. The caller needs KMS permission as well.
  • Parameters use a hierarchy such as /app/prod/db/host, and a policy can grant access to a whole path.

Lambda and ECS can also inject secrets into the environment, but a secret placed in a plain environment variable is visible to anything that reads the configuration. Fetching at run time is safer.

Finding and masking sensitive data

  • Amazon Macie scans S3 buckets and reports sensitive data such as PII and credentials. It finds data; it does not block access.
  • Amazon Comprehend detects PII in text. DetectPiiEntities returns each entity type with its position, so your code can replace it. A PII redaction job masks documents in bulk.
  • Amazon CloudWatch Logs data protection policies audit and mask matching values in log events. Only principals with logs:Unmask see the originals. Masking applies to events ingested after the policy is set.
  • Amazon Bedrock Guardrails can block or mask PII in model prompts and responses (covered later in this chapter).
  • CloudFront field level encryption encrypts chosen form fields at the edge with a public key, so only the service holding the private key can read them.

Limiting access

Masking is not enough on its own. Combine it with least privilege.

  • Allow s3:GetObject only on the prefix that holds the data, and use S3 access points to give each application its own entry point and policy.
  • Encrypt with a customer managed KMS key whose key policy lists the few roles that may decrypt.
  • Store only the fields you need. Tokenize or hash identifiers when the original value is not required.
  • Keep sensitive values out of logs, error messages and URLs.

How the exam asks about this

  • "Database credentials must rotate every 30 days with the least operational overhead" -> Secrets Manager with automatic rotation.
  • "An application needs a plain configuration value at the lowest cost" -> Parameter Store standard parameter.
  • "Find which S3 buckets contain PII" -> Amazon Macie.
  • "Log events must not reveal credit card numbers" -> a CloudWatch Logs data protection policy.

What to remember for the exam

  • Never store secrets in code, source control or images.
  • Secrets Manager rotates secrets and shares them across accounts. Parameter Store does not rotate.
  • SecureString parameters and Secrets Manager secrets both use KMS, so the caller may also need kms:Decrypt.
  • Macie discovers sensitive data in S3. Comprehend detects PII in text. CloudWatch Logs data protection masks log events.
  • Only roles with logs:Unmask can see masked log values.
  • Limit access with prefix level policies, access points and key policies.
Watch out

Force deleting a secret without a recovery window removes it immediately. Keep the recovery window so a mistake can be undone.

Common mistakes

Choosing Parameter Store when rotation is required. Parameter Store has no built in rotation. Use Secrets Manager.

Reading the secret once at import time and never again. After rotation the cached value is stale. Fetch on use or refresh the cache.

Expecting Macie to protect the data. Macie reports findings. You still need policies, encryption and masking to protect the objects.

Check yourself

  • Which service rotates database credentials automatically?

    AWS Secrets Manager, using a rotation Lambda function.

  • What extra permission does a function need to read a SecureString parameter?

    kms:Decrypt on the key that encrypts it, in addition to ssm:GetParameter.

  • How can you stop most users from seeing card numbers in CloudWatch Logs?

    Add a data protection policy that masks the data identifier. Only principals with logs:Unmask see the original.

Topic 4 of 6 in Security

Test yourself on Security

The full AWS DVA-C03 question bank has 850 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by AWS. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.