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
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:
Reproduction Steps
Run:
By following the advice from the warning message (that was supposed to be shown) and changing the code to use:
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: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:
Warning message was added in PR: #27861