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: addPermission() warning should not be shown #29887

Closed
jaapvanblaaderen opened this issue Apr 18, 2024 · 3 comments · Fixed by #30060
Closed

aws-lambda: addPermission() warning should not be shown #29887

jaapvanblaaderen opened this issue Apr 18, 2024 · 3 comments · Fixed by #30060
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Comments

@jaapvanblaaderen
Copy link
Contributor

jaapvanblaaderen commented Apr 18, 2024

Describe the bug

Incorrect warning is logged when synthesizing a HttpLambdaAuthorizer that points to a Lambda in another AWS account.

Expected Behavior

No warning message as I'm not intentionally setting any permissions on the handler.

Current Behavior

Consider a setup where a http lambda authorizer is used from another AWS account. In this case, the permissions to access the authorizer are already managed in the other account. When creating a lambda authorizer, a warning message is logged:

[Warning at /AuthorizerLambda] addPermission() has no effect on a Lambda Function with region=eu-west-1, account=12345678990, in a Stack with region=eu-west-1, account=09876543210. Suppress this warning if this is is intentional, or pass sameEnvironment=true to fromFunctionAttributes() if you would like to add the permissions. [ack: UnclearLambdaEnvironment]

Reproduction Steps

Create a HttpLambdaAuthorizer with an ARN pointing to another account:

new HttpLambdaAuthorizer('LambdaAuthorizer',
    lambda.Function.fromFunctionAttributes(this, 'AuthorizerLambda', {
         functionArn: 'arn...',
     }
),

Possible Solution

Looking at the skipPermissions option, I would actually expect that this option would make sure this warning is not logged as we do not care about permissions not being added (it's already handled). So maybe something like this could be the fix in function-base.ts:

  public addPermission(id: string, permission: Permission) {
    if (!this.canCreatePermissions) {
      if (!this._skipPermissions) {
        Annotations.of(this).addWarningV2('UnclearLambdaEnvironment', `addPermission() has no effect on a Lambda Function with region=${this.env.region}, account=${this.env.account}, in a Stack with region=${Stack.of(this).region}, account=${Stack.of(this).account}. Suppress this warning if this is is intentional, or pass sameEnvironment=true to fromFunctionAttributes() if you would like to add the permissions.`);
      }
      return;
    }
  }

Additional Information/Context

I also looked at where addPermission() is actually triggered for this use-case, which is here. Maybe we should have an option in HttpLambdaAuthorizer for not adding this permission in the first place?

CDK CLI Version

2.137.0

Framework Version

No response

Node.js Version

v18.19.0

OS

OSX

Language

TypeScript

Language Version

5.2.0

Other information

Ticket which is slightly related: #28936

@jaapvanblaaderen jaapvanblaaderen added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 18, 2024
@github-actions github-actions bot added the @aws-cdk/aws-lambda Related to AWS Lambda label Apr 18, 2024
@pahud
Copy link
Contributor

pahud commented Apr 18, 2024

Maybe we should have an option in HttpLambdaAuthorizer for not adding this permission in the first place?
Yes I support this option.

Are you interested to submit a PR for that? We'd love to review the PR and move this forward.

@pahud pahud added p2 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Apr 18, 2024
@mergify mergify bot closed this as completed in #30060 May 6, 2024
mergify bot pushed a commit that referenced this issue May 6, 2024
### Issue #29887

Closes #29887

### Reason for this change

If an user imports a lambda and wants to add permissions a warning is show. This warning should be skippable with the skipPermissions flag.

### Description of how you validated changes

Unit tests for checking if the warning is shown/not shown depending on the value of `skipPermissions` are added.

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

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

github-actions bot commented May 6, 2024

⚠️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.

@aws-cdk-automation
Copy link
Collaborator

Comments on closed issues and PRs are hard for our team to see. If you need help, please open a new issue that references this one.

@aws aws locked as resolved and limited conversation to collaborators Jul 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. effort/medium Medium work item – several days of effort p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants