Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 1171579

Browse files
authored
Fix dynamodb scan paginator (cloudposse#32)
Co-authored-by: goruha <goruha@users.noreply.github.com>
1 parent 55b5d34 commit 1171579

File tree

7 files changed

+72
-109
lines changed

7 files changed

+72
-109
lines changed

.github/workflows/auto-readme.yml

Lines changed: 0 additions & 75 deletions
This file was deleted.

.github/workflows/auto-release.yml

Lines changed: 0 additions & 18 deletions
This file was deleted.

.github/workflows/branch.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Branch
2+
on:
3+
pull_request:
4+
branches:
5+
- main
6+
- release/**
7+
types: [opened, synchronize, reopened]
8+
push:
9+
branches:
10+
- main
11+
- release/v*
12+
paths-ignore:
13+
- '.github/**'
14+
- 'docs/**'
15+
- 'examples/**'
16+
- 'test/**'
17+
- 'README.md'
18+
19+
permissions:
20+
contents: write
21+
actions: write
22+
23+
jobs:
24+
github-action:
25+
uses: cloudposse/.github/.github/workflows/shared-github-action.yml@main
26+
secrets: inherit
27+

.github/workflows/release.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
name: Release
2-
32
on:
43
release:
5-
types:
6-
- published
4+
types: [published]
5+
6+
permissions:
7+
id-token: write
8+
contents: write
9+
pull-requests: write
710

811
jobs:
9-
publish:
10-
runs-on: ubuntu-latest
11-
steps:
12-
- uses: cloudposse/github-action-major-release-tagger@v1
12+
github-action:
13+
uses: cloudposse/.github/.github/workflows/shared-release-branches.yml@main
14+
secrets: inherit

dist/index.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185422,6 +185422,7 @@ class DynamoDBMetadataRepo {
185422185422
return __awaiter(this, void 0, void 0, function* () {
185423185423
const params = {
185424185424
TableName: this.tableName,
185425+
ExclusiveStartKey: undefined,
185425185426
FilterExpression: "#owner = :owner and #repo = :repo and #commitSHA = :commitSHA and #component = :component and #stack = :stack",
185426185427
ExpressionAttributeNames: {
185427185428
"#owner": "repoOwner",
@@ -185439,13 +185440,23 @@ class DynamoDBMetadataRepo {
185439185440
},
185440185441
ProjectionExpression: projectionExpression
185441185442
};
185442-
const command = new lib_dynamodb_1.ScanCommand(params);
185443-
const response = yield this.dynamo.send(command);
185444-
if (!response.Items || response.Items.length === 0) {
185443+
let results = [];
185444+
let response;
185445+
do {
185446+
const command = new lib_dynamodb_1.ScanCommand(params);
185447+
response = yield this.dynamo.send(command);
185448+
if (response.Items && response.Items.length >= 0) {
185449+
results = results.concat(response.Items);
185450+
}
185451+
if (response.LastEvaluatedKey) {
185452+
params.ExclusiveStartKey = response.LastEvaluatedKey;
185453+
}
185454+
} while (response.LastEvaluatedKey);
185455+
if (results.length === 0) {
185445185456
throw new repository_1.RepositoryErrors.PlanNotFoundError(component, stack, commitSHA);
185446185457
}
185447185458
const items = [];
185448-
response.Items.forEach((item) => {
185459+
results.forEach((item) => {
185449185460
items.push(this.mapper.toDomain(item));
185450185461
});
185451185462
const sortedItems = items.sort((a, b) => {

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/modules/terraformPlan/repo/DynamoDbMetadataRepo.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
DynamoDBDocumentClient,
33
ScanCommandInput,
4+
ScanCommandOutput,
45
ScanCommand,
56
QueryCommandInput,
67
QueryCommand,
@@ -12,6 +13,7 @@ import {
1213
TerraformPlan,
1314
TerraformPlanDynamoDBMapper
1415
} from "@modules/terraformPlan";
16+
import {NativeAttributeValue} from "@aws-sdk/util-dynamodb";
1517

1618
const projectionExpression =
1719
"id, branch, commitSHA, component, contentsHash, repoOwner, pr, repoName, stack, tainted, createdAt";
@@ -32,6 +34,7 @@ export class DynamoDBMetadataRepo implements IMetadataRepository {
3234
): Promise<TerraformPlan> {
3335
const params: ScanCommandInput = {
3436
TableName: this.tableName,
37+
ExclusiveStartKey: undefined,
3538
FilterExpression:
3639
"#owner = :owner and #repo = :repo and #commitSHA = :commitSHA and #component = :component and #stack = :stack",
3740
ExpressionAttributeNames: {
@@ -51,15 +54,28 @@ export class DynamoDBMetadataRepo implements IMetadataRepository {
5154
ProjectionExpression: projectionExpression
5255
};
5356

54-
const command = new ScanCommand(params);
55-
const response = await this.dynamo.send(command);
57+
let results : Record<string, NativeAttributeValue>[] = []
58+
let response : ScanCommandOutput
5659

57-
if (!response.Items || response.Items.length === 0) {
60+
do {
61+
const command = new ScanCommand(params);
62+
response = await this.dynamo.send(command);
63+
64+
if (response.Items && response.Items.length >= 0) {
65+
results = results.concat(response.Items)
66+
}
67+
68+
if (response.LastEvaluatedKey) {
69+
params.ExclusiveStartKey = response.LastEvaluatedKey
70+
}
71+
} while (response.LastEvaluatedKey)
72+
73+
if (results.length === 0) {
5874
throw new RepositoryErrors.PlanNotFoundError(component, stack, commitSHA);
5975
}
6076

6177
const items: TerraformPlan[] = [];
62-
response.Items.forEach((item) => {
78+
results.forEach((item) => {
6379
items.push(this.mapper.toDomain(item));
6480
});
6581

0 commit comments

Comments
 (0)