Skip to content

Commit 668ba4a

Browse files
possebonclaude
andcommitted
feat(sqs): add support for custom SQS endpoint (EvolutionAPI#2458)
Adds optional SQS_ENDPOINT environment variable for custom SQS endpoints, useful for LocalStack or other S3-compatible services. Backward-compatible with existing AWS SQS configurations. Upstream PR: EvolutionAPI#2458 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f375f31 commit 668ba4a

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

src/api/integrations/event/sqs/sqs.controller.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ export class SqsController extends EventController implements EventControllerInt
2828
accessKeyId: awsConfig.ACCESS_KEY_ID,
2929
secretAccessKey: awsConfig.SECRET_ACCESS_KEY,
3030
},
31-
3231
region: awsConfig.REGION,
32+
endpoint: awsConfig.ENDPOINT,
3333
});
3434

3535
this.logger.info('SQS initialized');
@@ -126,7 +126,7 @@ export class SqsController extends EventController implements EventControllerInt
126126
? 'singlequeue'
127127
: `${event.replace('.', '_').toLowerCase()}`;
128128
const queueName = `${prefixName}_${eventFormatted}.fifo`;
129-
const sqsUrl = `https://sqs.${sqsConfig.REGION}.amazonaws.com/${sqsConfig.ACCOUNT_ID}/${queueName}`;
129+
const sqsUrl = this.getQueueUrl(sqsConfig, queueName);
130130

131131
const message = {
132132
...(extra ?? {}),
@@ -302,4 +302,15 @@ export class SqsController extends EventController implements EventControllerInt
302302
this.logger.error(`Error listing queues for ${prefixName}: ${err.message}`);
303303
}
304304
}
305+
306+
private getQueueUrl(sqsConfig: Sqs, queueName: string): string {
307+
if (sqsConfig.ENDPOINT) {
308+
const endpoint = sqsConfig.ENDPOINT.replace(/\/+$/, '');
309+
if (endpoint.endsWith(sqsConfig.ACCOUNT_ID)) {
310+
return `${endpoint}/${queueName}`;
311+
}
312+
return `${endpoint}/${sqsConfig.ACCOUNT_ID}/${queueName}`;
313+
}
314+
return `https://sqs.${sqsConfig.REGION}.amazonaws.com/${sqsConfig.ACCOUNT_ID}/${queueName}`;
315+
}
305316
}

src/config/env.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export type Sqs = {
121121
SECRET_ACCESS_KEY: string;
122122
ACCOUNT_ID: string;
123123
REGION: string;
124+
ENDPOINT?: string;
124125
MAX_PAYLOAD_SIZE: number;
125126
EVENTS: {
126127
APPLICATION_STARTUP: boolean;
@@ -585,6 +586,7 @@ export class ConfigService {
585586
SECRET_ACCESS_KEY: process.env.SQS_SECRET_ACCESS_KEY || '',
586587
ACCOUNT_ID: process.env.SQS_ACCOUNT_ID || '',
587588
REGION: process.env.SQS_REGION || '',
589+
ENDPOINT: process.env.SQS_ENDPOINT || undefined,
588590
MAX_PAYLOAD_SIZE: Number.parseInt(process.env.SQS_MAX_PAYLOAD_SIZE ?? '1048576'),
589591
EVENTS: {
590592
APPLICATION_STARTUP: process.env?.SQS_GLOBAL_APPLICATION_STARTUP === 'true',

0 commit comments

Comments
 (0)