Enables adding a subscription filter to subscribe the forwarder to the state machine's log group.
Motivation
This is the second step of instrumenting a step function.
Testing Guidelines
Automated testing
Passed the added test for forwarder setup
Manual testing
Step:
Deploy the example stacks in step-functions-typescript-stack.
Result:
The subscription filter appeared in AWS UI
@DylanLovesCoffee sorry I borrowed your forwarder.
Additional Notes
It takes a lot of code to extract log group from the log config of a state machine, if the user sets the log group themselves.
// Extract log group from logging config
const destinations = cfnStateMachine.loggingConfiguration.destinations;
if (!this.isLogDestinationPropertyArray(destinations)) {
throw new Error("destinations is not an array");
}
const destination = destinations[0];
if (!("cloudWatchLogsLogGroup" in destination)) {
throw new Error("cloudWatchLogsLogGroup is not in destination");
}
const logGroupConfig = destination.cloudWatchLogsLogGroup;
if (logGroupConfig === undefined) {
throw new Error("cloudWatchLogsLogGroup is undefined");
}
if (!("logGroupArn" in logGroupConfig)) {
throw new Error("logGroupArn is not in cloudWatchLogsLogGroup");
}
const logGroupArn = logGroupConfig.logGroupArn;
if (logGroupArn === undefined) {
throw new Error("logGroupArn is undefined");
}
logGroup = logs.LogGroup.fromLogGroupArn(this, "LogGroup", logGroupArn);
There are so many checks because at each level, the variable can often have multiple possible types, e.g. logGroupConfig can be
To be able to parse the log group, we assume that nothing is an unresolved token (i.e. IResolvable), and throw if anything is an unresolved token. I'm not sure in what case and if it's common that anything is an unresolved token. I think we can start from handling the simple case, and come back later if anyone asks for supporting the unresolved token cases.
What does this PR do?
Enables adding a subscription filter to subscribe the forwarder to the state machine's log group.
Motivation
This is the second step of instrumenting a step function.
Testing Guidelines
Automated testing
Passed the added test for forwarder setup
Manual testing
Step:
step-functions-typescript-stack
.Result:
@DylanLovesCoffee sorry I borrowed your forwarder.
Additional Notes
It takes a lot of code to extract log group from the log config of a state machine, if the user sets the log group themselves.
There are so many checks because at each level, the variable can often have multiple possible types, e.g.
logGroupConfig
can beTo be able to parse the log group, we assume that nothing is an unresolved token (i.e.
IResolvable
), and throw if anything is an unresolved token. I'm not sure in what case and if it's common that anything is an unresolved token. I think we can start from handling the simple case, and come back later if anyone asks for supporting the unresolved token cases.Types of Changes
Check all that apply