sst 2.0.31 → 2.0.33
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.
- package/constructs/EventBus.d.ts +16 -4
- package/constructs/EventBus.js +29 -5
- package/constructs/Function.d.ts +3 -0
- package/constructs/Function.js +17 -7
- package/iot.js +1 -0
- package/package.json +1 -1
- package/sst.mjs +1 -0
package/constructs/EventBus.d.ts
CHANGED
|
@@ -152,7 +152,7 @@ export interface EventBusRuleProps {
|
|
|
152
152
|
* },
|
|
153
153
|
* },
|
|
154
154
|
* targets: {
|
|
155
|
-
* myTarget1: "
|
|
155
|
+
* myTarget1: "src/lambda.handler",
|
|
156
156
|
* },
|
|
157
157
|
* },
|
|
158
158
|
* },
|
|
@@ -262,6 +262,15 @@ export declare class EventBus extends Construct implements SSTConstruct {
|
|
|
262
262
|
* The name of the internally created `EventBus` instance.
|
|
263
263
|
*/
|
|
264
264
|
get eventBusName(): string;
|
|
265
|
+
/**
|
|
266
|
+
* Get a rule
|
|
267
|
+
*
|
|
268
|
+
* @example
|
|
269
|
+
* ```js
|
|
270
|
+
* bus.getRule("myRule");
|
|
271
|
+
* ```
|
|
272
|
+
*/
|
|
273
|
+
getRule(key: string): events.Rule | undefined;
|
|
265
274
|
/**
|
|
266
275
|
* Add rules after the EventBus has been created.
|
|
267
276
|
*
|
|
@@ -280,14 +289,17 @@ export declare class EventBus extends Construct implements SSTConstruct {
|
|
|
280
289
|
*/
|
|
281
290
|
addRules(scope: Construct, rules: Record<string, EventBusRuleProps>): void;
|
|
282
291
|
/**
|
|
283
|
-
*
|
|
292
|
+
* Add targets to existing rules.
|
|
284
293
|
*
|
|
285
294
|
* @example
|
|
286
295
|
* ```js
|
|
287
|
-
* bus.
|
|
296
|
+
* bus.addRules(stack, "myRule", {
|
|
297
|
+
* myTarget1: "src/function1.handler"
|
|
298
|
+
* myTarget2: "src/function2.handler"
|
|
299
|
+
* });
|
|
288
300
|
* ```
|
|
289
301
|
*/
|
|
290
|
-
|
|
302
|
+
addTargets(scope: Construct, ruleKey: string, targets: Record<string, FunctionInlineDefinition | EventBusFunctionTargetProps | Queue | EventBusQueueTargetProps>): void;
|
|
291
303
|
/**
|
|
292
304
|
* Binds the given list of resources to all event targets in this EventBus.
|
|
293
305
|
*
|
package/constructs/EventBus.js
CHANGED
|
@@ -56,6 +56,17 @@ export class EventBus extends Construct {
|
|
|
56
56
|
get eventBusName() {
|
|
57
57
|
return this.cdk.eventBus.eventBusName;
|
|
58
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Get a rule
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```js
|
|
64
|
+
* bus.getRule("myRule");
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
getRule(key) {
|
|
68
|
+
return this.rulesData[key];
|
|
69
|
+
}
|
|
59
70
|
/**
|
|
60
71
|
* Add rules after the EventBus has been created.
|
|
61
72
|
*
|
|
@@ -76,15 +87,24 @@ export class EventBus extends Construct {
|
|
|
76
87
|
Object.entries(rules).forEach(([ruleKey, rule]) => this.addRule(scope, ruleKey, rule));
|
|
77
88
|
}
|
|
78
89
|
/**
|
|
79
|
-
*
|
|
90
|
+
* Add targets to existing rules.
|
|
80
91
|
*
|
|
81
92
|
* @example
|
|
82
93
|
* ```js
|
|
83
|
-
* bus.
|
|
94
|
+
* bus.addRules(stack, "myRule", {
|
|
95
|
+
* myTarget1: "src/function1.handler"
|
|
96
|
+
* myTarget2: "src/function2.handler"
|
|
97
|
+
* });
|
|
84
98
|
* ```
|
|
85
99
|
*/
|
|
86
|
-
|
|
87
|
-
|
|
100
|
+
addTargets(scope, ruleKey, targets) {
|
|
101
|
+
// Get rule
|
|
102
|
+
const eventsRule = this.getRule(ruleKey);
|
|
103
|
+
if (!eventsRule) {
|
|
104
|
+
throw new Error(`Cannot find the rule "${ruleKey}" in the "${this.node.id}" EventBus.`);
|
|
105
|
+
}
|
|
106
|
+
// Add targets
|
|
107
|
+
Object.entries(targets).forEach(([targetName, target]) => this.addTarget(scope, ruleKey, eventsRule, targetName, target));
|
|
88
108
|
}
|
|
89
109
|
/**
|
|
90
110
|
* Binds the given list of resources to all event targets in this EventBus.
|
|
@@ -246,10 +266,14 @@ export class EventBus extends Construct {
|
|
|
246
266
|
});
|
|
247
267
|
this.rulesData[ruleKey] = eventsRule;
|
|
248
268
|
// Create Targets
|
|
249
|
-
|
|
269
|
+
this.addTargets(scope, ruleKey, rule.targets || {});
|
|
250
270
|
}
|
|
251
271
|
addTarget(scope, ruleKey, eventsRule, targetName, target) {
|
|
252
272
|
this.targetsData[ruleKey] = this.targetsData[ruleKey] || {};
|
|
273
|
+
// Validate rule not redefined
|
|
274
|
+
if (this.targetsData[ruleKey][targetName]) {
|
|
275
|
+
throw new Error(`A target with name "${targetName}" already exists in rule "${ruleKey}"`);
|
|
276
|
+
}
|
|
253
277
|
if (target instanceof Queue || target.queue) {
|
|
254
278
|
target = target;
|
|
255
279
|
this.addQueueTarget(scope, ruleKey, eventsRule, targetName, target);
|
package/constructs/Function.d.ts
CHANGED
|
@@ -598,6 +598,9 @@ export declare class Function extends lambda.Function implements SSTConstruct {
|
|
|
598
598
|
};
|
|
599
599
|
};
|
|
600
600
|
private createUrl;
|
|
601
|
+
private isNodeRuntime;
|
|
602
|
+
static validateHandlerSet(id: string, props: FunctionProps): void;
|
|
603
|
+
static validateVpcSettings(id: string, props: FunctionProps): void;
|
|
601
604
|
static buildLayers(scope: Construct, id: string, props: FunctionProps): cdk.aws_lambda.ILayerVersion[];
|
|
602
605
|
static normalizeMemorySize(memorySize?: number | Size): number;
|
|
603
606
|
static normalizeDiskSize(diskSize?: number | Size): cdk.Size;
|
package/constructs/Function.js
CHANGED
|
@@ -101,12 +101,8 @@ export class Function extends lambda.Function {
|
|
|
101
101
|
const logRetention = props.logRetention &&
|
|
102
102
|
logs.RetentionDays[props.logRetention.toUpperCase()];
|
|
103
103
|
const isLiveDevEnabled = props.enableLiveDev === false ? false : true;
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
throw new Error(`No handler defined for the "${id}" Lambda function`);
|
|
107
|
-
}
|
|
108
|
-
// Validate input
|
|
109
|
-
const isNodeRuntime = props.runtime.startsWith("nodejs");
|
|
104
|
+
Function.validateHandlerSet(id, props);
|
|
105
|
+
Function.validateVpcSettings(id, props);
|
|
110
106
|
// Handle local development (ie. sst start)
|
|
111
107
|
// - set runtime to nodejs12.x for non-Node runtimes (b/c the stub is in Node)
|
|
112
108
|
// - set retry to 0. When the debugger is disconnected, the Cron construct
|
|
@@ -223,7 +219,7 @@ export class Function extends lambda.Function {
|
|
|
223
219
|
}
|
|
224
220
|
this.id = id;
|
|
225
221
|
this.props = props || {};
|
|
226
|
-
if (isNodeRuntime) {
|
|
222
|
+
if (this.isNodeRuntime()) {
|
|
227
223
|
// Enable reusing connections with Keep-Alive for NodeJs
|
|
228
224
|
// Lambda function
|
|
229
225
|
this.addEnvironment("AWS_NODEJS_CONNECTION_REUSE_ENABLED", "1", {
|
|
@@ -345,6 +341,20 @@ export class Function extends lambda.Function {
|
|
|
345
341
|
cors: functionUrlCors.buildCorsConfig(cors),
|
|
346
342
|
});
|
|
347
343
|
}
|
|
344
|
+
isNodeRuntime() {
|
|
345
|
+
const { runtime } = this.props;
|
|
346
|
+
return runtime.startsWith("nodejs");
|
|
347
|
+
}
|
|
348
|
+
static validateHandlerSet(id, props) {
|
|
349
|
+
if (!props.handler) {
|
|
350
|
+
throw new Error(`No handler defined for the "${id}" Lambda function`);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
static validateVpcSettings(id, props) {
|
|
354
|
+
if (props.securityGroups && !props.vpc) {
|
|
355
|
+
throw new Error(`Cannot configure "securityGroups" without "vpc" for the "${id}" Lambda function.`);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
348
358
|
static buildLayers(scope, id, props) {
|
|
349
359
|
return (props.layers || []).map((layer) => {
|
|
350
360
|
if (typeof layer === "string") {
|
package/iot.js
CHANGED
|
@@ -25,6 +25,7 @@ export const useIOT = Context.memo(async () => {
|
|
|
25
25
|
const device = new iot.device({
|
|
26
26
|
protocol: "wss",
|
|
27
27
|
host: endpoint,
|
|
28
|
+
region: project.config.region,
|
|
28
29
|
accessKeyId: creds.accessKeyId,
|
|
29
30
|
secretKey: creds.secretAccessKey,
|
|
30
31
|
sessionToken: creds.sessionToken,
|
package/package.json
CHANGED
package/sst.mjs
CHANGED
|
@@ -2546,6 +2546,7 @@ var init_iot = __esm({
|
|
|
2546
2546
|
const device = new iot.device({
|
|
2547
2547
|
protocol: "wss",
|
|
2548
2548
|
host: endpoint,
|
|
2549
|
+
region: project.config.region,
|
|
2549
2550
|
accessKeyId: creds.accessKeyId,
|
|
2550
2551
|
secretKey: creds.secretAccessKey,
|
|
2551
2552
|
sessionToken: creds.sessionToken
|