-
Notifications
You must be signed in to change notification settings - Fork 4.1k
aws-lambda: addPermission
doesn't allow overriding auto-generated statement ID
#34219
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
Comments
Hey @garysassano , Thanks for reporting this issue. The requested change would require modifications to two key files: In export interface Permission {
/**
* The statement ID to use for this permission statement. If not provided,
* CDK will auto-generate an ID using the construct path.
*
* @default - Auto-generated using construct path and a random suffix
*/
readonly statementId?: string;
// ... existing properties ...
} In public addPermission(id: string, permission: Permission) {
// ... existing checks ...
new CfnPermission(scope, id, {
action,
principal,
functionName: this.functionArn,
sid: permission.statementId ?? id, // Use provided statementId or fallback to id
eventSourceToken: permission.eventSourceToken,
sourceAccount: permission.sourceAccount ?? sourceAccount,
sourceArn: permission.sourceArn ?? sourceArn,
principalOrgId: permission.organizationId ?? principalOrgID,
functionUrlAuthType: permission.functionUrlAuthType,
});
} This would allow users to control the statement ID while maintaining backward compatibility with the current auto-generation behavior. I am making this a p2 feature request and any PR would be appreciated! |
@garysassano on diving further into this, noticed the I would suggest opening a issue on cloudformation-coverage-roadmap repository to track this implementation. Internal ticket for tracking: V1751760064 |
This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled. |
keep |
Description
When using
addPermission
method on a Lambda function, CDK generates a resource-based policy statement with an auto-generated statement ID that begins with the construct path. There is currently no way to override this behavior and specify a custom statement ID that will be used in the actual AWS resource.Current Behavior
When calling
addPermission
with a statement ID like:The statement ID in the actual Lambda resource-based policy becomes something like:
<stack-name>-<function-name><policy-logic-id><random-id>
As seen in the AWS Console:
Expected Behavior
The
addPermission
method should have an optional property to specify the exact statement ID to use in the deployed resource-based policy. For example:Additional Information
The AWS Lambda API itself allows specifying the statement ID directly when adding permissions. This feature request is to expose this capability through the CDK API.
AWS Lambda API vs. CDK Implementation
Lambda API Behavior
aws lambda add-permission \ --function-name my-function \ --action lambda:InvokeFunction \ --statement-id AllowCWL \ --principal logs.amazonaws.com \ --source-arn arn:aws:logs:us-west-2:123456789012:log-group:* \ --source-account 123456789012
CDK Current Implementation
<stack-name>-<function-name><policy-logic-id><random-id>
statementId
property in Permission interface:Current Workaround (Complex and Fragile)
CDK CLI Version
2.190.0
Framework Version
No response
Node.js Version
22.14.0
OS
Ubuntu 24.04
Language
TypeScript
Language Version
No response
Other information
No response
The text was updated successfully, but these errors were encountered: