How to have AWS Lambda assume a role dynamically and get permissions on the fly

Amlan Chakladar
7 min readMay 2, 2024

During a recent work on one of my projects, I came across a scenario where I needed to have a AWS Lambda function assume a role dynamically and get permissions conditionally. When we create an AWS Lambda function, we always associate a single role to the function. To achieve my need I had to come up with a solution where I could have the Lambda function assume a role dynamically and get permissions which is different than the associated role. I wanted to share my experience of this method and hopefully it will help someone who is looking for a similar solution.

In this post, I will show you how to have a Lambda function assume a role dynamically and give the functions permissions which are not present in the associated role. The sample code for this can be found in my Github Repo

https://github.com/amlana21/lambda-role-publish

Prerequisites

Before I begin, I assume you have the following:

  • An AWS account
  • AWS CLI installed and configured with the necessary permissions
  • Python 3.7 or later installed on your machine
  • A basic understanding of AWS Lambda and IAM roles

What is Lambda

--

--

Amlan Chakladar
Amlan Chakladar

Written by Amlan Chakladar

Cloud architect and DevOps engineer. Love to code and develop new stuff. A nerd by nature.

No responses yet