|
| 1 | +/* |
| 2 | + * Copyright (c) 2024 - Restate Software, Inc., Restate GmbH |
| 3 | + * |
| 4 | + * This file is part of the Restate examples, |
| 5 | + * which is released under the MIT license. |
| 6 | + * |
| 7 | + * You can find a copy of the license in the file LICENSE |
| 8 | + * in the root directory of this repository or package or at |
| 9 | + * https://github.com/restatedev/examples/ |
| 10 | + */ |
| 11 | + |
| 12 | +import * as restate from "@restatedev/restate-cdk"; |
| 13 | +import * as cdk from "aws-cdk-lib"; |
| 14 | +import * as lambda from "aws-cdk-lib/aws-lambda"; |
| 15 | +import * as secrets from "aws-cdk-lib/aws-secretsmanager"; |
| 16 | +import { Construct } from "constructs"; |
| 17 | + |
| 18 | +export class LambdaJvmCdkStack extends cdk.Stack { |
| 19 | + constructor(scope: Construct, id: string, props: cdk.StackProps) { |
| 20 | + super(scope, id, props); |
| 21 | + |
| 22 | + const handler: lambda.Function = new lambda.Function(this, "GreeterService", { |
| 23 | + runtime: lambda.Runtime.JAVA_21, |
| 24 | + architecture: lambda.Architecture.ARM_64, |
| 25 | + code: lambda.Code.fromAsset("lambda/build/distributions/lambda.zip"), |
| 26 | + handler: "my.example.LambdaHandler", |
| 27 | + timeout: cdk.Duration.seconds(10), |
| 28 | + loggingFormat: lambda.LoggingFormat.JSON, |
| 29 | + applicationLogLevelV2: lambda.ApplicationLogLevel.DEBUG, |
| 30 | + systemLogLevelV2: lambda.SystemLogLevel.INFO, |
| 31 | + }); |
| 32 | + |
| 33 | + // Set the RESTATE_ENV_ID and RESTATE_API_KEY environment variables to point to your Restate Cloud environment. |
| 34 | + // This construct automatically creates an invoker role that Restate Cloud will be able to assume to invoke handlers |
| 35 | + // on behalf of your environment. See https://docs.restate.dev/deploy/cloud for more information. |
| 36 | + const restateEnvironment = new restate.RestateCloudEnvironment(this, "RestateCloud", { |
| 37 | + environmentId: process.env.RESTATE_ENV_ID! as restate.EnvironmentId, |
| 38 | + // Warning: this will result in the API key being baked into the CloudFormation template! |
| 39 | + // For improved security, pre-populate the secret and pass it to the construct as a reference. |
| 40 | + // See: https://docs.aws.amazon.com/secretsmanager/latest/userguide/cdk.html |
| 41 | + apiKey: new secrets.Secret(this, "RestateCloudApiKey", { |
| 42 | + secretStringValue: cdk.SecretValue.unsafePlainText(process.env.RESTATE_API_KEY!), |
| 43 | + }), |
| 44 | + }); |
| 45 | + const deployer = new restate.ServiceDeployer(this, "ServiceDeployer"); |
| 46 | + |
| 47 | + // Alternatively, you can deploy a standalone Restate server using the SingleNodeRestateDeployment construct. |
| 48 | + // Please see https://docs.restate.dev/deploy/lambda/self-hosted and the construct documentation for more details. |
| 49 | + // const vpc = ec2.Vpc.fromLookup(this, "Vpc", { vpcId: "..." }); |
| 50 | + // const restateEnvironment = new restate.SingleNodeRestateDeployment(this, "Restate", { |
| 51 | + // vpc, |
| 52 | + // networkConfiguration: { subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS }, |
| 53 | + // }); |
| 54 | + // const deployer = new restate.ServiceDeployer(this, "ServiceDeployer", { |
| 55 | + // vpc, |
| 56 | + // securityGroups: [restateEnvironment.adminSecurityGroup], |
| 57 | + // }); |
| 58 | + |
| 59 | + deployer.deployService("Greeter", handler.currentVersion, restateEnvironment); |
| 60 | + new cdk.CfnOutput(this, "restateIngressUrl", { value: restateEnvironment.ingressUrl }); |
| 61 | + } |
| 62 | +} |
0 commit comments