serverless-offline-streams
Version:
This plugin provides support for event driven systems using Serverless Offline
23 lines (19 loc) • 864 B
text/typescript
import {ListQueuesCommand, SQSClient} from "@aws-sdk/client-sqs";
export type CreateSQSClientFunc = (region: string, endpoint: string) => Promise<SQSClient>
const createSQSClient: CreateSQSClientFunc = async (region: string, endpoint: string): Promise<SQSClient> => {
if (!endpoint) {
throw Error("No endpoint specified when creating SQS client")
}
const client = new SQSClient({region, endpoint});
// Ping the queue to see if it is available
try {
await client.send(new ListQueuesCommand({}))
} catch (e) {
if (e.code?.trim()?.toUpperCase() === 'ECONNREFUSED') {
throw Error(`An SQS API compatible queue is not available at '${endpoint}'. If this is a local queue, did you forget to start your elasticmq instance?`)
}
throw e
}
return client
};
export default createSQSClient