AWS Builder Center

One bucket, one Lambda role, no wildcard: least privilege that stays usable

A Lambda upload flow scoped to one bucket and one prefix, built from real CloudTrail events and kept in the same repo as the code.

Full-stack Developer & Security Researcher
The fastest IAM policy to write is the one with a wildcard, and it is the one that ages worst. When I scoped a small Lambda upload flow, I gave the function exactly one bucket and one prefix instead of s3:* on everything.
The role can read and write a single bucket prefix, write its own logs, and nothing else. No wildcard actions, no wildcard resources. If that function is ever compromised or just buggy, the blast radius is one prefix, not the account.
Two habits made this painless. First, build the policy from the CloudTrail events the function actually produced during a test run, not from guesses. Second, keep the policy in the same repo as the function code, so a reviewer sees the permissions change in the same diff as the code change.
Least privilege is not more work. It is the same work, done once, in the right order.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article