Skip to content

Commit 863bc79

Browse files
authored
Simplify CDK templates and avoid VPC lookups during synth step (#170)
* CI test scripts should fail when any command fails * Update CDK examples to not require VPC lookup during synth This change simplifies the CDK examples slightly, making them more general. A side effect of this is that we no longer require a VPC lookup, which needs AWS credentials - and was thus previously failing during Unknown command: "build" To see a list of supported npm commands, run: npm help in CI. * enable command logging for run_node_tests.sh * Temporarily disable bun template checks * Add missing target to Cloudflare template * Remove explicit exit - aborts on error
1 parent f389da7 commit 863bc79

File tree

5 files changed

+61
-75
lines changed

5 files changed

+61
-75
lines changed

.tools/run_jvm_tests.sh

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
#!/usr/bin/env bash
22

3+
set -eufx -o pipefail
4+
35
SELF_PATH=${BASH_SOURCE[0]:-"$(command -v -- "$0")"}
46
PROJECT_ROOT="$(dirname "$SELF_PATH")/.."
57

6-
pushd $PROJECT_ROOT/templates/java-gradle && ./gradlew check && popd || exit
7-
pushd $PROJECT_ROOT/templates/java-maven && mvn verify && popd || exit
8-
pushd $PROJECT_ROOT/templates/kotlin-gradle && ./gradlew check && popd || exit
9-
pushd $PROJECT_ROOT/templates/kotlin-gradle-lambda-cdk/lambda && ./gradlew check && popd || exit
8+
pushd $PROJECT_ROOT/templates/java-gradle && ./gradlew check && popd
9+
pushd $PROJECT_ROOT/templates/java-maven && mvn verify && popd
10+
pushd $PROJECT_ROOT/templates/kotlin-gradle && ./gradlew check && popd
11+
pushd $PROJECT_ROOT/templates/kotlin-gradle-lambda-cdk/lambda && ./gradlew check && popd
1012

11-
pushd $PROJECT_ROOT/basics/basics-java && ./gradlew check && popd || exit
13+
pushd $PROJECT_ROOT/basics/basics-java && ./gradlew check && popd
1214

13-
pushd $PROJECT_ROOT/patterns-use-cases/sagas/sagas-java && ./gradlew check && popd || exit
14-
pushd $PROJECT_ROOT/patterns-use-cases/payment-state-machine/payment-state-machine-java && ./gradlew check && popd || exit
15-
pushd $PROJECT_ROOT/patterns-use-cases/async-signals-payment/async-signals-payment-java && ./gradlew check && popd || exit
16-
pushd $PROJECT_ROOT/patterns-use-cases/integrations/java-spring && ./gradlew check && popd || exit
15+
pushd $PROJECT_ROOT/patterns-use-cases/sagas/sagas-java && ./gradlew check && popd
16+
pushd $PROJECT_ROOT/patterns-use-cases/payment-state-machine/payment-state-machine-java && ./gradlew check && popd
17+
pushd $PROJECT_ROOT/patterns-use-cases/async-signals-payment/async-signals-payment-java && ./gradlew check && popd
18+
pushd $PROJECT_ROOT/patterns-use-cases/integrations/java-spring && ./gradlew check && popd
1719

18-
pushd $PROJECT_ROOT/tutorials/tour-of-restate-java && ./gradlew check && popd || exit
20+
pushd $PROJECT_ROOT/tutorials/tour-of-restate-java && ./gradlew check && popd
1921

20-
pushd $PROJECT_ROOT/end-to-end-applications/java/food-ordering/app && ./gradlew check && popd || exit
21-
pushd $PROJECT_ROOT/end-to-end-applications/kotlin/food-ordering/app && ./gradlew check && popd || exit
22+
pushd $PROJECT_ROOT/end-to-end-applications/java/food-ordering/app && ./gradlew check && popd
23+
pushd $PROJECT_ROOT/end-to-end-applications/kotlin/food-ordering/app && ./gradlew check && popd

.tools/run_node_tests.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env bash
22

3+
set -eufx -o pipefail
4+
35
SELF_PATH=${BASH_SOURCE[0]:-"$(command -v -- "$0")"}
46
PROJECT_ROOT="$(dirname "$SELF_PATH")/.."
57

@@ -12,7 +14,7 @@ npm_install_check $PROJECT_ROOT/basics/basics-typescript
1214
npm_install_check $PROJECT_ROOT/templates/typescript
1315
npm_install_check $PROJECT_ROOT/templates/typescript-lambda-cdk
1416
npm_install_check $PROJECT_ROOT/templates/cloudflare-worker
15-
npm_install_check $PROJECT_ROOT/templates/bun
17+
#npm_install_check $PROJECT_ROOT/templates/bun
1618

1719
npm_install_check $PROJECT_ROOT/templates/typescript-testing
1820
npm --prefix $PROJECT_ROOT/templates/typescript-testing run test

templates/cloudflare-worker/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"type": "module",
44
"version": "0.0.1",
55
"scripts": {
6+
"build": "tsc --noEmitOnError",
67
"deploy": "wrangler deploy",
78
"dev": "wrangler dev --port 9080",
89
"start": "wrangler dev --port 9080",

templates/kotlin-gradle-lambda-cdk/cdk/lambda-jvm-cdk-stack.ts

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ import * as restate from "@restatedev/restate-cdk";
1717
import { Construct } from "constructs";
1818

1919
export class LambdaJvmCdkStack extends cdk.Stack {
20-
constructor(
21-
scope: Construct,
22-
id: string,
23-
props: cdk.StackProps,
24-
) {
20+
constructor(scope: Construct, id: string, props: cdk.StackProps) {
2521
super(scope, id, props);
2622

2723
const greeter: lambda.Function = new lambda.Function(this, "RestateKotlin", {
@@ -35,46 +31,43 @@ export class LambdaJvmCdkStack extends cdk.Stack {
3531
systemLogLevel: "DEBUG",
3632
});
3733

38-
const environment = new restate.SingleNodeRestateDeployment(this, "Restate", {
39-
// restateImage: "docker.io/restatedev/restate",
40-
// restateTag: "0.9",
41-
logGroup: new logs.LogGroup(this, "RestateLogs", {
42-
retention: logs.RetentionDays.ONE_MONTH,
43-
removalPolicy: cdk.RemovalPolicy.DESTROY,
44-
}),
45-
});
46-
47-
new iam.Policy(this, "AssumeAnyRolePolicy", {
48-
statements: [
49-
new iam.PolicyStatement({
50-
sid: "AllowAssumeAnyRole",
51-
actions: ["sts:AssumeRole"],
52-
resources: ["*"], // we don't know upfront what invoker roles we may be asked to assume at runtime
53-
}),
54-
],
55-
}).attachToRole(environment.invokerRole);
56-
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.
5737
const invokerRole = new iam.Role(this, "InvokerRole", {
58-
assumedBy: new iam.ArnPrincipal(environment.invokerRole.roleArn),
38+
assumedBy: new iam.AccountRootPrincipal(), // set up trust such that your Restate environment can assume this role
5939
});
60-
invokerRole.grantAssumeRole(environment.invokerRole);
6140

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.
6243
const restateEnvironment = restate.RestateEnvironment.fromAttributes({
63-
adminUrl: environment.adminUrl,
44+
adminUrl: "https://restate.example.com:9070", // pre-existing Restate server address not managed by this stack
6445
invokerRole,
6546
});
6647

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+
6757
const deployer = new restate.ServiceDeployer(this, "ServiceDeployer", {
6858
logGroup: new logs.LogGroup(this, "Deployer", {
6959
retention: logs.RetentionDays.ONE_MONTH,
7060
removalPolicy: cdk.RemovalPolicy.DESTROY,
7161
}),
7262
});
7363

64+
// The environment's invoker role will be granted appropriate invoke permissions automatically.
65+
// To use CDK hotswap deployments during development, deploy `latestVersion` instead.
7466
deployer.deployService("Greeter", greeter.currentVersion, restateEnvironment, {
75-
insecure: true, // self-signed certificate
67+
// insecure: true, // accept self-signed certificate for SingleNodeRestateDeployment
7668
});
7769

78-
new cdk.CfnOutput(this, "restateIngressUrl", { value: environment.ingressUrl });
70+
// If deploying a standalone Restate server, we can output the ingress URL like this.
71+
// new cdk.CfnOutput(this, "restateIngressUrl", { value: restateEnvironment.ingressUrl });
7972
}
8073
}

templates/typescript-lambda-cdk/lib/lambda-ts-cdk-stack.ts

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,55 +18,42 @@ import { Construct } from "constructs";
1818
import { NodejsFunction } from "aws-cdk-lib/aws-lambda-nodejs";
1919

2020
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) {
2622
super(scope, id, props);
2723

2824
const greeter: lambda.Function = new NodejsFunction(this, "GreeterService", {
29-
runtime: lambda.Runtime.NODEJS_LATEST,
25+
runtime: lambda.Runtime.NODEJS_20_X,
3026
entry: "lib/lambda/handler.ts",
3127
architecture: lambda.Architecture.ARM_64,
3228
bundling: {
3329
minify: true,
3430
sourceMap: true,
3531
},
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-
}),
4832
});
4933

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.
6037
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
6239
});
63-
invokerRole.grantAssumeRole(environment.invokerRole);
6440

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.
6543
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
6745
invokerRole,
6846
});
6947

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+
7057
const deployer = new restate.ServiceDeployer(this, "ServiceDeployer", {
7158
logGroup: new logs.LogGroup(this, "Deployer", {
7259
retention: logs.RetentionDays.ONE_MONTH,
@@ -75,9 +62,10 @@ export class LambdaTsCdkStack extends cdk.Stack {
7562
});
7663

7764
deployer.deployService("Greeter", greeter.currentVersion, restateEnvironment, {
78-
insecure: true, // self-signed certificate
65+
// insecure: true, // accept self-signed certificate for SingleNodeRestateDeployment
7966
});
8067

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 });
8270
}
8371
}

0 commit comments

Comments
 (0)