Menu

Secrets Manager Rotation with Lambda for API Keys
📰

Secrets Manager Rotation with Lambda for API Keys

DEV Community: aws·Sascha Mirow-Stanitzok·11 days ago
#3jDdoLt4
#devtoaws#devto#dev#rotation#secrets
Reading 0:00
15s threshold

Secrets Manager rotation is my answer to an uncomfortable question: how old is the API key your Lambda function has been sending to a partner for months? In many projects the honest answer is “as old as the project”. The key lives in a secret, the secret is read encrypted, and still nobody has ever replaced it. If it slips into a log, a support email or a ticket once, it stays valid until somebody notices.

AWS Secrets Manager can renew such keys automatically. For databases that is almost a single click. For an API key at an external service you need your own rotation function in Lambda, and that is what we build in this article, step by step: with TypeScript, tests and the Serverless Framework. Afterwards you will understand what happens in the four steps, why staging labels matter so much and how your other functions pick up the new key without downtime.

In short

Secrets Manager invokes your rotation function four times: create a new value, set it at the target service, test it, mark it as current.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.