Skip to content

Commit

Permalink
hotfix: replace stream session ended (#21)
Browse files Browse the repository at this point in the history
* chore: upgrade aws cdk dep to latest

* refactor: moved defaultLamdaParams constant to cdk-channels-stack so the params can be passed into channel resources

* hotfix: replace session ended event with stream end - streams do not always get the session ended event

* chore: upgrade IVS sdk scripts to latest

* doc: update Amazon Associate link url to correct url in README

* hotfix: format

* refactor: defaultLambdaParams remove logRetention and moved const to shared constant file

* fix: update defaultLambdaParams type to Partial of Lambda  NodejsFunctionProps type

* refactor: update all CDK lambdas logRetention to use enum RetentionDays
  • Loading branch information
drewhan90 authored May 23, 2024
1 parent 0866508 commit 974dd12
Show file tree
Hide file tree
Showing 11 changed files with 3,032 additions and 7,159 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ To set your Product Advertising API credentials you must:

After deployment, through [Amazon OneLink](https://affiliate-program.amazon.com/resource-center/onelink-launch), you can best earn money via product affiliate links by redirecting international traffic to the appropriate Amazon store for their location, increasing the likelihood that they will make a purchase. To get started:

1. Sign up for Amazon Associates: To use Amazon OneLink, you need to be an [Amazon Associate](https://associates.amazon.ca/). If you're not already signed up, go to the Amazon Associates website and create an account.
1. Sign up for Amazon Associates: To use Amazon OneLink, you need to be an [Amazon Associate](https://affiliate-program.amazon.com/). If you're not already signed up, go to the Amazon Associates website and create an account.

2. Enable OneLink: Once you've signed up for Amazon Associates, navigate to the 'Manage Tracking IDs' section located at the top right-hand corner
of the Amazon Associates portal.
Expand Down
14 changes: 6 additions & 8 deletions cdk/lib/ChannelsStack/Constructs/ChannelsCognitoTriggers.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { aws_lambda_nodejs as lambda } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { join } from 'path';
import { Runtime } from 'aws-cdk-lib/aws-lambda';

import { ChannelsResourceConfig } from '../../constants';
import { ChannelsResourceConfig, defaultLambdaParams } from '../../constants';

interface ChannelsCognitoTriggersProps extends ChannelsResourceConfig {}

Expand All @@ -25,18 +24,17 @@ export default class ChannelsCognitoTriggers extends Construct {
const { logRetention, enableUserAutoVerify, clientBaseUrl } = props;

// Default lambda parameters
const defaultLambdaParams = {
const defaultCognitoLambdaParams = {
...(logRetention ? { logRetention } : {}),
bundling: { minify: true },
runtime: Runtime.NODEJS_16_X
...defaultLambdaParams
};

// Lambda to auto verify new users, not suitable for production
let preSignUpLambda;

if (enableUserAutoVerify) {
preSignUpLambda = new lambda.NodejsFunction(this, 'PreSignUpLambda', {
...defaultLambdaParams,
...defaultCognitoLambdaParams,
entry: getCognitoLambdaTriggersEntryPath('preSignUp'),
environment: { ENABLE_USER_AUTO_VERIFY: `${enableUserAutoVerify}` }
});
Expand All @@ -48,7 +46,7 @@ export default class ChannelsCognitoTriggers extends Construct {
this,
'CustomMessageLambda',
{
...defaultLambdaParams,
...defaultCognitoLambdaParams,
entry: getCognitoLambdaTriggersEntryPath('customMessage'),
environment: {
CLIENT_BASE_URL: clientBaseUrl
Expand All @@ -62,7 +60,7 @@ export default class ChannelsCognitoTriggers extends Construct {
this,
'PreAuthenticationLambda',
{
...defaultLambdaParams,
...defaultCognitoLambdaParams,
entry: getCognitoLambdaTriggersEntryPath('preAuthentication')
}
);
Expand Down
10 changes: 5 additions & 5 deletions cdk/lib/ChannelsStack/cdk-channels-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
aws_events as events,
aws_events_targets as targets,
aws_iam as iam,
aws_lambda as lambda,
aws_lambda_nodejs as nodejsLambda,
aws_s3 as s3,
aws_s3_notifications as s3n,
Expand All @@ -19,11 +18,13 @@ import {
} from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { ProjectionType } from 'aws-cdk-lib/aws-dynamodb';
import { RetentionDays } from 'aws-cdk-lib/aws-logs';
import { Secret } from 'aws-cdk-lib/aws-secretsmanager';

import {
ALLOWED_CHANNEL_ASSET_TYPES,
ChannelsResourceConfig
ChannelsResourceConfig,
defaultLambdaParams
} from '../constants';
import ChannelsCognitoTriggers from './Constructs/ChannelsCognitoTriggers';
import SQSLambdaTrigger from '../Constructs/SQSLambdaTrigger';
Expand Down Expand Up @@ -406,9 +407,8 @@ export class ChannelsStack extends NestedStack {
this,
`${stackNamePrefix}-CleanupUnverifiedUsers-Handler`,
{
logRetention: 7,
runtime: lambda.Runtime.NODEJS_16_X,
bundling: { minify: true },
...defaultLambdaParams,
logRetention: RetentionDays.ONE_WEEK,
functionName: `${stackNamePrefix}-CleanupUnverifiedUsers`,
entry: getLambdaEntryPath('cleanupUnverifiedUsers'),
timeout: Duration.minutes(10),
Expand Down
16 changes: 7 additions & 9 deletions cdk/lib/Constructs/SQSLambdaTrigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import {
} from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { join } from 'path';
import { Runtime } from 'aws-cdk-lib/aws-lambda';
import { RetentionDays } from 'aws-cdk-lib/aws-logs';

import { defaultLambdaParams } from '../constants';

type FunctionProps = lambda.NodejsFunctionProps & {
entryFunctionName: string;
Expand Down Expand Up @@ -74,28 +76,24 @@ export default class SQSLambdaTrigger extends Construct {
* Lambda Triggers
*/

const defaultLambdaProps = {
bundling: { minify: true },
runtime: Runtime.NODEJS_16_X
};
// Source Queue Lambda Trigger
this.srcLambda = new lambda.NodejsFunction(this, `${srcId}-Lambda`, {
...defaultLambdaProps,
...defaultLambdaParams,
functionName: `${srcId}-handler`,
entry: srcHandlerEntry || getLambdaEntryPath(srcHandlerEntryFunctionName),
description:
'Triggered by Amazon SQS when new messages arrive in the queue',
logRetention: 7,
logRetention: RetentionDays.ONE_WEEK,
...srcHandlerProps
});
// Dead-letter Queue Lambda Trigger
this.dlqLambda = new lambda.NodejsFunction(this, `${dlqId}-Lambda`, {
...defaultLambdaProps,
...defaultLambdaParams,
functionName: `${dlqId}-handler`,
entry: dlqHandlerEntry || getLambdaEntryPath(dlqHandlerEntryFunctionName),
description:
'Triggered by Amazon SQS to handle message consumption failures and gracefully manage the life cycle of unconsumed messages',
logRetention: 14,
logRetention: RetentionDays.TWO_WEEKS,
...dlqHandlerProps
});

Expand Down
7 changes: 7 additions & 0 deletions cdk/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import {
aws_elasticloadbalancingv2 as elbv2,
aws_lambda_nodejs as lambda,
aws_logs as logs
} from 'aws-cdk-lib';
import { ChannelType, TranscodePreset } from '@aws-sdk/client-ivs';
import { Runtime } from 'aws-cdk-lib/aws-lambda';

export interface UGCResourceWithChannelsConfig extends ChannelsResourceConfig {
deploySeparateContainers: boolean;
Expand All @@ -25,6 +27,11 @@ export interface ChannelsResourceConfig {
signUpAllowedDomains: string[];
}

export const defaultLambdaParams: Partial<lambda.NodejsFunctionProps> = {
bundling: { minify: true },
runtime: Runtime.NODEJS_18_X
};

export const defaultTargetProps: Partial<elbv2.AddApplicationTargetsProps> = {
healthCheck: { path: '/status' },
port: 8080,
Expand Down
Loading

0 comments on commit 974dd12

Please sign in to comment.