Skip to content

Commit 14a4757

Browse files
authored
Merge pull request #2 from gammarers/feature/second-happy-code
feat: second happy code
2 parents 4c26998 + 4e75365 commit 14a4757

File tree

3 files changed

+265
-0
lines changed

3 files changed

+265
-0
lines changed

src/index.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,64 @@
1+
import { CfnOutput, Duration, RemovalPolicy, Stack } from 'aws-cdk-lib';
2+
import * as iam from 'aws-cdk-lib/aws-iam';
3+
import * as lambda from 'aws-cdk-lib/aws-lambda';
4+
import * as destinations from 'aws-cdk-lib/aws-lambda-destinations';
5+
import * as logs from 'aws-cdk-lib/aws-logs';
16
import { Construct } from 'constructs';
7+
import { ParserFunction } from './funcs/parser-function';
28

39
export interface LogStreamEventTriggerProps {
410
}
511

612
export class LogStreamEventTrigger extends Construct {
713
constructor(scope: Construct, id: string /** props?: LogStreamEventTriggerProps */ ) {
814
super(scope, id);
15+
16+
// 👇 Get current account & region
17+
const account = Stack.of(this).account;
18+
const region = Stack.of(this).region;
19+
const partition = Stack.of(this).partition;
20+
21+
// SubscriptionFilterLogParserFunction
22+
23+
// 👇 parser Lambda Function
24+
const parserFunction = new ParserFunction(this, 'ParserFunction', {
25+
// functionName: undefined,
26+
architecture: lambda.Architecture.ARM_64,
27+
timeout: Duration.seconds(10),
28+
role: new iam.Role(this, 'ParserFunctionRole', {
29+
// roleName: `lambda-log-notification-func-${random}-exec-role`,
30+
assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'),
31+
managedPolicies: [
32+
iam.ManagedPolicy.fromAwsManagedPolicyName('service-role/AWSLambdaBasicExecutionRole'),
33+
],
34+
inlinePolicies: {
35+
['put-events-policy']: new iam.PolicyDocument({
36+
statements: [
37+
new iam.PolicyStatement({
38+
effect: iam.Effect.ALLOW,
39+
actions: ['events:PutEvents'],
40+
resources: [`arn:${partition}:events:${region}:${account}:event-bus/default`],
41+
}),
42+
],
43+
}),
44+
},
45+
}),
46+
logGroup: new logs.LogGroup(this, 'ParserFunctionLogGroup', {
47+
//logGroupName: `/aws/lambda/${functionName}`,
48+
retention: logs.RetentionDays.THREE_MONTHS,
49+
removalPolicy: RemovalPolicy.RETAIN_ON_UPDATE_OR_DELETE,
50+
}),
51+
logFormat: lambda.LogFormat.JSON,
52+
systemLogLevel: lambda.SystemLogLevel.INFO,
53+
applicationLogLevel: lambda.ApplicationLogLevel.INFO,
54+
onSuccess: new destinations.EventBridgeDestination(),
55+
// onFailure: new lambdaDestinations.EventBridgeDestination(),
56+
});
57+
new CfnOutput(this, 'OutPutParserFunctionName', {
58+
key: 'ParserFunctionName',
59+
value: parserFunction.functionName,
60+
exportName: 'ParserFunctionFunctionName',
61+
});
62+
963
}
1064
}

test/__snapshots__/trigger.default.test.ts.snap

Lines changed: 199 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/trigger.default.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ describe('LogStreamEventTrigger default Testing', () => {
1212

1313
const template = Template.fromStack(stack);
1414

15+
it('Should have one iam role existing', async () => {
16+
template.resourceCountIs('AWS::IAM::Role', 1);
17+
});
18+
19+
it('Should have one lambda function existing', async () => {
20+
template.resourceCountIs('AWS::Lambda::Function', 1);
21+
});
22+
23+
it('Should have one log group existing', async () => {
24+
template.resourceCountIs('AWS::Logs::LogGroup', 1);
25+
});
26+
1527
it('Should match snapshot', () => {
1628
expect(template.toJSON()).toMatchSnapshot();
1729
});

0 commit comments

Comments
 (0)