Skip to content
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

[Step Function] 8.1 Fix subscription filter creation failure #164

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion serverless/src/step_function/forwarder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ export const SUBSCRIPTION_FILTER_PREFIX = "LogGroupDatadogSubscriptionFilter";
*/
export function addForwarder(resources: Resources, config: Configuration, stateMachine: StateMachine): void {
log.debug(`Subscribing the forwarder to the log group...`);
const logGroup = findLogGroup(resources, stateMachine);
const [logGroupKey, logGroup] = findLogGroup(resources, stateMachine);
const subscriptionFilter = {
Type: "AWS::Logs::SubscriptionFilter",
DependsOn: logGroupKey,
Properties: {
LogGroupName: logGroup.Properties.LogGroupName,
DestinationArn: config.stepFunctionForwarderArn,
Expand Down
5 changes: 3 additions & 2 deletions serverless/src/step_function/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,9 @@ export const buildLogGroupName = (stateMachine: StateMachine, env: string | unde
* "Fn::GetAtt": ["MyStateMachineLogGroup", "Arn"]
* which is the most common way of referencing a log group.
* We can add support for other cases when users request it.
* @returns [logGroupKey, logGroup]
*/
export function findLogGroup(resources: Resources, stateMachine: StateMachine): LogGroup {
export function findLogGroup(resources: Resources, stateMachine: StateMachine): [string, LogGroup] {
const logConfig = stateMachine.properties.LoggingConfiguration;

if (!logConfig?.Destinations) {
Expand All @@ -189,5 +190,5 @@ export function findLogGroup(resources: Resources, stateMachine: StateMachine):
}
const logGroupKey = logGroupArn[FN_GET_ATT][0];
const logGroup = resources[logGroupKey];
return logGroup;
return [logGroupKey, logGroup];
}
12 changes: 8 additions & 4 deletions serverless/test/step_function/forwarder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@ describe("addForwarder", () => {
const stateMachine = {
resourceKey: "MyStateMachine",
} as any;
(findLogGroup as jest.Mock).mockReturnValue({
Properties: {
LogGroupName: "/aws/lambda/my-function",
(findLogGroup as jest.Mock).mockReturnValue([
"MyStateMachineLogGroup",
{
Properties: {
LogGroupName: "/aws/lambda/my-function",
},
},
});
]);

addForwarder(resources, config, stateMachine);

const subscriptionFilterKey = stateMachine.resourceKey + SUBSCRIPTION_FILTER_PREFIX;
expect(resources[subscriptionFilterKey]).toEqual({
Type: "AWS::Logs::SubscriptionFilter",
DependsOn: "MyStateMachineLogGroup",
Properties: {
LogGroupName: "/aws/lambda/my-function",
DestinationArn: config.stepFunctionForwarderArn,
Expand Down
3 changes: 2 additions & 1 deletion serverless/test/step_function/log.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ describe("findLogGroup", () => {
},
};

const logGroup = findLogGroup(resources, stateMachine);
const [logGroupKey, logGroup] = findLogGroup(resources, stateMachine);
expect(logGroupKey).toBe("MyStateMachineLogGroup");
expect(logGroup.Type).toBe("AWS::Logs::LogGroup");
expect(logGroup.Properties.LogGroupName).toBe("/aws/vendedlogs/states/MyStateMachine-Logs-dev");
});
Expand Down
Loading