|
| 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'; |
1 | 6 | import { Construct } from 'constructs';
|
| 7 | +import { ParserFunction } from './funcs/parser-function'; |
2 | 8 |
|
3 | 9 | export interface LogStreamEventTriggerProps {
|
4 | 10 | }
|
5 | 11 |
|
6 | 12 | export class LogStreamEventTrigger extends Construct {
|
7 | 13 | constructor(scope: Construct, id: string /** props?: LogStreamEventTriggerProps */ ) {
|
8 | 14 | 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 | + |
9 | 63 | }
|
10 | 64 | }
|
0 commit comments