File tree Expand file tree Collapse file tree 4 files changed +32
-4
lines changed
Expand file tree Collapse file tree 4 files changed +32
-4
lines changed Original file line number Diff line number Diff line change 1- import { Metrics , MetricUnits } from '@aws-lambda-powertools/metrics'
1+ import {
2+ logMetrics ,
3+ Metrics ,
4+ MetricUnits ,
5+ } from '@aws-lambda-powertools/metrics'
26import { DynamoDBClient } from '@aws-sdk/client-dynamodb'
7+ import middy from '@middy/core'
38import { fromEnv } from '@nordicsemiconductor/from-env'
49import { chunk } from 'lodash-es'
510import pLimit from 'p-limit'
@@ -58,7 +63,7 @@ const deviceShadowPromise = (async () => {
5863} ) ( )
5964const deviceShadowPublisher = createDeviceShadowPublisher ( eventBusName )
6065
61- export const handler = async ( ) : Promise < void > => {
66+ const h = async ( ) : Promise < void > => {
6267 const deviceShadow = await deviceShadowPromise
6368 const lockAcquired = await lock . acquiredLock ( lockName , lockTTL )
6469 if ( lockAcquired === false ) {
@@ -117,3 +122,5 @@ export const handler = async (): Promise<void> => {
117122 await lock . releaseLock ( lockName )
118123 }
119124}
125+
126+ export const handler = middy ( h ) . use ( logMetrics ( metrics ) )
Original file line number Diff line number Diff line change 1- import { MetricUnits , Metrics } from '@aws-lambda-powertools/metrics'
1+ import {
2+ MetricUnits ,
3+ Metrics ,
4+ logMetrics ,
5+ } from '@aws-lambda-powertools/metrics'
26import {
37 DynamoDBClient ,
48 PutItemCommand ,
@@ -7,6 +11,7 @@ import {
711import { EventBridge } from '@aws-sdk/client-eventbridge'
812import { unmarshall } from '@aws-sdk/util-dynamodb'
913import { Context , DeviceIdentity } from '@hello.nrfcloud.com/proto/hello'
14+ import middy from '@middy/core'
1015import { fromEnv } from '@nordicsemiconductor/from-env'
1116import type { Static } from '@sinclair/typebox'
1217import type {
@@ -34,7 +39,7 @@ const metrics = new Metrics({
3439 serviceName : 'websocket' ,
3540} )
3641
37- export const handler = async (
42+ const h = async (
3843 event : APIGatewayProxyWebsocketEventV2 & {
3944 queryStringParameters ?: Record < string , any >
4045 } ,
@@ -126,3 +131,5 @@ export const handler = async (
126131 body : `Connected. Hello ${ event . requestContext . connectionId } @${ device . deviceId } !` ,
127132 }
128133}
134+
135+ export const handler = middy ( h ) . use ( logMetrics ( metrics ) )
Original file line number Diff line number Diff line change 117117 "dependencies" : {
118118 "@aws-lambda-powertools/metrics" : " 1.9.0" ,
119119 "@hello.nrfcloud.com/proto" : " 1.0.0" ,
120+ "@middy/core" : " 4.5.2" ,
120121 "@nordicsemiconductor/from-env" : " 2.0.0" ,
121122 "@nordicsemiconductor/timestream-helpers" : " 5.0.0" ,
122123 "@sinclair/typebox" : " 0.28.15" ,
You can’t perform that action at this time.
0 commit comments