-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Expand file tree
/
Copy pathstack.ts
More file actions
40 lines (35 loc) · 1.51 KB
/
stack.ts
File metadata and controls
40 lines (35 loc) · 1.51 KB
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
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import type { StackProps } from "aws-cdk-lib";
import { CfnOutput, Stack } from "aws-cdk-lib";
import { ServicePrincipal } from "aws-cdk-lib/aws-iam";
import { Runtime } from "aws-cdk-lib/aws-lambda";
import { NodejsFunction } from "aws-cdk-lib/aws-lambda-nodejs";
import type { Construct } from "constructs";
import { PoolsAndTriggersBase } from "./base";
export class PoolsAndTriggersStack extends Stack {
functions: Record<string, NodejsFunction>;
poolsAndTriggersBase = new PoolsAndTriggersBase(this, "PoolsAndTriggersBase");
cognitoPrincipal = new ServicePrincipal("cognito-idp.amazonaws.com");
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
this.createFunction("AutoConfirmHandler");
this.poolsAndTriggersBase.outputs(this);
}
createFunction(name: string): NodejsFunction {
const fn = new NodejsFunction(this, name, {
// An "entry" property is optional. By default, NodejsFunction
// will look for a file named `${this.stackName}.${name}.ts`
// entry: "",
environment: {
TABLE_NAME: this.poolsAndTriggersBase.tableName,
},
role: this.poolsAndTriggersBase.lambdaRole,
runtime: Runtime.NODEJS_20_X,
});
fn.grantInvoke(this.cognitoPrincipal);
new CfnOutput(this, `${name}Name`, { value: fn.functionName });
new CfnOutput(this, `${name}Arn`, { value: fn.functionArn });
return fn;
}
}