Skip to content

Commit cbc5571

Browse files
nicksiegergodu
authored andcommitted
Build eventSourceARN from stream name and config
When the event configuration arn is not a string (e.g., an object with 'Fn::GetAtt' referring to a queue resource, use the stream/queue name plus config to build the arn.
1 parent 630fc2c commit cbc5571

File tree

1 file changed

+12
-4
lines changed
  • packages/serverless-offline-sqs/src

1 file changed

+12
-4
lines changed

packages/serverless-offline-sqs/src/index.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ class ServerlessOfflineSQS {
9393
const streamName = this.getQueueName(queueEvent);
9494
this.serverless.cli.log(`${streamName} (λ: ${functionName})`);
9595

96-
const {location = '.'} = this.getConfig();
96+
const config = this.getConfig();
97+
const {location = '.'} = config;
9798

9899
const __function = this.service.getFunction(functionName);
99100

@@ -114,7 +115,7 @@ class ServerlessOfflineSQS {
114115
servicePath,
115116
serviceRuntime
116117
);
117-
const handler = functionHelper.createHandler(funOptions, this.getConfig());
118+
const handler = functionHelper.createHandler(funOptions, config);
118119

119120
const lambdaContext = new LambdaContext(__function, this.service.provider, (err, data) => {
120121
this.serverless.cli.log(
@@ -123,6 +124,13 @@ class ServerlessOfflineSQS {
123124
cb(err, data);
124125
});
125126

127+
const awsRegion = config.region || 'us-west-2';
128+
const awsAccountId = config.accountId || '000000000000';
129+
const eventSourceARN =
130+
typeof queueEvent.arn === 'string'
131+
? queueEvent.arn
132+
: `arn:aws:sqs:${awsRegion}:${awsAccountId}:${streamName}`;
133+
126134
const event = {
127135
Records: messages.map(
128136
({
@@ -140,8 +148,8 @@ class ServerlessOfflineSQS {
140148
messageAttributes,
141149
md5OfBody,
142150
eventSource: 'aws:sqs',
143-
eventSourceARN: queueEvent.arn,
144-
awsRegion: 'us-west-2'
151+
eventSourceARN,
152+
awsRegion
145153
})
146154
)
147155
};

0 commit comments

Comments
 (0)