Closed CrypticCabub closed 1 day ago
further debugging on my side makes it appear that the culprit for the deployment error is actually the selector under event:
and the extra comma is an artifact of jest snapshots but doesn't make it through to the deployment console.
Am doing some further testing to confirm, but this may be another case of playing hide-and-seek with punctuation
Hi @CrypticCabub , thanks for reaching out.
I tried to repro the mentioned scenario. However for me, the comma is not added in both the cases when I do cdk synth
or cdk deploy
but deployment fails in both cases with the same error of GeneralServiceException
. I am trying to identify the root cause though.
I believe the root cause is that "$." is not the correct selector but rather should be just "$". Am still having some problems with permissions not allowing EventBridge to actually write the log to cloudwatch, but deployment isn't failing anymore
@CrypticCabub ,I am still not able to repro the scenario you mentioned initially but did some observations by tweaking the code -
So I tried replacing the event.fromPath("$")
with different value and my synth as well as deployment succeeded.
Sharing the code and result -
initial code -
const logGroup = new LogGroup(this, "LogGroup", {});
const eventBus = new EventBus(this, "EventBus", {
description: "example event bus",
});
new Rule(this, "EventBusRule", {
description: "logs all events that get sent to the event bus",
eventBus: eventBus,
targets: [
new CloudWatchLogGroup(logGroup, {
installLatestAwsSdk: false,
retryAttempts: 20,
logEvent: RuleTargetInput.fromObject({
message: `EventBus received ${EventField.fromPath("$.detail-type")} event`,
module: "EventBus",
event: EventField.fromPath("$."),
}),
}),
],
eventPattern: {
source: [{ prefix: "" }] as any[],
},
});
}
const logGroup = new LogGroup(this, "LogGroup", {});
const eventBus = new EventBus(this, "EventBus", { description: "example event bus", });
new Rule(this, "EventBusRule", {
description: "logs all events that get sent to the event bus",
eventBus: eventBus,
targets: [
new CloudWatchLogGroup(logGroup, {
installLatestAwsSdk: false,
retryAttempts: 20,
logEvent: RuleTargetInput.fromObject({
message: EventBus received ${EventField.fromPath("$.detail-type")} event
,
module: "EventBus",
event: EventField.fromPath("$.detail-type"),
}),
}),
],
eventPattern: {
source: [{ prefix: "" }] as any[],
},
});
}
3. deploying code 1 resulted in `error - "InputPath for target Target0 is invalid.` but when I changed the `.fromPath("$.detail-type"), the result from `cdk diff` -
which means the earlier InputTemplate was wrongly generated due to the path mentioned.
Deploying the changed code succeeded-
AFAIU, the fromPath()
should have complete path value which is properly synthesized and deployed. Giving the value as "$." is incorrect (as you also noticed above) as CDK might be expecting complete path here. However I am trying to look for evidence to support my claim :)
yes, I can confirm that the issue appears to have been the $.
selector, so this looks like a false-positive. Thanks for taking the time to look into this.
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.
Describe the bug
When using RuleTargetInput.fromObject() with EventField.fromPath fields, CDK generates an invalid InputPathsMap by including a trailing comma in the InputsPathMap.
However, this behavior is not consistent. When running
cdk synth
, the InputsPathMap is generated correctly, but it is not generated correctly when attempting to deploy withcdk deploy
or withTemplate.fromStack()
in snapshot tests. (see examples)Regression Issue
Last Known Working CDK Version
N/A
Expected Behavior
When using RuleTargetInput.fromObject(), I expect a valid InputsPathMap to be generated every time
Current Behavior
Running a snapshot test or cdk deploy produces the following:
whereas running cdk synth produces the following:
The additional comma in the first example makes the stack undeployable and causes the following CloudFormation Error:
Reproduction Steps
cdk app:
snapshot test example:
Possible Solution
Not sure why the use of cdk synth would have a different result than cdk deploy, but the issue is likely a simple off-by-one error on a for loop somewhere.
Additional Information/Context
No response
CDK CLI Version
2.163.0 (build ad5325a)
Framework Version
No response
Node.js Version
18.18.2
OS
Mac
Language
TypeScript
Language Version
5.6.3
Other information
No response