88 ApiGatewayManagementApiClient ,
99 PostToConnectionCommand ,
1010} from "@aws-sdk/client-apigatewaymanagementapi" ;
11+ import { SQSEvent , SQSRecord } from "aws-lambda" ;
1112
1213const REGION = "us-east-1" ;
1314const clnt = new DynamoDBClient ( { region : REGION } ) ;
@@ -26,7 +27,7 @@ const unmarshallOptions = {
2627const translateConfig = { marshallOptions, unmarshallOptions } ;
2728const ddbDocClient = DynamoDBDocumentClient . from ( clnt , translateConfig ) ;
2829
29- export const handler = async ( event : any ) => {
30+ export const handler = async ( event : SQSEvent ) => {
3031 // SQS may batch multiple messages
3132 for ( const record of event . Records ) {
3233 await processRecord ( record ) ;
@@ -35,7 +36,7 @@ export const handler = async (event: any) => {
3536 return { statusCode : 200 } ;
3637} ;
3738
38- async function processRecord ( record : any ) {
39+ async function processRecord ( record : SQSRecord ) {
3940 let body ;
4041 try {
4142 body = JSON . parse ( record . body ) ;
@@ -75,11 +76,13 @@ async function processRecord(record: any) {
7576 const now = Math . floor ( Date . now ( ) / 1000 ) ;
7677
7778 for ( const item of result . Items ?? [ ] ) {
79+ console . log ( `Processing item: ${ JSON . stringify ( item ) } ` ) ;
7880 const connectionId = item . sk . S ! ;
7981 const ttl = item . ttl ?. N ? parseInt ( item . ttl . N ) : null ;
8082
8183 // Delete expired TTL entries
8284 if ( ttl && ttl < now ) {
85+ console . log ( `Deleting expired connection: ${ connectionId } ` ) ;
8386 await deleteConnection ( connectionId ) ;
8487 continue ;
8588 }
0 commit comments