In my scenario I have 2 accounts (11111111, 22222222) that need to+ invoke a lambda in a 3rd account: 33333333. The lambdas in the 3rd account will be invoked from lambdas in the first 2.
The lambdas in 3rd account are created on the fly but I need to give them a role which I wish to create using CDK (which I will do using 3rd account creds - no cross account stuff here).
I am following the instructions here - invoking the lambda using STS seems straightforward. What I am not fully clear on is how to define the 3rd account role in cdk.
Here's my stack:
export class ModuleIAMStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props)
const lambdaModuleRole = new Role(this, 'moduleRole', {
roleName: 'moduleRole',
assumedBy: new AccountPrincipal({ accountId: '111111111' }),
managedPolicies: [ManagedPolicy.fromAwsManagedPolicyName('service-role/AWSLambdaBasicExecutionRole')] // My lambdas in 3X... will not need to access any resources so this should be enough to execute
})
}
}
I am unclear on the assumedBy line. Is AccountPrincipal the correct entry? and if so how do I enter the 22222222 account?