Skip to content

Commit

Permalink
Not use custom-resource converter for dynamodb seeding adapter (#365)
Browse files Browse the repository at this point in the history
* Not use custom-resource converter for dynamodb seeding adapter

* fix e2e

---------

Co-authored-by: Dorseuil Nicolas <[email protected]>
  • Loading branch information
fwang and conico974 authored Feb 20, 2024
1 parent e1a9589 commit 68858bb
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 44 deletions.
31 changes: 20 additions & 11 deletions examples/sst/stacks/OpenNextReferenceImplementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import {
Runtime,
} from "aws-cdk-lib/aws-lambda";
import { SqsEventSource } from "aws-cdk-lib/aws-lambda-event-sources";
import { RetentionDays } from "aws-cdk-lib/aws-logs";
import { BlockPublicAccess, Bucket } from "aws-cdk-lib/aws-s3";
import { BucketDeployment, Source } from "aws-cdk-lib/aws-s3-deployment";
import { Queue } from "aws-cdk-lib/aws-sqs";
Expand All @@ -42,7 +41,11 @@ import {
RemovalPolicy,
Stack,
} from "aws-cdk-lib/core";
import { Provider } from "aws-cdk-lib/custom-resources";
import {
AwsCustomResource,
AwsCustomResourcePolicy,
PhysicalResourceId,
} from "aws-cdk-lib/custom-resources";
import { Construct } from "constructs";
import { readFileSync } from "fs";
import path from "path";
Expand Down Expand Up @@ -199,16 +202,22 @@ export class OpenNextCdkReferenceImplementation extends Construct {
],
});

const provider = new Provider(this, "RevalidationProvider", {
onEventHandler: insertFn,
logRetention: RetentionDays.ONE_DAY,
});

new CustomResource(this, "RevalidationResource", {
serviceToken: provider.serviceToken,
properties: {
version: Date.now().toString(),
new AwsCustomResource(this, "RevalidationInitResource", {
onUpdate: {
service: "Lambda",
action: "invoke",
parameters: {
FunctionName: insertFn.functionArn,
},
physicalResourceId: PhysicalResourceId.of("dynamodb-cache"),
},

policy: AwsCustomResourcePolicy.fromStatements([
new PolicyStatement({
actions: ["lambda:InvokeFunction"],
resources: [insertFn.functionArn],
}),
]),
});
}

Expand Down
5 changes: 3 additions & 2 deletions packages/open-next/src/adapters/dynamo-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ async function defaultHandler(
event: InitializationFunctionEvent,
): Promise<InitializationFunctionEvent> {
switch (event.requestType) {
case "delete":
return remove();
case "create":
case "update":
default:
return insert(event.requestType);
case "delete":
return remove();
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/open-next/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ async function createCacheAssets(monorepoRoot: string) {
plugins: [
openNextResolvePlugin({
overrides: {
converter: "custom-resource",
converter: "dummy",
},
}),
],
Expand Down
29 changes: 0 additions & 29 deletions packages/open-next/src/converters/custom-resource.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/open-next/src/types/open-next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ export type IncludedConverter =
| "edge"
| "node"
| "sqs-revalidate"
| "custom-resource"
| "dummy";

export type IncludedQueue = "sqs";
Expand Down

0 comments on commit 68858bb

Please sign in to comment.