Ravindra BagaleCourses & study guides मराठी

Chapter 93: AWS Lambda and Serverless for DevOps

DevOps

93.4 Execution role and least privilege

Story (fictional teaching scenario). At a fictional Kochi training team, Kabir nearly gives a thumbnail function administrator access. Amira from Rabat asks which exact object prefix it needs to read instead.

Execution role and least privilege
Execution role and least privilege

Why

One function bug should not become permission to change the whole account.

What

  • IAM is AWS Identity and Access Management.
  • Execution role is the identity the function assumes to call AWS services.
  • Policy lists allowed actions and resources.
  • Least privilege means only the required actions on the required resources.
  • Trust policy answers who may assume a role; an access policy answers what that role may do. Permission to invoke the function is separate from its execution role.

How

  1. List the exact business operations.

  2. Restrict the resource path.

  3. Keep AWS keys out of code and environment variables; use the execution role for AWS access.

Example 1: Read-only permission fragment

  1. Read the input and the code.
{"Effect":"Allow","Action":"s3:GetObject",
 "Resource":"arn:aws:s3:::example-training-input/incoming/*"}
  1. Read the result.

Output (illustrative; not executed on AWS)

Read incoming/photo.jpg: allowed if other policy checks permit
Delete incoming/photo.jpg: not granted by this statement
  1. What each part means: Effect permits rather than denies. Action allows object reads only. Resource narrows the bucket and prefix. This is a teaching fragment, not a complete deployable role. The example bucket is not a real resource being accessed. Logging permissions must also be scoped as appropriate.

Example 2: Trust and invocation are different

  1. Read the input and the code.
Trust: Lambda service can assume the execution role.
Invocation: only the chosen event source/caller may invoke the function.
  1. Read the result.

Output (illustrative; not executed on AWS)

Caller invokes -> Lambda runs -> execution role authorizes AWS API calls
  1. What each part means: The caller is not automatically granted the role permissions. Conversely, adding S3 read access to the role does not wire S3 events or allow everyone to invoke the function.

Ravindra Bagale's Tip

A role is permission, not a connection to an event source.

Did you understand? Let us try it once more.