diff --git a/src/index.js b/src/index.js index 5257af4a..e54acfb7 100644 --- a/src/index.js +++ b/src/index.js @@ -15,7 +15,7 @@ import { logger } from '@adobe/helix-universal-logger'; import { helixStatus } from '@adobe/helix-status'; import DB from './db.js'; import PSIClient from './psi-client.js'; -import { queueWrapper } from './queue-wrapper.js'; +import queueWrapper from './queue-wrapper.js'; /** * This is the main function @@ -25,13 +25,13 @@ import { queueWrapper } from './queue-wrapper.js'; */ async function run(request, context) { const db = DB({ - region: process.env.REGION, + region: context.env.REGION, }); const { message } = JSON.parse(context.invocation.event.Records[0].body); const psiClient = PSIClient({ - apiKey: process.env.PAGESPEED_API_KEY, - baseUrl: process.env.PAGESPEED_API_BASE_URL, + apiKey: context.env.PAGESPEED_API_KEY, + baseUrl: context.env.PAGESPEED_API_BASE_URL, }); const site = { diff --git a/src/queue-wrapper.js b/src/queue-wrapper.js index 2437e06f..82b44973 100644 --- a/src/queue-wrapper.js +++ b/src/queue-wrapper.js @@ -14,15 +14,12 @@ import SqsQueue from './sqs-queue.js'; -function queueWrapper(func) { +export default function queueWrapper(func) { return async (request, context) => { - const region = process.env.AWS_REGION; - const queueUrl = process.env.AUDIT_RESULTS_QUEUE_URL; + const region = context.env.AWS_REGION; + const queueUrl = context.env.AUDIT_RESULTS_QUEUE_URL; const { log } = context; - if (!region) { - throw new Error('AWS_REGION env variable is empty/not provided'); - } if (!queueUrl) { throw new Error('AUDIT_RESULTS_QUEUE_URL env variable is empty/not provided'); } @@ -32,5 +29,3 @@ function queueWrapper(func) { return func(request, context); }; } - -export default queueWrapper; diff --git a/src/sqs-queue.js b/src/sqs-queue.js index 4d5c27bf..31a87520 100644 --- a/src/sqs-queue.js +++ b/src/sqs-queue.js @@ -13,7 +13,7 @@ import { SendMessageCommand, SQSClient } from '@aws-sdk/client-sqs'; let sqsClient; -function SQSQueue(region, queueUrl, log) { +export default function SQSQueue(region, queueUrl, log) { if (!sqsClient) { sqsClient = new SQSClient({ region }); log.info(`Creating SQS client in region ${region}`); @@ -41,5 +41,3 @@ function SQSQueue(region, queueUrl, log) { } return { sendAuditResult }; } - -export default SQSQueue;