Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws-lambda: Invalid principal type for Lambda permission statement: CompositePrincipal. #27503

Closed
AlJohri opened this issue Oct 11, 2023 · 8 comments · Fixed by #27529
Closed
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. effort/small Small work item – less than a day of effort p2

Comments

@AlJohri
Copy link

AlJohri commented Oct 11, 2023

Describe the bug

I am getting an error when trying to use a CompositePrincipal to grantInvoke permissions on a lambda.

Expected Behavior

I expect it to work and allow all of the account principals to invoke the lambda.

Current Behavior

Currently it errors out and says it is unsupported with the following error:

Error: Invalid principal type for Lambda permission statement: CompositePrincipal. Supported: AccountPrincipal, ArnPrincipal, ServicePrincipal, OrganizationPrincipal

Reproduction Steps

This code results in the error:

const accounts = new iam.CompositePrincipal(
  new iam.AccountPrincipal('1234'),
  new iam.AccountPrincipal('5678'),
);
myLambda.grantInvoke(accounts);

Possible Solution

No response

Additional Information/Context

Possibly related:

CDK CLI Version

2.95.0 (build cfa7e88)

Framework Version

No response

Node.js Version

v18.17.1

OS

macOS Sonoma

Language

TypeScript

Language Version

TypeScript 5.2

Other information

No response

@AlJohri AlJohri added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 11, 2023
@github-actions github-actions bot added the @aws-cdk/aws-lambda Related to AWS Lambda label Oct 11, 2023
@msambol
Copy link
Contributor

msambol commented Oct 11, 2023

@peterwoodworth I'll take this.

@msambol
Copy link
Contributor

msambol commented Oct 11, 2023

@AlJohri This currently isn't supported but you can do this:

    const account1 = new iam.AccountPrincipal('111111111111')
    const account2 = new iam.AccountPrincipal('222222222222')
    myLambda.grantInvoke(account1);
    myLambda.grantInvoke(account2);

@peterwoodworth Is this functionality we want to add?

@peterwoodworth
Copy link
Contributor

I don't see why not @msambol, feel free to take

@peterwoodworth peterwoodworth added p2 effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. labels Oct 12, 2023
@msambol
Copy link
Contributor

msambol commented Oct 13, 2023

@peterwoodworth I don't think it makes sense to change grantInvoke to accommodate this. I could add a new method if we want to support it, maybe grantInvokeCompositePrincipal (basically a wrapper around grantInvoke). Thoughts?

@vinayak-kukreja
Copy link
Contributor

Hey @msambol, could you tell me why did you not go for accommodating this in grantInvoke function? :)

@msambol
Copy link
Contributor

msambol commented Oct 17, 2023

@vinayak-kukreja I think it would require updating the function declaration? At the very least the return type. So I thought best to create a new method. I'm open to suggestions though if you think we can do it better.

@vinayak-kukreja
Copy link
Contributor

Hey @msambol , I agree, thank you for the clarification.

@mergify mergify bot closed this as completed in #27529 Oct 19, 2023
mergify bot pushed a commit that referenced this issue Oct 19, 2023
Add ability to grant function access to `CompositePrincipal`.

Closes #27503.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. effort/small Small work item – less than a day of effort p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants