-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Description
General Issue
No way to rename log group/lambda for AwsCustomResource
The Question
I'm not sure if this is a feature or bug, sorry if this is in the wrong place.
AwsCustomResource uses a SingletonLambda to make a single SDK call (I didn't, understand this when I started my project). I utilize this a few times in the same stack for a website:
- Get my AppMonitor ID for CW RUM (not in CFN spec yet)
- Invalidate my CloudFront distribution at the end of deploy
- Upload some JSON to my website bucket as config for the site
I created one of these first, say a custom resource of the following form:
private getAppMonitorId() {
const awsRUMSDKCall: AwsSdkCall = {
service: 'RUM',
action: 'getAppMonitor',
parameters: { Name: this.rumMonitor.name },
physicalResourceId: PhysicalResourceId.of('7854f358-6c0a-4ed4-8863-2d5bf35d7062'),
};
const customResource = new AwsCustomResource(this, 'Custom::GetAppMonitorId', {
policy: AwsCustomResourcePolicy.fromSdkCalls({
resources: [this.rumMonitorArn],
}),
installLatestAwsSdk: true,
onCreate: awsRUMSDKCall,
onUpdate: awsRUMSDKCall,
functionName: 'GetAppMonitorCustomResourceHandler',
});
customResource.node.addDependency(this.rumMonitor);
return customResource.getResponseField('AppMonitor.Id');
}
}The functionName here names the Singleton Lambda and the log group that gets created /aws/lambda/GetAppMonitorCustomResourceHandler. This is all well and good until another custom resource is added, with a functionName or not. The new custom resource then uses the named lambda and the named log group named specifically for a different custom resource. This creates confusion when trying to debug, trying to look for the logs (especially if you don't know that AwsCustomResource is a singleton lambda), etc.
Out of this, I ask two things:
- Is it possible to rename an
AwsCustomResourcefunction name?- I think the answer to this is no, as I get
Modifying service token is not allowed.on any attempts I make.
- I think the answer to this is no, as I get
- I would move to suggest to remove/deprecate
functionNamefromAwsCustomResourceas the creation of a specifically named lambda that potentially adds unrelatedAwsCustomResources to it is confusing. I don't know what implications that removal would have and is probably a breaking change so I'm not too worried about it now that I know. Calling it out at the top of theAwsCustomResourcedocs page would be nice at least.
CDK CLI Version
2.0.0
Framework Version
1.147.0
Node.js Version
16
OS
Mac OSX Monterey
Language
Typescript
Language Version
4.0.5
Other information
No response