Skip to content

Commit

Permalink
Merge pull request #102 from uatisdeproblem/chore-update-aws-logging
Browse files Browse the repository at this point in the history
chore: update AWS Logging
  • Loading branch information
rbento1096 authored Feb 22, 2024
2 parents 44000da + c5f8e3b commit 3792373
Show file tree
Hide file tree
Showing 22 changed files with 348 additions and 276 deletions.
11 changes: 8 additions & 3 deletions back-end/deploy/api-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface ApiProps extends cdk.StackProps {
ses: { identityArn: string; notificationTopicArn: string };
cognito: { userPoolId: string; audience: string[] };
removalPolicy: RemovalPolicy;
lambdaLogLevel: 'TRACE' | 'DEBUG' | 'INFO' | 'WARN' | 'ERROR' | 'FATAL';
}
export interface ResourceController {
name: string;
Expand All @@ -48,7 +49,8 @@ const defaultLambdaFnProps: NodejsFunctionProps = {
memorySize: 1024,
bundling: { minify: true, sourceMap: true },
environment: { NODE_OPTIONS: '--enable-source-maps' },
logRetention: RetentionDays.TWO_WEEKS
logRetention: RetentionDays.TWO_WEEKS,
logFormat: Lambda.LogFormat.JSON
};

const defaultDDBTableProps: DDB.TableProps | any = {
Expand Down Expand Up @@ -77,7 +79,8 @@ export class ApiStack extends cdk.Stack {
defaultLambdaFnProps,
project: props.project,
stage: props.stage,
versionStatus: props.versionStatus
versionStatus: props.versionStatus,
lambdaLogLevel: props.lambdaLogLevel
});
this.allowLambdaFunctionsToAccessCognitoUserPool({
cognitoUserPoolId: props.cognito.userPoolId,
Expand Down Expand Up @@ -172,6 +175,7 @@ export class ApiStack extends cdk.Stack {
defaultLambdaFnProps: NodejsFunctionProps;
api: cdk.aws_apigatewayv2.CfnApi;
versionStatus: VersionStatus;
lambdaLogLevel: 'TRACE' | 'DEBUG' | 'INFO' | 'WARN' | 'ERROR' | 'FATAL';
}): {
lambdaFunctions: { [resourceName: string]: NodejsFunction };
} {
Expand All @@ -189,7 +193,8 @@ export class ApiStack extends cdk.Stack {
const lambdaFn = new NodejsFunction(this, resource.name.concat('Function'), {
...params.defaultLambdaFnProps,
functionName: lambdaFnName,
entry: `./src/handlers/${resource.name}.ts`
entry: `./src/handlers/${resource.name}.ts`,
applicationLogLevel: params.lambdaLogLevel
});

// link the Lambda function to the Resource Controller's paths (if any)
Expand Down
10 changes: 8 additions & 2 deletions back-end/deploy/environments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ export const stages: { [stage: string]: Stage } = {
domain: 'egm-app.click',
alternativeDomain: 'app.erasmusgeneration.org',
frontEndCertificateARN: 'arn:aws:acm:us-east-1:767203414619:certificate/a82a1829-9d1b-4e0e-a2e7-fda8ef7a72d6',
destroyDataOnDelete: false
destroyDataOnDelete: false,
logLevel: 'INFO'
},
dev: {
domain: 'dev.egm-app.click',
frontEndCertificateARN: 'arn:aws:acm:us-east-1:767203414619:certificate/fb400353-44df-4148-a1f7-53f180c7db70',
destroyDataOnDelete: true
destroyDataOnDelete: true,
logLevel: 'DEBUG'
}
};

Expand Down Expand Up @@ -72,6 +74,10 @@ export interface Stage {
* It should be True for dev and False for prod environments.
*/
destroyDataOnDelete: boolean;
/**
* The minimum level of log to print in functions (default: `INFO`).
*/
logLevel?: 'TRACE' | 'DEBUG' | 'INFO' | 'WARN' | 'ERROR' | 'FATAL';
}

export interface VersionStatus {
Expand Down
8 changes: 0 additions & 8 deletions back-end/deploy/idea-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ export class IDEAStack extends cdk.Stack {
pointInTimeRecovery: true
});

new DDB.Table(this, 'idea_ISID', {
tableName: 'idea_ISID',
partitionKey: { name: 'project', type: DDB.AttributeType.STRING },
sortKey: { name: 'id', type: DDB.AttributeType.STRING },
billingMode: DDB.BillingMode.PAY_PER_REQUEST,
pointInTimeRecovery: true
});

new DDB.Table(this, 'idea_atomicCounters', {
tableName: 'idea_atomicCounters',
partitionKey: { name: 'key', type: DDB.AttributeType.STRING },
Expand Down
1 change: 1 addition & 0 deletions back-end/deploy/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ const createApp = async (): Promise<void> => {
userPoolId: cognitoStack.userPool.userPoolId,
audience: [cognitoStack.clientFrontEnd.userPoolClientId, cognitoStack.clientBackEnd.userPoolClientId]
},
lambdaLogLevel: STAGE_VARIABLES.logLevel ?? 'INFO',
removalPolicy: STAGE_VARIABLES.destroyDataOnDelete ? cdk.RemovalPolicy.DESTROY : cdk.RemovalPolicy.RETAIN
});
apiStack.addDependency(mediaStack);
Expand Down
Loading

0 comments on commit 3792373

Please sign in to comment.