-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathgo-lambda-cdk-stack.ts
More file actions
85 lines (78 loc) · 3.38 KB
/
go-lambda-cdk-stack.ts
File metadata and controls
85 lines (78 loc) · 3.38 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
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
80
81
82
83
84
85
/*
* Copyright (c) 2024 - Restate Software, Inc., Restate GmbH
*
* This file is part of the Restate examples,
* which is released under the MIT license.
*
* You can find a copy of the license in the file LICENSE
* in the root directory of this repository or package or at
* https://github.com/restatedev/examples/
*/
import * as restate from "@restatedev/restate-cdk";
import * as cdk from "aws-cdk-lib";
import * as lambda from "aws-cdk-lib/aws-lambda";
import * as secrets from "aws-cdk-lib/aws-secretsmanager";
import * as go from "@aws-cdk/aws-lambda-go-alpha";
import { Construct } from "constructs";
export class GoLambdaCdkStack extends cdk.Stack {
constructor(scope: Construct, id: string, props: cdk.StackProps) {
super(scope, id, props);
const handler = new go.GoFunction(
this,
"GreeterService",
{
runtime: lambda.Runtime.PROVIDED_AL2023,
architecture: lambda.Architecture.ARM_64,
entry: "lambda",
timeout: cdk.Duration.seconds(10),
loggingFormat: lambda.LoggingFormat.JSON,
applicationLogLevelV2: lambda.ApplicationLogLevel.DEBUG,
systemLogLevelV2: lambda.SystemLogLevel.INFO,
},
);
// If you would prefer to manually register the Lambda service with your Restate environment,
// you can remove or comment the rest of the code below this line.
if (!process.env.RESTATE_ENV_ID || !process.env.RESTATE_API_KEY) {
throw new Error(
"Required environment variables RESTATE_ENV_ID and RESTATE_API_KEY are not set, please see README."
);
}
// This construct automatically creates an invoker role that Restate Cloud will be able to assume to invoke handlers
// on behalf of your environment. See https://docs.restate.dev/deploy/cloud for more information.
const restateEnvironment = new restate.RestateCloudEnvironment(
this,
"RestateCloud",
{
environmentId: process.env.RESTATE_ENV_ID! as restate.EnvironmentId,
// Warning: this will result in the API key being baked into the CloudFormation template!
// For improved security, pre-populate the secret and pass it to the construct as a reference.
// See: https://docs.aws.amazon.com/secretsmanager/latest/userguide/cdk.html
apiKey: new secrets.Secret(this, "RestateCloudApiKey", {
secretStringValue: cdk.SecretValue.unsafePlainText(
process.env.RESTATE_API_KEY!,
),
}),
},
);
const deployer = new restate.ServiceDeployer(this, "ServiceDeployer");
// Alternatively, you can deploy a standalone Restate server using the SingleNodeRestateDeployment construct.
// Please see https://docs.restate.dev/deploy/lambda/self-hosted and the construct documentation for more details.
// const vpc = ec2.Vpc.fromLookup(this, "Vpc", { vpcId: "..." });
// const restateEnvironment = new restate.SingleNodeRestateDeployment(this, "Restate", {
// vpc,
// networkConfiguration: { subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS },
// });
// const deployer = new restate.ServiceDeployer(this, "ServiceDeployer", {
// vpc,
// securityGroups: [restateEnvironment.adminSecurityGroup],
// });
deployer.deployService(
"Greeter",
handler.currentVersion,
restateEnvironment,
);
new cdk.CfnOutput(this, "restateIngressUrl", {
value: restateEnvironment.ingressUrl,
});
}
}