feat: add support for custom SQS endpoint#2458
feat: add support for custom SQS endpoint#2458maxir143 wants to merge 3 commits intoevolution-foundation:developfrom
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdds optional support for a custom SQS endpoint (e.g., Localstack) by wiring a new SQS_ENDPOINT env var through configuration, SQS client initialization, and queue URL construction while preserving existing default AWS behavior when not set. Sequence diagram for publishing SQS message with optional custom endpointsequenceDiagram
actor User
participant Service
participant ConfigService
participant SqsController
participant AwsSQS as Aws_SQS_SDK
User->>Service: triggerEvent(event, payload)
Service->>ConfigService: getSqsConfig()
ConfigService-->>Service: Sqs config (includes ENDPOINT)
Service->>SqsController: publishEvent(event, payload, extra)
SqsController->>SqsController: initializeSqs() with REGION and ENDPOINT
alt Custom endpoint provided
SqsController->>SqsController: buildQueueUrl() using ENDPOINT without trailing slash
else Default AWS endpoint
SqsController->>SqsController: buildQueueUrl() using https://sqs.REGION.amazonaws.com
end
SqsController->>AwsSQS: sendMessage(queueUrl, message)
AwsSQS-->>SqsController: sendMessageResult
SqsController-->>Service: publishEvent result
Service-->>User: event processed
Updated class diagram for SQS configuration and controllerclassDiagram
class Sqs {
+string ACCESS_KEY_ID
+string SECRET_ACCESS_KEY
+string ACCOUNT_ID
+string REGION
+string ENDPOINT
+number MAX_PAYLOAD_SIZE
}
class ConfigService {
+getSqsConfig() Sqs
}
class SqsController {
-Sqs awsConfig
-Sqs sqsConfig
-SQS sqsClient
+constructor(configService ConfigService)
+initializeSqs() void
+publishEvent(event string, payload any, extra any) Promise~void~
-buildQueueUrl(event string, prefixName string) string
}
ConfigService --> Sqs : returns
SqsController --> ConfigService : uses
SqsController --> Sqs : reads configuration
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- Consider making
Sqs.ENDPOINToptional (ENDPOINT?: string) and defaulting it toundefinedinstead of''inConfigServiceso you can avoid relying on truthiness checks and keep the type aligned with how it’s used when passing to the SQS client. - The URL construction for custom endpoints assumes the endpoint does not already contain the account ID path; if users might pass a fully qualified LocalStack URL, you may want to either document that constraint or add a small normalization/validation helper to avoid double-appending the account ID.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider making `Sqs.ENDPOINT` optional (`ENDPOINT?: string`) and defaulting it to `undefined` instead of `''` in `ConfigService` so you can avoid relying on truthiness checks and keep the type aligned with how it’s used when passing to the SQS client.
- The URL construction for custom endpoints assumes the endpoint does not already contain the account ID path; if users might pass a fully qualified LocalStack URL, you may want to either document that constraint or add a small normalization/validation helper to avoid double-appending the account ID.
## Individual Comments
### Comment 1
<location path="src/api/integrations/event/sqs/sqs.controller.ts" line_range="129-130" />
<code_context>
: `${event.replace('.', '_').toLowerCase()}`;
const queueName = `${prefixName}_${eventFormatted}.fifo`;
- const sqsUrl = `https://sqs.${sqsConfig.REGION}.amazonaws.com/${sqsConfig.ACCOUNT_ID}/${queueName}`;
+ const sqsUrl = sqsConfig.ENDPOINT
+ ? `${sqsConfig.ENDPOINT.replace(/\/$/, '')}/${sqsConfig.ACCOUNT_ID}/${queueName}`
+ : `https://sqs.${sqsConfig.REGION}.amazonaws.com/${sqsConfig.ACCOUNT_ID}/${queueName}`;
</code_context>
<issue_to_address>
**nitpick:** Normalize endpoint more robustly when stripping trailing slashes.
`replace(/\/$/, '')` only strips one trailing slash, so an endpoint like `http://localhost:4566///` would still produce extra slashes before the account ID. Using `replace(/\/+$/, '')`, the `URL` API, or a small normalization helper would make this more robust and avoid subtle URL issues.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
…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: evolution-foundation#2458 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Hi! As part of our PR triage, we noticed the Check Code Quality workflow has not run on this PR (it requires maintainer approval for first-time external contributors, which we've now enabled). To trigger CI:
Once CI runs and is green I'll re-review for merge. Thanks! |
There was a problem hiding this comment.
Pull request overview
This PR introduces configuration support for using a custom AWS SQS endpoint (e.g., LocalStack) by adding an SQS_ENDPOINT environment variable and passing it into the SQS client initialization.
Changes:
- Added optional
SQS.ENDPOINTto the config model and populated it fromprocess.env.SQS_ENDPOINT. - Passed the configured endpoint into the AWS SQS client constructor.
- Added a helper method intended to build queue URLs based on the custom endpoint.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/config/env.config.ts |
Adds SQS.ENDPOINT and reads SQS_ENDPOINT from environment variables into runtime config. |
src/api/integrations/event/sqs/sqs.controller.ts |
Configures the SQS client with the custom endpoint and adds a queue URL helper. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (sqsConfig.ENDPOINT) { | ||
| const endpoint = sqsConfig.ENDPOINT.replace(/\/+$/, ''); | ||
| if (endpoint.endsWith(sqsConfig.ACCOUNT_ID)) { | ||
| return `${endpoint}/${queueName}`; | ||
| } | ||
| return `${endpoint}/${sqsConfig.ACCOUNT_ID}/${queueName}`; | ||
| } |
| return `${endpoint}/${queueName}`; | ||
| } | ||
| return `${endpoint}/${sqsConfig.ACCOUNT_ID}/${queueName}`; | ||
| } |
| ACCOUNT_ID: process.env.SQS_ACCOUNT_ID || '', | ||
| REGION: process.env.SQS_REGION || '', | ||
| ENDPOINT: process.env.SQS_ENDPOINT || undefined, | ||
| BASE_URL: process.env.SQS_BASE_URL || '', | ||
| MAX_PAYLOAD_SIZE: Number.parseInt(process.env.SQS_MAX_PAYLOAD_SIZE ?? '1048576'), |
📋 Description
Add support for custom endpoint at SQS enabling users to use localstack endpoint, config, set it and clean the endpoint from environment variables, if not, fallback to default behaviour.
🔗 Related Issue
Closes #(issue_number)
🧪 Type of Change
🧪 Testing
📸 Screenshots (if applicable)
✅ Checklist
📝 Additional Notes
Summary by Sourcery
Add configurable support for custom SQS endpoints while preserving existing default behavior.
New Features: