@@ -29,18 +29,14 @@ import type {
2929 APIGatewayProxyResultV2 ,
3030 Context as LambdaContext ,
3131} from 'aws-lambda'
32- import { consentDurationMS } from '../devices/consentDuration.js'
3332
34- const {
35- publicDevicesTableName,
36- publicDevicesTableModelOwnerConfirmedIndex,
37- version,
38- } = fromEnv ( {
39- version : 'VERSION' ,
40- publicDevicesTableName : 'PUBLIC_DEVICES_TABLE_NAME' ,
41- publicDevicesTableModelOwnerConfirmedIndex :
42- 'PUBLIC_DEVICES_TABLE_MODEL_OWNER_CONFIRMED_INDEX_NAME' ,
43- } ) ( process . env )
33+ const { publicDevicesTableName, publicDevicesTablemodelTTLIndex, version } =
34+ fromEnv ( {
35+ version : 'VERSION' ,
36+ publicDevicesTableName : 'PUBLIC_DEVICES_TABLE_NAME' ,
37+ publicDevicesTablemodelTTLIndex :
38+ 'PUBLIC_DEVICES_TABLE_MODEL_TTL_INDEX_NAME' ,
39+ } ) ( process . env )
4440
4541const db = new DynamoDBClient ( { } )
4642const iotData = new IoTDataPlaneClient ( { } )
@@ -56,13 +52,12 @@ const h = async (
5652 context : ValidInput < typeof InputSchema > & LambdaContext ,
5753) : Promise < APIGatewayProxyResultV2 > => {
5854 const devicesToFetch : { id : string ; deviceId : string ; model : string } [ ] = [ ]
59- const minConfirmTime = Date . now ( ) - consentDurationMS
6055
6156 for ( const model of Object . keys ( models ) ) {
6257 const queryInput : QueryCommandInput = {
6358 TableName : publicDevicesTableName ,
64- IndexName : publicDevicesTableModelOwnerConfirmedIndex ,
65- KeyConditionExpression : '#model = :model AND #ttl > :minConfirmTime ' ,
59+ IndexName : publicDevicesTablemodelTTLIndex ,
60+ KeyConditionExpression : '#model = :model AND #ttl > :now ' ,
6661 ExpressionAttributeNames : {
6762 '#id' : 'id' ,
6863 '#deviceId' : 'deviceId' ,
@@ -71,8 +66,8 @@ const h = async (
7166 } ,
7267 ExpressionAttributeValues : {
7368 ':model' : { S : model } ,
74- ':minConfirmTime ' : {
75- N : Math . round ( new Date ( minConfirmTime ) . getTime ( ) / 1000 ) . toString ( ) ,
69+ ':now ' : {
70+ N : Math . round ( new Date ( ) . getTime ( ) / 1000 ) . toString ( ) ,
7671 } ,
7772 } ,
7873 ProjectionExpression : '#id, #deviceId' ,
0 commit comments