Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
fix(cellgeo): always log
Browse files Browse the repository at this point in the history
  • Loading branch information
coderbyheart committed Oct 23, 2020
1 parent 1306ac4 commit e0eb346
Showing 1 changed file with 30 additions and 31 deletions.
61 changes: 30 additions & 31 deletions cdk/resources/CellGeolocationApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ export class CellGeolocationApi extends CloudFormation.Resource {
cellgeo,
lambdas,
cdkLambdas,
enableLogging,
}: {
cellgeo: CellGeolocation
lambdas: LambdasWithLayer<BifravstLambdas>
cdkLambdas: LambdasWithLayer<CDKLambdas>
enableLogging?: boolean
},
) {
super(parent, id)
Expand Down Expand Up @@ -99,37 +97,38 @@ export class CellGeolocationApi extends CloudFormation.Resource {
autoDeploy: true,
})

if (enableLogging ?? false) {
const httpApiLogGroup = new CloudWatchLogs.LogGroup(
this,
`HttpApiLogGroup`,
{
removalPolicy: CloudFormation.RemovalPolicy.DESTROY,
logGroupName: `/${this.stack.stackName}/cellGeolocationApiAccessLogs`,
retention: CloudWatchLogs.RetentionDays.ONE_WEEK,
const httpApiLogGroup = new CloudWatchLogs.LogGroup(
this,
`HttpApiLogGroup`,
{
removalPolicy: CloudFormation.RemovalPolicy.RETAIN,
logGroupName: `/${this.stack.stackName}/cellGeolocationApiAccessLogs`,
retention:
this.node.tryGetContext('isTest') === true
? CloudWatchLogs.RetentionDays.ONE_DAY
: CloudWatchLogs.RetentionDays.ONE_WEEK,
},
)
this.stage.accessLogSettings = {
destinationArn: httpApiLogGroup.logGroupArn,
format: JSON.stringify({
requestId: '$context.requestId',
awsEndpointRequestId: '$context.awsEndpointRequestId',
requestTime: '$context.requestTime',
ip: '$context.identity.sourceIp',
protocol: '$context.protocol',
routeKey: '$context.routeKey',
status: '$context.status',
responseLength: '$context.responseLength',
integrationLatency: '$context.integrationLatency',
integrationStatus: '$context.integrationStatus',
integrationErrorMessage: '$context.integrationErrorMessage',
integration: {
status: '$context.integration.status',
},
)
this.stage.accessLogSettings = {
destinationArn: httpApiLogGroup.logGroupArn,
format: JSON.stringify({
requestId: '$context.requestId',
awsEndpointRequestId: '$context.awsEndpointRequestId',
requestTime: '$context.requestTime',
ip: '$context.identity.sourceIp',
protocol: '$context.protocol',
routeKey: '$context.routeKey',
status: '$context.status',
responseLength: '$context.responseLength',
integrationLatency: '$context.integrationLatency',
integrationStatus: '$context.integrationStatus',
integrationErrorMessage: '$context.integrationErrorMessage',
integration: {
status: '$context.integration.status',
},
}),
}
this.stage.node.addDependency(httpApiLogGroup)
}),
}
this.stage.node.addDependency(httpApiLogGroup)

// GET __health

Expand Down

0 comments on commit e0eb346

Please sign in to comment.