-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changing from esbuild to tsc because we are not bundling dist anymore
- Loading branch information
Flavio Stutz
committed
Jan 13, 2024
1 parent
0e3ccdf
commit 21196dc
Showing
8 changed files
with
159 additions
and
1,228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* eslint-disable no-new */ | ||
import { App } from 'aws-cdk-lib/core'; | ||
|
||
import { resolveStackNameAndPropsForStage } from '../cdk-shared2-nn/stack'; | ||
import { globalConfig } from '../cdk-shared3-monorepo/globals'; | ||
|
||
import { AppStack } from './stack'; | ||
|
||
const { STAGE } = requireEnvVars(['STAGE']); | ||
|
||
const app = new App(); | ||
|
||
const { stackName, stackProps } = resolveStackNameAndPropsForStage({ | ||
stage: STAGE, | ||
globalConfig, | ||
serviceName: 'splunk-forward-service', | ||
snowApplicationServiceNamePrefix: 'Splunk Forward Service', | ||
}); | ||
|
||
new AppStack(app, stackName, stackProps); | ||
|
||
app.synth(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* eslint-disable camelcase */ | ||
|
||
import { RetentionDays } from 'aws-cdk-lib/aws-logs'; | ||
|
||
// Global configs | ||
export const globalConfig = { | ||
default: { | ||
env: { | ||
region: 'us-east-1', | ||
}, | ||
lambda: { | ||
allowTLSOutboundTo: '10.0.0.0/8', | ||
logRetention: RetentionDays.ONE_WEEK, | ||
}, | ||
services: defaultServicesConfig, | ||
}, | ||
dev: { | ||
lambda: {}, | ||
}, | ||
tst: { | ||
lambda: { | ||
logRetention: RetentionDays.ONE_WEEK, | ||
}, | ||
}, | ||
acc: { | ||
lambda: { | ||
logRetention: RetentionDays.ONE_MONTH, | ||
}, | ||
}, | ||
prd: { | ||
lambda: { | ||
logRetention: RetentionDays.SIX_MONTHS, | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* eslint-disable camelcase */ | ||
import { ScopedAws } from 'aws-cdk-lib'; | ||
import { Construct } from 'constructs'; | ||
import { PolicyStatement } from 'aws-cdk-lib/aws-iam'; | ||
import { Peer, Port } from 'aws-cdk-lib/aws-ec2'; | ||
import { StringParameter } from 'aws-cdk-lib/aws-ssm'; | ||
|
||
import { DefaultStackProps } from '../cdk-shared2-nn/stack'; | ||
import { EventType } from '../cdk-shared1-public/constructs/lambda/types'; | ||
import { BaseNodeJsFunction } from '../cdk-shared1-public/constructs/lambda/lambda-base'; | ||
import { DefaultStack } from '../cdk-shared2-nn/constructs/default-stack'; | ||
|
||
export class AppStack extends DefaultStack { | ||
constructor(scope: Construct, id: string, props: DefaultStackProps) { | ||
super(scope, id, props); | ||
|
||
const { accountId, region } = new ScopedAws(this); | ||
|
||
// eslint-disable-next-line no-new | ||
const func = new BaseNodeJsFunction(this, 'splunkForward', { | ||
...props.stageConfig.lambda, | ||
stage: props.stage, | ||
network: props.stageConfig.network, | ||
eventType: EventType.Cloudwatch, | ||
description: 'Forwards Cloudwatch events to Splunk', | ||
initialPolicy: [ | ||
PolicyStatement.fromJson({ | ||
Effect: 'Allow', | ||
Action: 'secretsmanager:GetSecretValue', | ||
Resource: `arn:aws:secretsmanager:${region}:${accountId}:secret:services/splunk-forward-service/splunk-hec-token*`, | ||
}), | ||
], | ||
}); | ||
func.defaultSecurityGroup.addEgressRule( | ||
Peer.ipv4('10.109.0.0/16'), | ||
Port.tcp(8088), | ||
'Allow connection to Splunk Collector', | ||
); | ||
|
||
// Store splunk forward lambda arn in parameter store | ||
// eslint-disable-next-line no-new | ||
new StringParameter(this, 'SplunkForwardLambdaArn', { | ||
parameterName: `/${props.stage}/services/splunk-forward-service/lambda-arn`, | ||
description: 'Cloudwatch to Splunk log forwarder Lambda ARN', | ||
stringValue: func.nodeJsFunction.functionArn, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* eslint-disable camelcase */ | ||
|
||
import { NetworkConfig } from '../../src/lambda/types'; | ||
|
||
// https://stackoverflow.com/questions/43159887/make-a-single-property-optional-in-typescript | ||
export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>; | ||
|
||
/** | ||
* Configurations resolved for a specific stage | ||
*/ | ||
export type StageConfig = { | ||
services: ServiceConfig; | ||
lambda: GlobalLambdaConfig; | ||
env: { | ||
account?: string; | ||
region: string; | ||
}; | ||
network?: NetworkConfig; | ||
}; | ||
|
||
/** | ||
* Global configurations | ||
* This will be used to resolve configurations for specific stages | ||
*/ | ||
export type GlobalConfig = { | ||
default: StageConfig; | ||
dev?: StageConfig; | ||
tst: StageConfig; | ||
acc: StageConfig; | ||
prd: StageConfig; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.