-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
79 lines (73 loc) · 3.03 KB
/
index.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { join } from "node:path";
import { aws_cloudformation, aws_iam, aws_lambda, aws_lambda_nodejs, Stack, StackProps } from "aws-cdk-lib";
import { Construct } from "constructs";
export class MyStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
const c = new aws_lambda_nodejs.NodejsFunction(this, "ChangeSetFunction", {
applicationLogLevelV2: aws_lambda.ApplicationLogLevel.DEBUG,
architecture: aws_lambda.Architecture.ARM_64,
bundling: {
format: aws_lambda_nodejs.OutputFormat.ESM,
target: "esnext",
},
entry: join(import.meta.dirname, "../handlers/change-set.ts"),
loggingFormat: aws_lambda.LoggingFormat.JSON,
runtime: aws_lambda.Runtime.NODEJS_22_X,
});
const t = new aws_lambda_nodejs.NodejsFunction(this, "TemplateFunction", {
applicationLogLevelV2: aws_lambda.ApplicationLogLevel.DEBUG,
architecture: aws_lambda.Architecture.ARM_64,
bundling: {
format: aws_lambda_nodejs.OutputFormat.ESM,
target: "esnext",
},
entry: join(import.meta.dirname, "../handlers/template.ts"),
loggingFormat: aws_lambda.LoggingFormat.JSON,
runtime: aws_lambda.Runtime.NODEJS_22_X,
});
const hooksRole = new aws_iam.Role(this, "HooksRole", {
assumedBy: new aws_iam.ServicePrincipal("hooks.cloudformation.amazonaws.com"),
path: "/",
inlinePolicies: {
LambdaInvokerHookPolicy: new aws_iam.PolicyDocument({
statements: [
new aws_iam.PolicyStatement({
effect: aws_iam.Effect.ALLOW,
actions: ["lambda:InvokeFunction"],
resources: [c.functionArn, t.functionArn],
}),
],
}),
},
});
new aws_cloudformation.CfnLambdaHook(this, "ChangeSetHook", {
alias: "Test::Lambda::ChangeSetHook",
executionRole: hooksRole.roleArn,
failureMode: "WARN",
hookStatus: "ENABLED",
lambdaFunction: c.functionArn,
stackFilters: {
filteringCriteria: "ALL",
stackNames: {
exclude: [this.stackName],
},
},
targetOperations: ["CHANGE_SET"],
});
new aws_cloudformation.CfnLambdaHook(this, "StackHook", {
alias: "Test::Lambda::StackHook",
executionRole: hooksRole.roleArn,
failureMode: "WARN",
hookStatus: "ENABLED",
lambdaFunction: t.functionArn,
stackFilters: {
filteringCriteria: "ALL",
stackNames: {
exclude: [this.stackName],
},
},
targetOperations: ["STACK"],
});
}
}