PowerShell Assume Role Credentials Presists in subsequent execution #314
-
Hello Team, I am having an issue. I have a lambda function that is assigned an execution role(LambdaExecutionRole) that assumes another role(DeleteSnapshotsRole) in another account using Use-STSRole cmdlet. I am able to execute the function the first time after modifying the code however when the function is executed the second time it returns the error DeleteSnapshotsRole is not authorized to assume DeleteSnapshotsRole. For some reason after the first execution the credentials presist in the function and second execution it uses the assumed role from the previous execution. Is there any configuration we need to set in the function or layer to flush the environment variables after each execution? I have tried to set the AWS credentials to null after the function is executed but these null values are getting picked up in subsequent executions. Here is the code:
Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Away from my PC, but is it possible it's an issue with the Role Session Name ? try changing the role session name to have a variable as the last character so each creation of role session is unique. You could store value in file in attached storage that's not temp, or could create a parameter and just put numeric value 1 in it. read it with lambda function then add it to end of role session name, then write it back to the parameter as $i + 1 (ie 2 2nd time) , |
Beta Was this translation helpful? Give feedback.
-
@ashishdhingra Good morning, I was able to get around the problem by setting the $env:AWS_ACCESS_KEY_ID, $env:AWS_SECRET_ACCESS_KEY and $env:AWS_SESSION_TOKEN to temporary variable before running STSAssume. At the end I reassigned the credentials from the variables and subsequent runs were successful.
|
Beta Was this translation helpful? Give feedback.
-
Hello! Reopening this discussion to make it searchable. |
Beta Was this translation helpful? Give feedback.
Away from my PC, but is it possible it's an issue with the Role Session Name ? try changing the role session name to have a variable as the last character so each creation of role session is unique. You could store value in file in attached storage that's not temp, or could create a parameter and just put numeric value 1 in it. read it with lambda function then add it to end of role session name, then write it back to the parameter as $i + 1 (ie 2 2nd time) ,