-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-function.ts
55 lines (53 loc) · 2.06 KB
/
create-function.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// ~~ Generated by projen. To modify, edit .projenrc.ts and run "npx projen".
import * as path from 'path';
// eslint-disable-next-line import/no-extraneous-dependencies
import { LogLevel } from '@aws-lambda-powertools/logger/lib/types';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import { Stack, ArnFormat } from 'aws-cdk-lib/core';
import { Construct } from 'constructs';
import { LambdaMonitor } from '../constructs/monitoring';
import { Env } from '../types';
/**
* Props for CreateFunction
*/
export interface CreateFunctionProps extends lambda.FunctionOptions {
readonly logLevel?: LogLevel;
readonly env?: Env;
}
/**
* An AWS Lambda function which executes src/posts/create.
*/
export class CreateFunction extends lambda.Function {
public readonly lambdaMonitor: LambdaMonitor;
constructor(scope: Construct, id: string, props: CreateFunctionProps) {
super(scope, id, {
description: 'src/posts/create.lambda.ts',
...props,
environment: {
LOG_LEVEL: props?.logLevel ?? 'DEBUG',
POWERTOOLS_LOGGER_LOG_EVENT: 'true',
POWERTOOLS_SERVICE_NAME: 'CreateFunction',
POWERTOOLS_METRICS_NAMESPACE: 'blogApp',
ENV: props?.env ?? Env.DEV,
...props?.environment,
},
layers: [
lambda.LayerVersion.fromLayerVersionArn(scope, 'PowertoolsLayer', Stack.of(scope).formatArn({
resource: 'layer',
service: 'lambda',
arnFormat: ArnFormat.COLON_RESOURCE_NAME,
resourceName: 'AWSLambdaPowertoolsTypeScript:15',
account: '094274105915',
})),
],
memorySize: props?.memorySize ?? 256,
tracing: lambda.Tracing.ACTIVE,
architecture: lambda.Architecture.ARM_64,
runtime: new lambda.Runtime('nodejs18.x', lambda.RuntimeFamily.NODEJS),
handler: 'index.handler',
code: lambda.Code.fromAsset(path.join(__dirname, '../../assets/posts/create.lambda')),
});
this.addEnvironment('AWS_NODEJS_CONNECTION_REUSE_ENABLED', '1', { removeInEdge: true });
this.lambdaMonitor = new LambdaMonitor('CreateFunction', this);
}
}