Skip to content

Commit

Permalink
Merge pull request #20 from dvsa/feature/CB2-11440
Browse files Browse the repository at this point in the history
feat(cb2-11440): filter out old ttl due to AWS limitation
  • Loading branch information
naathanbrown authored Mar 21, 2024
2 parents bda81d5 + 73657f5 commit 823ca26
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/dynamo/getDynamoRecords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ export const getDynamoMembers: () => Promise<IDynamoRecord[]> = async () => {
.query({
TableName: config.aws.dynamoTable,
KeyConditionExpression: 'resourceType = :type',
FilterExpression: 'attribute_not_exists(#ttl_key) or #ttl_key = :null',
ExpressionAttributeValues: {
':type': ResourceType.User,
':null': null,
},
ExpressionAttributeNames: {
'#ttl_key': 'ttl',
},
} as AWS.DynamoDB.DocumentClient.QueryInput)
.promise();
Expand Down
2 changes: 1 addition & 1 deletion src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function generateStatements(
const SECONDS_IN_AN_HOUR = 60 * 60;
const HOURS_IN_A_DAY = 24;
const secondsSinceEpoch = Math.round(Date.now() / 1000);
const expirationTime = (secondsSinceEpoch + HOURS_IN_A_DAY * SECONDS_IN_AN_HOUR) - SECONDS_IN_AN_HOUR;
const expirationTime = secondsSinceEpoch + HOURS_IN_A_DAY * SECONDS_IN_AN_HOUR - SECONDS_IN_AN_HOUR;

const drMap = dynamoRecords
.filter((dr) => !azureMembers.some((am) => am.id === dr.resourceKey))
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/getDynamoRecords.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,13 @@ describe('getDynamoMembers', () => {
expect(mockDynamoQuery).toBeCalledWith({
TableName: 'testTable',
KeyConditionExpression: 'resourceType = :type',
FilterExpression: 'attribute_not_exists(#ttl_key) or #ttl_key = :null',
ExpressionAttributeValues: {
':type': ResourceType.User,
':null': null,
},
ExpressionAttributeNames: {
'#ttl_key': 'ttl',
},
} as AWS.DynamoDB.DocumentClient.QueryInput);
});
Expand Down

0 comments on commit 823ca26

Please sign in to comment.