|
|
|
// At the top of the file define your queue name as an export |
|
export const QUEUE_NAME = `membership-events-queue`; |
|
|
|
// Create your SQS queue as normal: |
|
|
|
export const composeMembershipEventsHandler = ( |
|
stack: Stack, |
|
props: ComposeBackgroundEventProps |
|
) => { |
|
const { env, tables } = props; |
|
|
|
/** |
|
* Create queues to handle the event data and trigger events |
|
*/ |
|
const dlq = new sqs.Queue(stack, `${env}-membership-events-dlq`, { |
|
queueName: `${env}-membership-events-dlq`, |
|
encryption: sqs.QueueEncryption.KMS_MANAGED, |
|
retentionPeriod: Duration.days(14), |
|
}); |
|
tagComponent(dlq, "private"); |
|
|
|
const queue = new sqs.Queue(stack, `${env}-${QUEUE_NAME}`, { |
|
queueName: `${env}-membership-events-queue`, |
|
encryption: sqs.QueueEncryption.KMS_MANAGED, |
|
deadLetterQueue: { |
|
maxReceiveCount: 2, |
|
queue: dlq, |
|
}, |
|
}); |
|
... |
|
}; |
|
|
|
// Now in your other stack, compose the ARN and import it: |
|
|
|
import { QUEUE_NAME } from "~/background-events-stack/membershipEvents"; |
|
|
|
export const composeMembershipHandlerFunction = ( |
|
stack: Stack, |
|
props: ComposeHandlerFunction |
|
) => { |
|
const { env, tables } = props; |
|
|
|
/** |
|
* Find the queue responsible for handling class based events |
|
*/ |
|
const queueArn = `arn:aws:sqs:${stack.region}:${stack.account}:${env}-${QUEUE_NAME}`; |
|
const queue = sqs.Queue.fromQueueArn( |
|
stack, |
|
`${env}-class-handler-${QUEUE_NAME}`, |
|
queueArn |
|
); |
|
... |
|
}; |