import { APIGatewayProxyEvent , Context } from "aws-lambda" ; import { Configuration } from "./common" ; import { env } from "./env" ; import { importDashboard } from "./services/importer-service" ; function logRequest ( event , context ) { let eventToLog = { ... event } ; if ( eventToLog ) { if ( eventToLog . resource ?. includes ( "ingestapi" ) ) { eventToLog = { ... eventToLog , body : null } ; } if ( eventToLog . headers ?. Authorization ) { eventToLog . headers . Authorization = "<Redacted>" ; } if ( eventToLog . multiValueHeaders ?. Authorization ) { eventToLog . multiValueHeaders . Authorization = [ "<Redacted>" ] ; } } console . log ( "Event=" , JSON . stringify ( eventToLog ) ) ; console . log ( "Context=" , JSON . stringify ( context ) ) ; } param event export const handler = async ( event , context ) => { logRequest ( event , context ) ; try { const config = ( event . body as unknown as Configuration ) || { } ; if ( ! config . example ) { config . example = env . EXAMPLE ; } if ( ! config . author ) { config . author = env . USER_EMAIL ; } if ( config . reuseTopicArea === undefined ) { config . reuseTopicArea = true ; } const dashboard = await importDashboard ( config ) ; console . log ( { dashboard } ) ; } catch ( e ) { console . log ( e ) ; } return context ?. logStreamName ; } ;