sst 2.11.8 → 2.11.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -426,6 +426,7 @@ export declare class EventBus extends Construct implements SSTConstruct {
426
426
  getFunctionBinding(): FunctionBindingProps;
427
427
  private retrierQueue;
428
428
  private retrierFn;
429
+ private retrierMap;
429
430
  private getRetrier;
430
431
  private createEventBus;
431
432
  private addRule;
@@ -8,7 +8,9 @@ import { getFunctionRef, isCDKConstruct } from "./Construct.js";
8
8
  import { Function as Fn, } from "./Function.js";
9
9
  import { SqsEventSource } from "aws-cdk-lib/aws-lambda-event-sources";
10
10
  import { SqsDestination } from "aws-cdk-lib/aws-lambda-destinations";
11
+ import url from "url";
11
12
  import path from "path";
13
+ const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
12
14
  /////////////////////
13
15
  // Construct
14
16
  /////////////////////
@@ -231,12 +233,17 @@ export class EventBus extends Construct {
231
233
  }
232
234
  retrierQueue;
233
235
  retrierFn;
236
+ retrierMap = {};
234
237
  getRetrier() {
238
+ const app = this.node.root;
235
239
  if (this.retrierFn && this.retrierQueue) {
236
240
  return { fn: this.retrierFn, queue: this.retrierQueue };
237
241
  }
238
- this.retrierQueue = new sqs.Queue(this, `RetrierQueue`);
242
+ this.retrierQueue = new sqs.Queue(this, `RetrierQueue`, {
243
+ queueName: app.logicalPrefixedName(this.node.id + "Retrier"),
244
+ });
239
245
  this.retrierFn = new lambda.Function(this, `RetrierFunction`, {
246
+ functionName: app.logicalPrefixedName(this.node.id + "Retrier"),
240
247
  runtime: lambda.Runtime.NODEJS_14_X,
241
248
  handler: "index.handler",
242
249
  code: lambda.Code.fromAsset(path.join(__dirname, "../support/event-bus-retrier")),
@@ -350,7 +357,20 @@ export class EventBus extends Construct {
350
357
  const count = this.subs.get(type) || 0 + 1;
351
358
  this.subs.set(type, count);
352
359
  const name = `${type.replaceAll(/[^a-zA-Z_]/g, "_")}_${count}`;
353
- const fn = Fn.fromDefinition(this, name, target);
360
+ const retries = props?.retries || this.props.defaults?.retries;
361
+ const fn = (() => {
362
+ if (retries) {
363
+ const retrier = this.getRetrier();
364
+ const fn = Fn.fromDefinition(this, name, target, {
365
+ onFailure: new SqsDestination(retrier.queue),
366
+ });
367
+ this.retrierMap[fn.functionArn] = retries;
368
+ retrier.fn.addEnvironment(`RETRIES`, JSON.stringify(this.retrierMap));
369
+ fn.grantInvoke(retrier.fn);
370
+ return fn;
371
+ }
372
+ return Fn.fromDefinition(this, name, target);
373
+ })();
354
374
  this.addRule(this, name + "_rule", {
355
375
  pattern: {
356
376
  detailType: [type],
@@ -374,7 +394,8 @@ export class EventBus extends Construct {
374
394
  target = target;
375
395
  targetProps = target.cdk?.target;
376
396
  functionDefinition = target.function;
377
- retries = target.retries;
397
+ if (target.retries)
398
+ retries = target.retries;
378
399
  }
379
400
  else {
380
401
  target = target;
@@ -385,15 +406,6 @@ export class EventBus extends Construct {
385
406
  this.targetsData[ruleKey][targetName] = fn;
386
407
  // Create target
387
408
  eventsRule.addTarget(new LambdaFunctionTarget(fn, targetProps));
388
- // Configure retrier
389
- if (retries) {
390
- const retrier = this.getRetrier();
391
- retrier.fn.addEnvironment(`RETRIER_${retrier.fn.functionName}`, retries.toString());
392
- fn.grantInvoke(retrier.fn);
393
- fn.configureAsyncInvoke({
394
- onFailure: new SqsDestination(retrier.queue),
395
- });
396
- }
397
409
  // Attach existing permissions
398
410
  this.permissionsAttachedForAllTargets.forEach((permissions) => fn.attachPermissions(permissions));
399
411
  fn.bind(this.bindingForAllTargets);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "sideEffects": false,
3
3
  "name": "sst",
4
- "version": "2.11.8",
4
+ "version": "2.11.9",
5
5
  "bin": {
6
6
  "sst": "cli/sst.js"
7
7
  },