@@ -18,55 +18,42 @@ import { Construct } from "constructs";
18
18
import { NodejsFunction } from "aws-cdk-lib/aws-lambda-nodejs" ;
19
19
20
20
export class LambdaTsCdkStack extends cdk . Stack {
21
- constructor (
22
- scope : Construct ,
23
- id : string ,
24
- props : cdk . StackProps ,
25
- ) {
21
+ constructor ( scope : Construct , id : string , props : cdk . StackProps ) {
26
22
super ( scope , id , props ) ;
27
23
28
24
const greeter : lambda . Function = new NodejsFunction ( this , "GreeterService" , {
29
- runtime : lambda . Runtime . NODEJS_LATEST ,
25
+ runtime : lambda . Runtime . NODEJS_20_X ,
30
26
entry : "lib/lambda/handler.ts" ,
31
27
architecture : lambda . Architecture . ARM_64 ,
32
28
bundling : {
33
29
minify : true ,
34
30
sourceMap : true ,
35
31
} ,
36
- environment : {
37
- NODE_OPTIONS : "--enable-source-maps" ,
38
- } ,
39
- } ) ;
40
-
41
- const environment = new restate . SingleNodeRestateDeployment ( this , "Restate" , {
42
- // restateImage: "docker.io/restatedev/restate",
43
- // restateTag: "0.9",
44
- logGroup : new logs . LogGroup ( this , "RestateLogs" , {
45
- retention : logs . RetentionDays . ONE_MONTH ,
46
- removalPolicy : cdk . RemovalPolicy . DESTROY ,
47
- } ) ,
48
32
} ) ;
49
33
50
- new iam . Policy ( this , "AssumeAnyRolePolicy" , {
51
- statements : [
52
- new iam . PolicyStatement ( {
53
- sid : "AllowAssumeAnyRole" ,
54
- actions : [ "sts:AssumeRole" ] ,
55
- resources : [ "*" ] , // we don't know upfront what invoker roles we may be asked to assume at runtime
56
- } ) ,
57
- ] ,
58
- } ) . attachToRole ( environment . invokerRole ) ;
59
-
34
+ // This role is used by Restate to invoke Lambda service handlers; see https://docs.restate.dev/deploy/cloud for
35
+ // information on deploying services to Restate Cloud environments. For standalone environments, the EC2 instance
36
+ // profile can be used directly instead of creating a separate role.
60
37
const invokerRole = new iam . Role ( this , "InvokerRole" , {
61
- assumedBy : new iam . ArnPrincipal ( environment . invokerRole . roleArn ) ,
38
+ assumedBy : new iam . AccountRootPrincipal ( ) , // set up trust such that your Restate environment can assume this role
62
39
} ) ;
63
- invokerRole . grantAssumeRole ( environment . invokerRole ) ;
64
40
41
+ // You can reference an existing Restate environment you manage yourself or a Restate Cloud environment by
42
+ // configuring its address and optionally auth token. The deployer will use these settings to register the handlers.
65
43
const restateEnvironment = restate . RestateEnvironment . fromAttributes ( {
66
- adminUrl : environment . adminUrl ,
44
+ adminUrl : "https://restate.example.com:9070" , // pre-existing Restate server address not managed by this stack
67
45
invokerRole,
68
46
} ) ;
69
47
48
+ // Alternatively, you can deploy a standalone Restate server using the RestateServer construct. Please refer to
49
+ // https://docs.restate.dev/deploy/lambda/self-hosted and the construct documentation for details.
50
+ // const restateEnvironment = new restate.SingleNodeRestateDeployment(this, "Restate", {
51
+ // logGroup: new logs.LogGroup(this, "RestateLogs", {
52
+ // logGroupName: "/restate/server-logs",
53
+ // retention: logs.RetentionDays.ONE_MONTH,
54
+ // }),
55
+ // });
56
+
70
57
const deployer = new restate . ServiceDeployer ( this , "ServiceDeployer" , {
71
58
logGroup : new logs . LogGroup ( this , "Deployer" , {
72
59
retention : logs . RetentionDays . ONE_MONTH ,
@@ -75,9 +62,10 @@ export class LambdaTsCdkStack extends cdk.Stack {
75
62
} ) ;
76
63
77
64
deployer . deployService ( "Greeter" , greeter . currentVersion , restateEnvironment , {
78
- insecure : true , // self-signed certificate
65
+ // insecure: true, // accept self-signed certificate for SingleNodeRestateDeployment
79
66
} ) ;
80
67
81
- new cdk . CfnOutput ( this , "restateIngressUrl" , { value : environment . ingressUrl } ) ;
68
+ // If deploying a standalone Restate server, we can output the ingress URL like this.
69
+ // new cdk.CfnOutput(this, "restateIngressUrl", { value: restateEnvironment.ingressUrl });
82
70
}
83
71
}
0 commit comments