Skip to content

Commit e7c2133

Browse files
authored
fix: remove cleanup idle stages lambda and event rule schedule (#34)
1 parent b66948d commit e7c2133

File tree

5 files changed

+37
-106
lines changed

5 files changed

+37
-106
lines changed

cdk/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ PUBLISH ?= false
1010
STACK ?= UGC-$(STAGE)
1111
COGNITO_CLEANUP_SCHEDULE ?= rate(48 hours)
1212
STAGE_CLEANUP_SCHEDULE ?= rate(24 hours)
13-
CDK_OPTIONS = $(if $(AWS_PROFILE),$(AWS_PROFILE_FLAG)) -c stage=$(STAGE) -c publish=$(PUBLISH) -c stackName=$(STACK) -c cognitoCleanupScheduleExp="$(strip $(COGNITO_CLEANUP_SCHEDULE))" -c stageCleanupScheduleExp="$(strip $(STAGE_CLEANUP_SCHEDULE))"
13+
CDK_OPTIONS = $(if $(AWS_PROFILE),$(AWS_PROFILE_FLAG)) -c stage=$(STAGE) -c publish=$(PUBLISH) -c stackName=$(STACK) -c cognitoCleanupScheduleExp="$(strip $(COGNITO_CLEANUP_SCHEDULE))"
1414
FE_DEPLOYMENT_STACK = UGC-Frontend-Deployment-$(STAGE)
1515
SEED_COUNT ?= 50
1616
OFFLINE_SESSION_COUNT ?= 1

cdk/bin/cdk.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ const app = new App();
1212
const stage = app.node.tryGetContext('stage');
1313
const stackName = app.node.tryGetContext('stackName');
1414
const shouldPublish = app.node.tryGetContext('publish') === 'true';
15-
const cognitoCleanupScheduleExp = app.node.tryGetContext('cognitoCleanupScheduleExp');
16-
const stageCleanupScheduleExp = app.node.tryGetContext('stageCleanupScheduleExp')
15+
const cognitoCleanupScheduleExp = app.node.tryGetContext(
16+
'cognitoCleanupScheduleExp'
17+
);
1718
// Get the config for the current stage
1819
const { resourceConfig }: { resourceConfig: UGCResourceWithChannelsConfig } =
1920
app.node.tryGetContext(stage);
@@ -25,8 +26,7 @@ new UGCStack(app, stackName, {
2526
tags: { stage, project: 'ugc' },
2627
resourceConfig,
2728
shouldPublish,
28-
cognitoCleanupScheduleExp,
29-
stageCleanupScheduleExp
29+
cognitoCleanupScheduleExp
3030
});
3131

3232
new UGCFrontendDeploymentStack(app, `UGC-Frontend-Deployment-${stage}`, {

cdk/lambdas/cleanupIdleStages.ts

Lines changed: 0 additions & 46 deletions
This file was deleted.

cdk/lib/ChannelsStack/cdk-channels-stack.ts

Lines changed: 17 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ import {
77
aws_events as events,
88
aws_events_targets as targets,
99
aws_iam as iam,
10-
aws_lambda as lambda,
1110
aws_lambda_nodejs as nodejsLambda,
1211
aws_s3 as s3,
1312
aws_s3_notifications as s3n,
14-
aws_sqs as sqs,
1513
Duration,
1614
NestedStack,
1715
NestedStackProps,
@@ -43,7 +41,6 @@ interface ChannelsStackProps extends NestedStackProps {
4341
resourceConfig: ChannelsResourceConfig;
4442
tags: { [key: string]: string };
4543
cognitoCleanupScheduleExp: string;
46-
stageCleanupScheduleExp: string;
4744
}
4845

4946
export class ChannelsStack extends NestedStack {
@@ -70,12 +67,7 @@ export class ChannelsStack extends NestedStack {
7067
const region = Stack.of(this.nestedStackParent!).region;
7168
const nestedStackName = 'Channels';
7269
const stackNamePrefix = `${parentStackName}-${nestedStackName}`;
73-
const {
74-
resourceConfig,
75-
cognitoCleanupScheduleExp,
76-
stageCleanupScheduleExp,
77-
tags
78-
} = props;
70+
const { resourceConfig, cognitoCleanupScheduleExp, tags } = props;
7971

8072
// Configuration variables based on the stage (dev or prod)
8173
const {
@@ -496,21 +488,6 @@ export class ChannelsStack extends NestedStack {
496488
resources: [userPool.userPoolArn]
497489
});
498490

499-
// Cleanup idle stages lambda
500-
const cleanupIdleStagesHandler = new nodejsLambda.NodejsFunction(
501-
this,
502-
`${stackNamePrefix}-CleanupIdleStages-Handler`,
503-
{
504-
logRetention: 7,
505-
runtime: lambda.Runtime.NODEJS_16_X,
506-
bundling: { minify: true },
507-
functionName: `${stackNamePrefix}-CleanupIdleStages`,
508-
entry: getLambdaEntryPath('cleanupIdleStages'),
509-
timeout: Duration.minutes(10),
510-
initialPolicy: [deleteIdleStagesIvsPolicyStatement]
511-
}
512-
);
513-
514491
// Cleanup unverified users lambda
515492
const cleanupUnverifiedUsersHandler = new nodejsLambda.NodejsFunction(
516493
this,
@@ -528,18 +505,6 @@ export class ChannelsStack extends NestedStack {
528505
}
529506
);
530507

531-
// Scheduled cleanup idle stages lambda function
532-
new events.Rule(this, 'Cleanup-Idle-Stages-Schedule-Rule', {
533-
schedule: events.Schedule.expression(stageCleanupScheduleExp),
534-
ruleName: `${stackNamePrefix}-CleanupIdleStages-Schedule`,
535-
targets: [
536-
new targets.LambdaFunction(cleanupIdleStagesHandler, {
537-
maxEventAge: Duration.minutes(2),
538-
retryAttempts: 2
539-
})
540-
]
541-
});
542-
543508
// Scheduled cleanup unverified users lambda function
544509
new events.Rule(this, 'Cleanup-Unverified-Users-Schedule-Rule', {
545510
schedule: events.Schedule.expression(cognitoCleanupScheduleExp),
@@ -553,29 +518,32 @@ export class ChannelsStack extends NestedStack {
553518
});
554519

555520
// Create a SQS message on Stage Participant Unpublished event
556-
const unpublishedParticipantRule = new events.Rule(this, `${stackNamePrefix}-UnpublishedParticipant-Rule`, {
557-
ruleName: `${stackNamePrefix}-UnpublishedParticipant-Rule`,
558-
eventPattern: {
559-
source: ['aws.ivs'],
560-
detailType: ['IVS Stage Update'],
561-
detail: {
562-
'event_name': ['Participant Unpublished'],
563-
'user_id': [{ 'prefix': 'host:' }]
521+
const unpublishedParticipantRule = new events.Rule(
522+
this,
523+
`${stackNamePrefix}-UnpublishedParticipant-Rule`,
524+
{
525+
ruleName: `${stackNamePrefix}-UnpublishedParticipant-Rule`,
526+
eventPattern: {
527+
source: ['aws.ivs'],
528+
detailType: ['IVS Stage Update'],
529+
detail: {
530+
event_name: ['Participant Unpublished'],
531+
user_id: [{ prefix: 'host:' }]
532+
}
564533
}
565534
}
566-
});
535+
);
567536

568537
unpublishedParticipantRule.addTarget(
569538
new targets.SqsQueue(deleteStageQueue, {
570539
messageGroupId: MESSAGE_GROUP_IDS.DELETE_STAGE_MESSAGE,
571-
message:
572-
RuleTargetInput.fromObject({
540+
message: RuleTargetInput.fromObject({
573541
stageArn: EventField.fromPath('$.resources[0]'),
574542
sessionId: EventField.fromPath('$.detail.session_id'),
575-
userId: EventField.fromPath('$.detail.user_id'),
543+
userId: EventField.fromPath('$.detail.user_id')
576544
})
577545
})
578-
)
546+
);
579547

580548
const containerEnv = {
581549
CHANNEL_ASSETS_BUCKET_NAME: channelAssetsBucket.bucketName,

cdk/lib/cdk-ugc-stack.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,19 @@ const DEFAULT_CLIENT_BASE_URLS = ['', 'http://localhost:3000'];
2828
interface UGCDashboardStackProps extends StackProps {
2929
resourceConfig: UGCResourceWithChannelsConfig;
3030
cognitoCleanupScheduleExp: string;
31-
stageCleanupScheduleExp: string;
3231
shouldPublish: boolean;
3332
}
3433

3534
export class UGCStack extends Stack {
3635
constructor(scope: Construct, id: string, props: UGCDashboardStackProps) {
3736
super(scope, id, props);
3837

39-
const { resourceConfig, cognitoCleanupScheduleExp, stageCleanupScheduleExp, shouldPublish, tags = {} } = props;
38+
const {
39+
resourceConfig,
40+
cognitoCleanupScheduleExp,
41+
shouldPublish,
42+
tags = {}
43+
} = props;
4044
const {
4145
deploySeparateContainers,
4246
ivsChannelType,
@@ -137,7 +141,6 @@ export class UGCStack extends Stack {
137141
const channelsStack = new ChannelsStack(this, 'Channels', {
138142
resourceConfig,
139143
cognitoCleanupScheduleExp,
140-
stageCleanupScheduleExp,
141144
tags
142145
});
143146
const {
@@ -366,9 +369,15 @@ export class UGCStack extends Stack {
366369
value: `${enableAmazonProductStreamAction}`
367370
});
368371
new CfnOutput(this, 'channelType', { value: ivsChannelType });
369-
new CfnOutput(this, 'appSyncGraphQlApiKey', { value: appSyncGraphQlApi.apiKey })
370-
new CfnOutput(this, 'appSyncGraphQlApiEndpoint', { value: appSyncGraphQlApi.endpoint })
371-
new CfnOutput(this, 'appSyncGraphQlAuthenticationType', { value: appSyncGraphQlApi.authType })
372+
new CfnOutput(this, 'appSyncGraphQlApiKey', {
373+
value: appSyncGraphQlApi.apiKey
374+
});
375+
new CfnOutput(this, 'appSyncGraphQlApiEndpoint', {
376+
value: appSyncGraphQlApi.endpoint
377+
});
378+
new CfnOutput(this, 'appSyncGraphQlAuthenticationType', {
379+
value: appSyncGraphQlApi.authType
380+
});
372381

373382
if (frontendAppBaseUrl) {
374383
new CfnOutput(this, 'frontendAppBaseUrl', {

0 commit comments

Comments
 (0)