Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/restate-constructs/service-deployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import path from "node:path";
import { Construct } from "constructs";
import * as cdk from "aws-cdk-lib";
import * as cx_api from "aws-cdk-lib/cx-api";
import * as iam from "aws-cdk-lib/aws-iam";
import * as lambda from "aws-cdk-lib/aws-lambda";
import * as lambda_node from "aws-cdk-lib/aws-lambda-nodejs";
Expand Down Expand Up @@ -219,7 +220,10 @@ export class ServiceDeployer extends Construct {
allowPublicSubnet: props?.allowPublicSubnet,
});

if (!props?.logGroup) {
// Skip creating an explicit LogGroup when CDK manages it automatically via the
// useCdkManagedLogGroup feature flag - both would resolve to the same name and conflict.
const cdkManagedLogGroup = cdk.FeatureFlags.of(this).isEnabled(cx_api.USE_CDK_MANAGED_LAMBDA_LOGGROUP);
if (!props?.logGroup && !cdkManagedLogGroup) {
// By default, Lambda Functions have a log group with never-expiring retention policy.
new logs.LogGroup(this, "DeploymentLogs", {
logGroupName: `/aws/lambda/${this.eventHandler.functionName}`,
Expand Down
20 changes: 20 additions & 0 deletions test/restate-constructs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,26 @@ describe("Restate constructs", () => {
});
});

test("ServiceDeployer with useCdkManagedLogGroup feature flag enabled", () => {
const app = new cdk.App({
context: { "@aws-cdk/aws-lambda:useCdkManagedLogGroup": true },
});
const stack = new cdk.Stack(app, "RestateCloudStack", {
env: { account: "account-id", region: "region" },
});

new ServiceDeployer(stack, "ServiceDeployer", {
code: lambda.Code.fromAsset("dist/register-service-handler"),
});

const template = app.synth().getStackByName("RestateCloudStack").template;
const logGroups = Object.values(template.Resources as Record<string, { Type: string }>).filter(
(r) => r.Type === "AWS::Logs::LogGroup",
);
// Only the CDK-managed LogGroup created by the Lambda construct; none added by ServiceDeployer
expect(logGroups).toHaveLength(1);
});

test("Service Deployer overrides", () => {
const app = new cdk.App();
const stack = new cdk.Stack(app, "RestateCloudStack", {
Expand Down
Loading