@@ -7,18 +7,19 @@ import {
77 SendMessageBatchCommandOutput ,
88 SendMessageBatchRequestEntry ,
99} from '@aws-sdk/client-sqs' ;
10- import logger from '../commons/logger' ;
10+ import getEnvOrThrow from '../commons/get-env-or-throw' ;
11+
12+ export function createSqsClient ( ) {
13+ const region = getEnvOrThrow ( 'AWS_REGION' ) ;
14+
15+ return new SQSClient ( { region } ) ;
16+ }
1117
1218export async function sendSqsMessage (
1319 messageBody : string ,
1420 queueUrl : string | undefined ,
21+ client : SQSClient = createSqsClient ( ) ,
1522) : Promise < SendMessageCommandOutput > {
16- if ( ! process . env [ 'AWS_REGION' ] ) {
17- logger . error ( 'AWS_REGION environment variable is not set' ) ;
18- throw new Error ( 'AWS_REGION environment variable not set' ) ;
19- }
20- const region = process . env [ 'AWS_REGION' ] ;
21- const client = new SQSClient ( { region } ) ;
2223 const message : SendMessageRequest = {
2324 QueueUrl : queueUrl ,
2425 MessageBody : messageBody ,
@@ -29,13 +30,8 @@ export async function sendSqsMessage(
2930export async function sendBatchSqsMessage (
3031 messages : SendMessageBatchRequestEntry [ ] ,
3132 queueUrl : string | undefined ,
33+ client : SQSClient = createSqsClient ( ) ,
3234) : Promise < SendMessageBatchCommandOutput > {
33- if ( ! process . env [ 'AWS_REGION' ] ) {
34- logger . error ( 'AWS_REGION environment variable is not set' ) ;
35- throw new Error ( 'AWS_REGION environment variable not set' ) ;
36- }
37- const region = process . env [ 'AWS_REGION' ] ;
38- const client = new SQSClient ( { region } ) ;
3935 const parameters = {
4036 QueueUrl : queueUrl ,
4137 Entries : messages ,
0 commit comments