-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathlambda-durable-execution-java-stack.ts
More file actions
52 lines (45 loc) · 1.8 KB
/
lambda-durable-execution-java-stack.ts
File metadata and controls
52 lines (45 loc) · 1.8 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
41
42
43
44
45
46
47
48
49
50
51
52
import * as cdk from "aws-cdk-lib";
import * as lambda from "aws-cdk-lib/aws-lambda";
import * as iam from "aws-cdk-lib/aws-iam";
import { Construct } from "constructs";
export class LambdaDurableExecutionJavaStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
// Lambda function
const fn = new lambda.Function(this, "DurableOrderProcessorFn", {
runtime: lambda.Runtime.JAVA_17,
handler: "com.example.OrderProcessor::handleRequest",
code: lambda.Code.fromAsset("src/target/lambda-durable-execution-java-1.0.0.jar"),
timeout: cdk.Duration.minutes(15),
memorySize: 512,
description: "Durable order processing workflow using Java SDK",
});
// Enable durable execution via escape hatch
const cfnFn = fn.node.defaultChild as lambda.CfnFunction;
cfnFn.addOverride("Properties.DurableConfig", {
ExecutionTimeout: 3600,
RetentionPeriodInDays: 7,
});
// Durable execution permissions via AWS managed policy
fn.role!.addManagedPolicy(
iam.ManagedPolicy.fromAwsManagedPolicyName(
"service-role/AWSLambdaBasicDurableExecutionRolePolicy"
)
);
// Version and alias via L1 to avoid CDK version property validation
const version = new lambda.CfnVersion(this, "FnVersion", {
functionName: fn.functionName,
description: "Durable execution version",
});
const alias = new lambda.CfnAlias(this, "ProdAlias", {
functionName: fn.functionName,
functionVersion: version.attrVersion,
name: "prod",
});
new cdk.CfnOutput(this, "FunctionName", { value: fn.functionName });
new cdk.CfnOutput(this, "FunctionAliasArn", {
value: alias.ref,
description: "Use this ARN to invoke the durable function",
});
}
}