AWS Secrets Manager

Parameter Store already encrypts things. The reason Secrets Manager exists is the verb rotate — generating a new credential, changing it at the database, and swapping it in without breaking live callers. Everything on this page hangs off that.

Parameter Store đã mã hoá được rồi. Lý do Secrets Manager tồn tại là động từ rotate — sinh credential mới, đổi nó ở phía database, và tráo vào mà không làm gãy caller đang chạy. Mọi thứ trong trang này treo vào đó.

The rotation loopVòng rotation

Four steps, always the same four, whether the code is yours or AWS's. What makes rotation hard — and what Parameter Store can't do — is step 2: something has to log into the database and actually change the password there. Bốn bước, luôn là bốn bước đó, dù code là của bạn hay của AWS. Cái làm rotation khó — và là cái Parameter Store không làm được — là bước 2: phải có thứ gì đó đăng nhập vào database và thật sự đổi password ở đó.

The four-step Secrets Manager rotation cycle. A rotation schedule fires, for example every ninety days, and invokes the rotation function four times. Step one, createSecret, generates a new password and stores it as a new version labelled AWSPENDING. Step two, setSecret, logs into the database and changes the password there. Step three, testSecret, connects using the pending credential to prove it works. Step four, finishSecret, moves the AWSCURRENT label onto the new version, and the old version becomes AWSPREVIOUS. A note explains that step two is the step Parameter Store cannot do, and that managed rotation removes the Lambda because the database service performs all four steps itself. RotationSchedule every 90 days rotation function invoked 4× per rotation ① createSecret generate a new password → version: AWSPENDING ② setSecret log in to the DB and change the password there ③ testSecret connect with AWSPENDING to prove it works ④ finishSecret move AWSCURRENT over old one → AWSPREVIOUS step ② is exactly what Parameter Store cannot do — it stores a string, it has no idea how to talk to MySQL managed rotation (ManageMasterUserPassword) = RDS runs all four steps itself, no Lambda in the picture at all apps must re-read the secret after ④ — cache it, but with a TTL, or catch the auth error and refetch single-user strategy: brief window between ② and ④ where a stale cached credential fails · alternating-users avoids it

The staging labels are the whole trick: the secret holds several versions at once and rotation is just relabelling. That's also why AWSPREVIOUS exists — a bad rotation can be rolled back by moving the label back.

Staging label chính là mẹo của toàn bộ chuyện này: secret giữ nhiều version cùng lúc và rotation chỉ là dán lại nhãn. Đó cũng là lý do có AWSPREVIOUS — một lần rotate hỏng có thể quay lại bằng cách dịch nhãn về.

Secrets Manager vs Parameter StoreSecrets Manager vs Parameter Store

Secrets Manager Parameter Store (SecureString)(SecureString)
KMS encryption at restMã hoá at rest bằng KMS ✓ ✓
Generate a strong random passwordSinh password ngẫu nhiên mạnh ✓ GetRandomPassword ✗
Native rotation scheduleLịch rotation native ✓ RotationSchedule ✗ — build it yourself with EventBridge + Lambda✗ — tự dựng bằng EventBridge + Lambda
Knows how to change the password in RDS/Redshift/DocumentDBBiết cách đổi password trong RDS/Redshift/DocumentDB ✓ ✗
Cross-Region replication of the valueNhân bản giá trị sang Region khác ✓ built incó sẵn ✗ — copy it yourself✗ — tự copy
Resource policy for cross-accountResource policy cho cross-account ✓ ✗ (advanced tier has policies, but not cross-account sharing)✗ (tier advanced có policy, nhưng không share cross-account)
CostChi phí per secret / month + API callstheo secret / tháng + API call free at standard tiermiễn phí ở tier standard
Reach for it whenDùng khi DB credentials · API keys that must rotateCredential DB · API key phải xoay Config: endpoints, feature flags, AMI IDs, licence stringsConfig: endpoint, feature flag, AMI ID, chuỗi licence
Parameter Store can read a secretParameter Store đọc được secret SSM can proxy to Secrets Manager with the path /aws/reference/secretsmanager/<secret-name>, so code that already speaks Parameter Store doesn't need rewriting. Useful in real life; rarely the point of an exam question. SSM có thể proxy sang Secrets Manager bằng đường dẫn /aws/reference/secretsmanager/<secret-name>, nên code đã nói chuyện với Parameter Store không phải viết lại. Hữu ích ngoài đời; hiếm khi là trọng tâm câu hỏi thi.

Rotation in CloudFormationRotation trong CloudFormation

"Create a Lambda function to rotate the password" sounds like writing code. It usually isn't — CloudFormation can attach an AWS-hosted rotation Lambda for the common database types with a few lines. "Tạo Lambda function để xoay password" nghe như phải viết code. Thường thì không — CloudFormation có thể gắn rotation Lambda do AWS host cho các loại database phổ biến chỉ với vài dòng.

DbSecret:
  Type: AWS::SecretsManager::Secret
  Properties:
    GenerateSecretString:            # sinh password mạnh, không hard-code
      SecretStringTemplate: '{"username":"admin"}'
      GenerateStringKey: password
      ExcludeCharacters: '"@/\'

SecretAttachment:                    # nối secret ↔ DB instance
  Type: AWS::SecretsManager::SecretTargetAttachment
  Properties:
    SecretId: !Ref DbSecret
    TargetId: !Ref Database
    TargetType: AWS::RDS::DBInstance

Rotation:
  Type: AWS::SecretsManager::RotationSchedule
  Properties:
    SecretId: !Ref DbSecret
    HostedRotationLambda:            # AWS cung cấp sẵn code rotation
      RotationType: MySQLSingleUser
    RotationRules:
      AutomaticallyAfterDays: 90
  • There is no AWS::SSM::RotationSchedule. Any option pairing "Parameter Store" with "RotationSchedule" is inventing a resource type.Không có AWS::SSM::RotationSchedule. Option nào ghép "Parameter Store" với "RotationSchedule" là đang bịa ra resource type.
  • EventBridge scheduled rule → Lambda works, but it's re-implementing something native. In a "LEAST operational overhead" question it loses to RotationSchedule.EventBridge scheduled rule → Lambda chạy được, nhưng là tự làm lại thứ đã có sẵn. Trong câu "LEAST operational overhead" nó thua RotationSchedule.
  • If the DB is in a VPC, the rotation Lambda needs VPC config + a route to Secrets Manager — an interface VPC endpoint, or a NAT gateway.Nếu DB nằm trong VPC, rotation Lambda cần VPC config + đường tới Secrets Manager — interface VPC endpoint, hoặc NAT gateway.
  • Managed rotation (ManageMasterUserPassword) defaults to every 7 days and the secret is owned by RDS — you can change the schedule but you don't hand-edit the value.Managed rotation (ManageMasterUserPassword) mặc định 7 ngày một lần và secret do RDS sở hữu — đổi được lịch nhưng không sửa tay giá trị.

Exam reflexesPhản xạ thi

  • "Strong random password · stored in a secure AWS managed service · rotate every 90 days · deployed by CloudFormation · least overhead" → Secrets Manager secret + rotation Lambda + RotationSchedule."Password ngẫu nhiên mạnh · lưu trong service AWS an toàn · xoay mỗi 90 ngày · deploy bằng CloudFormation · ít overhead nhất" → secret Secrets Manager + rotation Lambda + RotationSchedule.
  • See "rotate" anywhere near credentials → Secrets Manager. See "store an encrypted config value" → Parameter Store.Thấy "rotate" gần chữ credential → Secrets Manager. Thấy "lưu giá trị config đã mã hoá" → Parameter Store.
  • If the option set includes ManageMasterUserPassword, that's the no-Lambda answer and it wins on overhead.Nếu trong các option có ManageMasterUserPassword, đó là đáp án không cần Lambda và thắng về overhead.
  • Zero-downtime rotation for a busy app → alternating-users strategy, not single-user.Rotation không downtime cho app bận → chiến lược alternating-users, không phải single-user.
  • Cross-account secret → resource policy and a customer-managed KMS key. Forgetting the key grant is the classic silent failure.Secret cross-account → resource policy và customer-managed KMS key. Quên grant key là lỗi im lặng kinh điển.