Skip to content

Commit

Permalink
build: set lambda to log as JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
blacha committed Oct 21, 2024
1 parent 6655441 commit 45e0b51
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 68 deletions.
152 changes: 92 additions & 60 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/_infra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"@basemaps/lambda-tiler": "^7.11.0",
"@basemaps/shared": "^7.11.0",
"@linzjs/cdk-tags": "^1.7.0",
"aws-cdk": "2.114.x",
"aws-cdk-lib": "2.114.x",
"constructs": "^10.3.0"
"aws-cdk": "2.162.x",
"aws-cdk-lib": "2.162.x",
"constructs": "^10.4.2"
}
}
11 changes: 6 additions & 5 deletions packages/_infra/src/analytics/edge.analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Env } from '@basemaps/shared';
import { Duration, Stack, StackProps } from 'aws-cdk-lib';
import { Rule, Schedule } from 'aws-cdk-lib/aws-events';
import { LambdaFunction } from 'aws-cdk-lib/aws-events-targets';
import lf from 'aws-cdk-lib/aws-lambda';
import lambda from 'aws-cdk-lib/aws-lambda';
import { RetentionDays } from 'aws-cdk-lib/aws-logs';
import { BlockPublicAccess, Bucket } from 'aws-cdk-lib/aws-s3';
import { Construct } from 'constructs';
Expand All @@ -18,7 +18,7 @@ export interface EdgeAnalyticsProps extends StackProps {
* Every hour create analytics based off the logs given to us from cloudwatch
*/
export class EdgeAnalytics extends Stack {
public lambda: lf.Function;
public lambda: lambda.Function;

public constructor(scope: Construct, id: string, props: EdgeAnalyticsProps) {
super(scope, id, props);
Expand All @@ -31,19 +31,20 @@ export class EdgeAnalytics extends Stack {
blockPublicAccess: BlockPublicAccess.BLOCK_ALL,
});

this.lambda = new lf.Function(this, 'AnalyticLambda', {
runtime: lf.Runtime.NODEJS_18_X,
this.lambda = new lambda.Function(this, 'AnalyticLambda', {
runtime: lambda.Runtime.NODEJS_18_X,
memorySize: 2048,
timeout: Duration.minutes(10),
handler: 'index.handler',
code: lf.Code.fromAsset(CODE_PATH),
code: lambda.Code.fromAsset(CODE_PATH),
environment: {
[Env.Analytics.CloudFrontId]: distributionId,
[Env.Analytics.CacheBucket]: `s3://${cacheBucket.bucketName}`,
[Env.Analytics.CloudFrontSourceBucket]: `s3://${logBucket.bucketName}`,
AWS_NODEJS_CONNECTION_REUSE_ENABLED: '1',
},
logRetention: RetentionDays.ONE_MONTH,
loggingFormat: lambda.LoggingFormat.JSON,
});

cacheBucket.grantReadWrite(this.lambda);
Expand Down
1 change: 1 addition & 0 deletions packages/_infra/src/serve/lambda.tiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class LambdaTiler extends Construct {
architecture: lambda.Architecture.ARM_64,
environment,
logRetention: RetentionDays.ONE_MONTH,
loggingFormat: lambda.LoggingFormat.JSON,
});

this.functionUrl = new lambda.FunctionUrl(this, 'LambdaCogUrl', {
Expand Down

0 comments on commit 45e0b51

Please sign in to comment.