Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/api/integrations/event/sqs/sqs.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export class SqsController extends EventController implements EventControllerInt
accessKeyId: awsConfig.ACCESS_KEY_ID,
secretAccessKey: awsConfig.SECRET_ACCESS_KEY,
},

region: awsConfig.REGION,
endpoint: awsConfig.ENDPOINT,
});

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

const message = {
...(extra ?? {}),
Expand Down Expand Up @@ -302,4 +302,15 @@ export class SqsController extends EventController implements EventControllerInt
this.logger.error(`Error listing queues for ${prefixName}: ${err.message}`);
}
}

private getQueueUrl(sqsConfig: Sqs, queueName: string): string {
if (sqsConfig.ENDPOINT) {
const endpoint = sqsConfig.ENDPOINT.replace(/\/+$/, '');
if (endpoint.endsWith(sqsConfig.ACCOUNT_ID)) {
return `${endpoint}/${queueName}`;
}
return `${endpoint}/${sqsConfig.ACCOUNT_ID}/${queueName}`;
}
return `https://sqs.${sqsConfig.REGION}.amazonaws.com/${sqsConfig.ACCOUNT_ID}/${queueName}`;
}
}
2 changes: 2 additions & 0 deletions src/config/env.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export type Sqs = {
SECRET_ACCESS_KEY: string;
ACCOUNT_ID: string;
REGION: string;
ENDPOINT?: string;
MAX_PAYLOAD_SIZE: number;
EVENTS: {
APPLICATION_STARTUP: boolean;
Expand Down Expand Up @@ -585,6 +586,7 @@ export class ConfigService {
SECRET_ACCESS_KEY: process.env.SQS_SECRET_ACCESS_KEY || '',
ACCOUNT_ID: process.env.SQS_ACCOUNT_ID || '',
REGION: process.env.SQS_REGION || '',
ENDPOINT: process.env.SQS_ENDPOINT || undefined,
MAX_PAYLOAD_SIZE: Number.parseInt(process.env.SQS_MAX_PAYLOAD_SIZE ?? '1048576'),
EVENTS: {
APPLICATION_STARTUP: process.env?.SQS_GLOBAL_APPLICATION_STARTUP === 'true',
Expand Down