Skip to content

Commit f07914c

Browse files
authored
Merge pull request #85 from ServerlessLife/fix/suppress-error-for-dynamo-stream-in-newer-cdk-versions
fix: suppress error when using newer cdk versions and spy on dynamo
2 parents ee3eba6 + 13796e2 commit f07914c

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/ServerlessSpy.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -585,18 +585,15 @@ export class ServerlessSpy extends Construct {
585585
(table.node.defaultChild as dynamoDb.CfnTable).streamSpecification = {
586586
streamViewType: dynamoDb.StreamViewType.NEW_AND_OLD_IMAGES,
587587
};
588-
var tableStreamArnDescriptor = Object.getOwnPropertyDescriptor(
589-
table,
590-
'tableStreamArn'
591-
);
592-
593-
if (
594-
tableStreamArnDescriptor === undefined ||
595-
tableStreamArnDescriptor.get === undefined
596-
) {
597-
(table as any)['tableStreamArn'] = (
588+
try {
589+
(table as any).tableStreamArn = (
598590
table.node.defaultChild as dynamoDb.CfnTable
599591
).attrStreamArn;
592+
} catch (e) {
593+
// Property is read-only in newer CDK versions, skip the assignment
594+
if (!(e instanceof TypeError && e.message.includes('only a getter'))) {
595+
throw e; // Re-throw if it's a different error
596+
}
600597
}
601598

602599
this.lambdaSubscriptionMain.function.addEventSource(

0 commit comments

Comments
 (0)