Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bus-sqs): use aws-sdk v3, allow passing ARNs #199

Open
wants to merge 3 commits into
base: aws-sdk-3
Choose a base branch
from
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
5 changes: 3 additions & 2 deletions packages/bus-sqs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
"access": "public"
},
"dependencies": {
"@aws-sdk/client-sns": "^3.289.0",
"@aws-sdk/client-sqs": "^3.289.0",
"@aws-sdk/util-arn-parser": "^3.208.0",
"@node-ts/bus-messages": "^1.0.4",
"aws-sdk": "^2.834.0",
"tslib": "^1.9.3",
"uuid": "^3.3.2"
},
"devDependencies": {
Expand Down
15 changes: 10 additions & 5 deletions packages/bus-sqs/src/queue-resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { SqsTransportConfiguration } from './sqs-transport-configuration'

const invalidSqsSnsCharacters = new RegExp('[^a-zA-Z0-9_-]', 'g')

export const normalizeMessageName = (messageName: string) =>
messageName.replace(invalidSqsSnsCharacters, '-')

Expand All @@ -20,9 +23,11 @@ export const resolveTopicName = (messageName: string) =>
export const resolveTopicArn = (awsAccountId: string, awsRegion: string, topicName: string) =>
`arn:aws:sns:${awsRegion}:${awsAccountId}:${topicName}`

export const resolveQueueUrl = (href: string, awsAccountId: string, queueName: string) =>
`${href}${awsAccountId}/${queueName}`
export const resolveQueueUrl = ({ awsAccountId, awsRegion }: SqsTransportConfiguration, queueName: string) =>
`https://sqs.${awsRegion}.amazonaws.com/${awsAccountId}/${queueName}`;

export const resolveQueueArn = (awsAccountId: string, awsRegion: string, queueName: string) =>
`arn:aws:sqs:${awsRegion}:${awsAccountId}:${queueName}`
export const resolveDeadLetterQueueName = () =>
`dead-letter-queue`
`arn:aws:sqs:${awsRegion}:${awsAccountId}:${queueName}`

export const resolveDeadLetterQueueName = () => `dlq`

23 changes: 20 additions & 3 deletions packages/bus-sqs/src/sqs-transport-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,40 @@ import {
resolveTopicName as defaultResolveTopicName
} from './queue-resolvers'

export interface SqsTransportConfiguration extends TransportConfiguration {
export interface SqsTransportConfiguration extends Omit<TransportConfiguration, 'queueName'> {
/**
* The AWS Account Id of the account where queues and topics will be created
*/
awsAccountId: string
awsAccountId?: string

/**
* The AWS region to create queues and topics in
*/
awsRegion: string
awsRegion?: string

/**
* An optional AWS ARN of the dead letter queue to fail messages to
* @default undefined
*/
deadLetterQueueArn?: string;

/**
* The number of seconds to retain messages in the service and dead letter queues
* @default 1209600 (14 days)
*/
messageRetentionPeriod?: number

/**
* The AWS ARN for the target SQS Queue
*/
queueArn?: string

/**
* The name of the queue that receives incoming messages
* @example order-booking-service
*/
queueName?: string;

/**
* An optional custom queue policy to apply to any created SQS queues.
* By default a generic policy will be added that grants send permissions to SNS
Expand Down
Loading