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

lambda: CDK synth warning message presented as [object Object] #28936

Open
enpatrik opened this issue Jan 31, 2024 · 5 comments
Open

lambda: CDK synth warning message presented as [object Object] #28936

enpatrik opened this issue Jan 31, 2024 · 5 comments
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

@enpatrik
Copy link

Describe the bug

Warning message is expected to be shown, but the message is not correctly presented.

Expected Behavior

Warning message to be presented correctly.

`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.`

Warning message was added in: 2c21ea0#diff-527ac1e9edceb6fd9abb75249884fa31415393bbfed87ef28a2faa8a6a39b416R347 CDK v2.112.0

Current Behavior

CDK synth warning message:

[Warning at /CdkTestStack/AuthFunction] [object Object]

Reproduction Steps

import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as lambda from 'aws-cdk-lib/aws-lambda'
import * as apigateway from 'aws-cdk-lib/aws-apigateway'

export class CdkTestStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const authFunc = lambda.Function.fromFunctionArn(this,'AuthFunction', 'arn:aws:lambda:eu-west-1:000000000000:function:AuthFunction')

    const authorizer = new apigateway.TokenAuthorizer(this, 'TokenAuthorizer', {
      handler: authFunc,
    })

    const restApi = new apigateway.RestApi(this, 'RestApi', {})
    restApi.root.addResource('hello').addMethod('GET', new apigateway.MockIntegration(), {
      authorizer: authorizer
    })
  }
}

Run:

npx cdk synth -q
# Output:
# [Warning at /CdkTestStack/AuthFunction] [object Object]

By following the advice from the warning message (that was supposed to be shown) and changing the code to use:

const authFunc = lambda.Function.fromFunctionAttributes(this,'AuthFunction', {
  functionArn: 'arn:aws:lambda:eu-west-1:000000000000:function:AuthFunction',
  sameEnvironment: true,
})

The warning is no longer shown (as expected).

Possible Solution

No response

Additional Information/Context

The warning message is still shown when setting skipPermissions = true:

lambda.Function.fromFunctionAttributes(this,'AuthFunction', {
  functionArn: 'arn:aws:lambda:eu-west-1:000000000000:function:AuthFunction',
  skipPermissions: true
})

And the permissions are still added to the function, which was unexpected. Let me know if you consider this a bug and if you want me to create a separate ticket for that.

CDK CLI Version

CDK 2.124.0 (build 4b6724c)

Framework Version

No response

Node.js Version

v20.11.0

OS

MacOS

Language

TypeScript

Language Version

No response

Other information

cdk synth verbose log:

Annotations.addMessage (/cdktest/cdktest/node_modules/aws-cdk-lib/core/lib/annotations.js:1:1608)
Annotations.addWarningV2 (/cdktest/cdktest/node_modules/aws-cdk-lib/core/lib/annotations.js:1:825)
Import.addPermission (/cdktest/cdktest/node_modules/aws-cdk-lib/aws-lambda/lib/function-base.js:2:309)
TokenAuthorizer.addDefaultPermissionRole (/cdktest/cdktest/node_modules/aws-cdk-lib/aws-apigateway/lib/authorizers/lambda.js:1:2064)
TokenAuthorizer.setupPermissions (/cdktest/cdktest/node_modules/aws-cdk-lib/aws-apigateway/lib/authorizers/lambda.js:1:1997)
new TokenAuthorizer (/cdktest/cdktest/node_modules/aws-cdk-lib/aws-apigateway/lib/authorizers/lambda.js:1:3753)
new CdkTestStack (/cdktest/cdktest/lib/cdk-test-stack.ts:16:24)
...

Warning message was added in PR: #27861

@enpatrik enpatrik added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jan 31, 2024
@github-actions github-actions bot added the @aws-cdk/aws-lambda Related to AWS Lambda label Jan 31, 2024
@pahud pahud changed the title (aws-cdk-lib.aws_lambda): CDK synth warning message presented as [object Object] lambda: CDK synth warning message presented as [object Object] Jan 31, 2024
@pahud pahud added p2 effort/medium Medium work item – several days of effort and removed effort/medium Medium work item – several days of effort needs-triage This issue or PR still needs to be triaged. labels Jan 31, 2024
@msambol
Copy link
Contributor

msambol commented Feb 1, 2024

I'll take this.

@msambol
Copy link
Contributor

msambol commented Feb 3, 2024

@lmammino I wanted to loop you in here as it's related to #28414. It looks like we're still seeing this.

@jaapvanblaaderen
Copy link
Contributor

FYI, I created a ticket which slightly related to this one: #29887

@alexander-dermicus
Copy link

alexander-dermicus commented May 29, 2024

I got the same [object Object] warning on aws-cdk and aws-cdk-lib version 2.114.1 up to 2.143.0 (currently latest version). The warnings only appear since version 2.112.0 in my case. It's the exact same issue as the OP. Somehow the string interpolation turns into [object Object], because if I replace the two ` with regular " quotes I do see the message.
image

@hakenmt
Copy link

hakenmt commented Jun 11, 2024

I get a similar output from a CloudWatch Alarm resource: [Warning at /path/to/my/cloudwatch/alarm] [object Object]. Would be great to be able to see what the actual warning is.

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/medium Medium work item – several days of effort p2
Projects
None yet
Development

No branches or pull requests

6 participants