Skip to content

Commit 0bbdf3e

Browse files
authored
Expose Service Deployer event handler bundling property (#47)
1 parent 60bb2c4 commit 0bbdf3e

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

lib/restate-constructs/service-deployer.ts

+18-7
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export interface ServiceRegistrationProps {
8282
export class ServiceDeployer extends Construct {
8383
/** The custom resource provider for handling "deployment" resources. */
8484
readonly deploymentResourceProvider: cr.Provider;
85+
readonly eventHandler: lambda_node.NodejsFunction;
8586

8687
private invocationPolicy?: iam.Policy;
8788

@@ -93,15 +94,23 @@ export class ServiceDeployer extends Construct {
9394
* VPC and security group settings for Restate environments that require it.
9495
*/
9596
props?: Pick<
96-
lambda.FunctionOptions,
97-
"functionName" | "logGroup" | "timeout" | "vpc" | "vpcSubnets" | "securityGroups" | "allowPublicSubnet"
97+
lambda_node.NodejsFunctionProps,
98+
| "allowPublicSubnet"
99+
| "bundling"
100+
| "code"
101+
| "entry"
102+
| "functionName"
103+
| "logGroup"
104+
| "securityGroups"
105+
| "timeout"
106+
| "vpc"
107+
| "vpcSubnets"
98108
> &
99-
Pick<lambda_node.NodejsFunctionProps, "entry"> &
100109
Pick<logs.LogGroupProps, "removalPolicy">,
101110
) {
102111
super(scope, id);
103112

104-
const eventHandler = new lambda_node.NodejsFunction(this, "EventHandler", {
113+
this.eventHandler = new lambda_node.NodejsFunction(this, "EventHandler", {
105114
functionName: props?.functionName,
106115
logGroup: props?.logGroup,
107116
description: "Restate custom registration handler",
@@ -130,13 +139,15 @@ export class ServiceDeployer extends Construct {
130139
if (!props?.logGroup) {
131140
// By default, Lambda Functions have a log group with never-expiring retention policy.
132141
new logs.LogGroup(this, "DeploymentLogs", {
133-
logGroupName: `/aws/lambda/${eventHandler.functionName}`,
142+
logGroupName: `/aws/lambda/${this.eventHandler.functionName}`,
134143
retention: logs.RetentionDays.ONE_MONTH,
135-
removalPolicy: cdk.RemovalPolicy.RETAIN_ON_UPDATE_OR_DELETE,
144+
removalPolicy: props?.removalPolicy ?? cdk.RemovalPolicy.RETAIN_ON_UPDATE_OR_DELETE,
136145
});
137146
}
138147

139-
this.deploymentResourceProvider = new cr.Provider(this, "CustomResourceProvider", { onEventHandler: eventHandler });
148+
this.deploymentResourceProvider = new cr.Provider(this, "CustomResourceProvider", {
149+
onEventHandler: this.eventHandler,
150+
});
140151
}
141152

142153
/**

0 commit comments

Comments
 (0)