sst 2.1.31 → 2.1.32

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.
@@ -1,11 +1,6 @@
1
1
  /* eslint-disable @typescript-eslint/ban-types */
2
2
  // Note: disabling ban-type rule so we don't get an error referencing the class Function
3
3
  import path from "path";
4
- import * as cdk from "aws-cdk-lib";
5
- import * as iam from "aws-cdk-lib/aws-iam";
6
- import * as lambda from "aws-cdk-lib/aws-lambda";
7
- import * as logs from "aws-cdk-lib/aws-logs";
8
- import * as ssm from "aws-cdk-lib/aws-ssm";
9
4
  import { Stack } from "./Stack.js";
10
5
  import { Job } from "./Job.js";
11
6
  import { Secret } from "./Config.js";
@@ -20,32 +15,37 @@ import { useProject } from "../project.js";
20
15
  import { useRuntimeHandlers } from "../runtime/handlers.js";
21
16
  import { createAppContext } from "./context.js";
22
17
  import { useWarning } from "./util/warning.js";
18
+ import { Architecture, AssetCode, Code, Function as CDKFunction, FunctionUrlAuthType, LayerVersion, Runtime as CDKRuntime, Tracing, } from "aws-cdk-lib/aws-lambda";
19
+ import { RetentionDays } from "aws-cdk-lib/aws-logs";
20
+ import { Token, Size as CDKSize, Duration as CDKDuration } from "aws-cdk-lib";
21
+ import { Effect, PolicyStatement } from "aws-cdk-lib/aws-iam";
22
+ import { StringParameter } from "aws-cdk-lib/aws-ssm";
23
23
  const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
24
24
  const supportedRuntimes = {
25
- rust: lambda.Runtime.PROVIDED_AL2,
26
- nodejs: lambda.Runtime.NODEJS,
27
- "nodejs4.3": lambda.Runtime.NODEJS_4_3,
28
- "nodejs6.10": lambda.Runtime.NODEJS_6_10,
29
- "nodejs8.10": lambda.Runtime.NODEJS_8_10,
30
- "nodejs10.x": lambda.Runtime.NODEJS_10_X,
31
- "nodejs12.x": lambda.Runtime.NODEJS_12_X,
32
- "nodejs14.x": lambda.Runtime.NODEJS_14_X,
33
- "nodejs16.x": lambda.Runtime.NODEJS_16_X,
34
- "nodejs18.x": lambda.Runtime.NODEJS_18_X,
35
- "python2.7": lambda.Runtime.PYTHON_2_7,
36
- "python3.6": lambda.Runtime.PYTHON_3_6,
37
- "python3.7": lambda.Runtime.PYTHON_3_7,
38
- "python3.8": lambda.Runtime.PYTHON_3_8,
39
- "python3.9": lambda.Runtime.PYTHON_3_9,
40
- "dotnetcore1.0": lambda.Runtime.DOTNET_CORE_1,
41
- "dotnetcore2.0": lambda.Runtime.DOTNET_CORE_2,
42
- "dotnetcore2.1": lambda.Runtime.DOTNET_CORE_2_1,
43
- "dotnetcore3.1": lambda.Runtime.DOTNET_CORE_3_1,
44
- dotnet6: lambda.Runtime.DOTNET_6,
45
- java8: lambda.Runtime.JAVA_8,
46
- java11: lambda.Runtime.JAVA_11,
47
- "go1.x": lambda.Runtime.PROVIDED_AL2,
48
- go: lambda.Runtime.PROVIDED_AL2,
25
+ rust: CDKRuntime.PROVIDED_AL2,
26
+ nodejs: CDKRuntime.NODEJS,
27
+ "nodejs4.3": CDKRuntime.NODEJS_4_3,
28
+ "nodejs6.10": CDKRuntime.NODEJS_6_10,
29
+ "nodejs8.10": CDKRuntime.NODEJS_8_10,
30
+ "nodejs10.x": CDKRuntime.NODEJS_10_X,
31
+ "nodejs12.x": CDKRuntime.NODEJS_12_X,
32
+ "nodejs14.x": CDKRuntime.NODEJS_14_X,
33
+ "nodejs16.x": CDKRuntime.NODEJS_16_X,
34
+ "nodejs18.x": CDKRuntime.NODEJS_18_X,
35
+ "python2.7": CDKRuntime.PYTHON_2_7,
36
+ "python3.6": CDKRuntime.PYTHON_3_6,
37
+ "python3.7": CDKRuntime.PYTHON_3_7,
38
+ "python3.8": CDKRuntime.PYTHON_3_8,
39
+ "python3.9": CDKRuntime.PYTHON_3_9,
40
+ "dotnetcore1.0": CDKRuntime.DOTNET_CORE_1,
41
+ "dotnetcore2.0": CDKRuntime.DOTNET_CORE_2,
42
+ "dotnetcore2.1": CDKRuntime.DOTNET_CORE_2_1,
43
+ "dotnetcore3.1": CDKRuntime.DOTNET_CORE_3_1,
44
+ dotnet6: CDKRuntime.DOTNET_6,
45
+ java8: CDKRuntime.JAVA_8,
46
+ java11: CDKRuntime.JAVA_11,
47
+ "go1.x": CDKRuntime.PROVIDED_AL2,
48
+ go: CDKRuntime.PROVIDED_AL2,
49
49
  };
50
50
  /**
51
51
  * The `Function` construct is a higher level CDK construct that makes it easy to create a Lambda Function with support for Live Lambda Development.
@@ -60,7 +60,7 @@ const supportedRuntimes = {
60
60
  * });
61
61
  * ```
62
62
  */
63
- export class Function extends lambda.Function {
63
+ export class Function extends CDKFunction {
64
64
  id;
65
65
  _isLiveDevEnabled;
66
66
  /** @internal */
@@ -87,20 +87,19 @@ export class Function extends lambda.Function {
87
87
  (typeof props.functionName === "string"
88
88
  ? props.functionName
89
89
  : props.functionName({ stack, functionProps: props }));
90
- const handler = props.handler;
91
90
  const timeout = Function.normalizeTimeout(props.timeout);
92
91
  const architecture = (() => {
93
92
  if (props.architecture === "arm_64")
94
- return lambda.Architecture.ARM_64;
93
+ return Architecture.ARM_64;
95
94
  if (props.architecture === "x86_64")
96
- return lambda.Architecture.X86_64;
95
+ return Architecture.X86_64;
97
96
  return undefined;
98
97
  })();
99
98
  const memorySize = Function.normalizeMemorySize(props.memorySize);
100
99
  const diskSize = Function.normalizeDiskSize(props.diskSize);
101
- const tracing = lambda.Tracing[(props.tracing || "active").toUpperCase()];
100
+ const tracing = Tracing[(props.tracing || "active").toUpperCase()];
102
101
  const logRetention = props.logRetention &&
103
- logs.RetentionDays[props.logRetention.toUpperCase()];
102
+ RetentionDays[props.logRetention.toUpperCase()];
104
103
  const isLiveDevEnabled = props.enableLiveDev === false ? false : true;
105
104
  Function.validateHandlerSet(id, props);
106
105
  Function.validateVpcSettings(id, props);
@@ -119,16 +118,16 @@ export class Function extends lambda.Function {
119
118
  let debugOverrideProps;
120
119
  if (app.debugIncreaseTimeout) {
121
120
  debugOverrideProps = {
122
- timeout: cdk.Duration.seconds(900),
121
+ timeout: toCdkDuration("900 second"),
123
122
  };
124
123
  }
125
124
  super(scope, id, {
126
125
  ...props,
127
126
  architecture,
128
- code: lambda.Code.fromAsset(path.resolve(__dirname, "../support/bridge")),
127
+ code: Code.fromAsset(path.resolve(__dirname, "../support/bridge")),
129
128
  handler: "bridge.handler",
130
129
  functionName,
131
- runtime: lambda.Runtime.NODEJS_16_X,
130
+ runtime: CDKRuntime.NODEJS_16_X,
132
131
  memorySize,
133
132
  ephemeralStorageSize: diskSize,
134
133
  timeout,
@@ -141,9 +140,9 @@ export class Function extends lambda.Function {
141
140
  });
142
141
  this.addEnvironment("SST_FUNCTION_ID", this.node.addr);
143
142
  this.attachPermissions([
144
- new iam.PolicyStatement({
143
+ new PolicyStatement({
145
144
  actions: ["iot:*"],
146
- effect: iam.Effect.ALLOW,
145
+ effect: Effect.ALLOW,
147
146
  resources: ["*"],
148
147
  }),
149
148
  ]);
@@ -155,10 +154,10 @@ export class Function extends lambda.Function {
155
154
  super(scope, id, {
156
155
  ...props,
157
156
  architecture,
158
- code: lambda.Code.fromInline("export function placeholder() {}"),
157
+ code: Code.fromInline("export function placeholder() {}"),
159
158
  handler: "index.placeholder",
160
159
  functionName,
161
- runtime: lambda.Runtime.NODEJS_16_X,
160
+ runtime: CDKRuntime.NODEJS_16_X,
162
161
  memorySize,
163
162
  ephemeralStorageSize: diskSize,
164
163
  timeout,
@@ -173,10 +172,10 @@ export class Function extends lambda.Function {
173
172
  super(scope, id, {
174
173
  ...props,
175
174
  architecture,
176
- code: lambda.Code.fromInline("export function placeholder() {}"),
175
+ code: Code.fromInline("export function placeholder() {}"),
177
176
  handler: "index.placeholder",
178
177
  functionName,
179
- runtime: lambda.Runtime.NODEJS_16_X,
178
+ runtime: CDKRuntime.NODEJS_16_X,
180
179
  memorySize,
181
180
  ephemeralStorageSize: diskSize,
182
181
  timeout,
@@ -194,7 +193,7 @@ export class Function extends lambda.Function {
194
193
  ...result.errors,
195
194
  ].join("\n"));
196
195
  }
197
- const code = lambda.AssetCode.fromAsset(result.out);
196
+ const code = AssetCode.fromAsset(result.out);
198
197
  // Update function's code
199
198
  const codeConfig = code.bind(this);
200
199
  const cfnFunction = this.node.defaultChild;
@@ -265,9 +264,9 @@ export class Function extends lambda.Function {
265
264
  // Bind permissions
266
265
  const permissions = bindPermissions(c);
267
266
  Object.entries(permissions).forEach(([action, resources]) => this.attachPermissions([
268
- new iam.PolicyStatement({
267
+ new PolicyStatement({
269
268
  actions: [action],
270
- effect: iam.Effect.ALLOW,
269
+ effect: Effect.ALLOW,
271
270
  resources,
272
271
  }),
273
272
  ]));
@@ -330,14 +329,14 @@ export class Function extends lambda.Function {
330
329
  let authType;
331
330
  let cors;
332
331
  if (url === true) {
333
- authType = lambda.FunctionUrlAuthType.NONE;
332
+ authType = FunctionUrlAuthType.NONE;
334
333
  cors = true;
335
334
  }
336
335
  else {
337
336
  authType =
338
337
  url.authorizer === "iam"
339
- ? lambda.FunctionUrlAuthType.AWS_IAM
340
- : lambda.FunctionUrlAuthType.NONE;
338
+ ? FunctionUrlAuthType.AWS_IAM
339
+ : FunctionUrlAuthType.NONE;
341
340
  cors = url.cors === undefined ? true : url.cors;
342
341
  }
343
342
  this.functionUrl = this.addFunctionUrl({
@@ -362,7 +361,7 @@ export class Function extends lambda.Function {
362
361
  static buildLayers(scope, id, props) {
363
362
  return (props.layers || []).map((layer) => {
364
363
  if (typeof layer === "string") {
365
- return lambda.LayerVersion.fromLayerVersionArn(scope, `${id}${layer}`, layer);
364
+ return LayerVersion.fromLayerVersionArn(scope, `${id}${layer}`, layer);
366
365
  }
367
366
  return Function.handleImportedLayer(scope, layer);
368
367
  });
@@ -377,13 +376,13 @@ export class Function extends lambda.Function {
377
376
  if (typeof diskSize === "string") {
378
377
  return toCdkSize(diskSize);
379
378
  }
380
- return cdk.Size.mebibytes(diskSize || 512);
379
+ return CDKSize.mebibytes(diskSize || 512);
381
380
  }
382
381
  static normalizeTimeout(timeout) {
383
382
  if (typeof timeout === "string") {
384
383
  return toCdkDuration(timeout);
385
384
  }
386
- return cdk.Duration.seconds(timeout || 10);
385
+ return CDKDuration.seconds(timeout || 10);
387
386
  }
388
387
  static handleImportedLayer(scope, layer) {
389
388
  const layerStack = Stack.of(layer);
@@ -392,7 +391,7 @@ export class Function extends lambda.Function {
392
391
  // - layer is created in the current stack; OR
393
392
  // - layer is imported (ie. layerArn is a string)
394
393
  if (layerStack === currentStack ||
395
- !cdk.Token.isUnresolved(layer.layerVersionArn)) {
394
+ !Token.isUnresolved(layer.layerVersionArn)) {
396
395
  return layer;
397
396
  }
398
397
  // layer is created from another stack
@@ -404,7 +403,7 @@ export class Function extends lambda.Function {
404
403
  const parameterName = `/layers/${layerStack.node.id}/${parameterId}`;
405
404
  const existingSsmParam = layerStack.node.tryFindChild(parameterId);
406
405
  if (!existingSsmParam) {
407
- new ssm.StringParameter(layerStack, parameterId, {
406
+ new StringParameter(layerStack, parameterId, {
408
407
  parameterName,
409
408
  stringValue: layer.layerVersionArn,
410
409
  });
@@ -416,7 +415,7 @@ export class Function extends lambda.Function {
416
415
  return existingLayer;
417
416
  }
418
417
  else {
419
- return lambda.LayerVersion.fromLayerVersionArn(scope, layerId, ssm.StringParameter.valueForStringParameter(scope, parameterName));
418
+ return LayerVersion.fromLayerVersionArn(scope, layerId, StringParameter.valueForStringParameter(scope, parameterName));
420
419
  }
421
420
  }
422
421
  }
@@ -439,7 +438,7 @@ export class Function extends lambda.Function {
439
438
  }
440
439
  return definition;
441
440
  }
442
- else if (definition instanceof lambda.Function) {
441
+ else if (definition instanceof CDKFunction) {
443
442
  throw new Error(`Please use sst.Function instead of lambda.Function for the "${id}" Function.`);
444
443
  }
445
444
  else if (definition.handler !== undefined) {
@@ -1,6 +1,6 @@
1
+ import { ITopic, Subscription, TopicProps as AWSTopicProps } from "aws-cdk-lib/aws-sns";
2
+ import { LambdaSubscriptionProps, SqsSubscriptionProps } from "aws-cdk-lib/aws-sns-subscriptions";
1
3
  import { Construct } from "constructs";
2
- import * as sns from "aws-cdk-lib/aws-sns";
3
- import * as snsSubscriptions from "aws-cdk-lib/aws-sns-subscriptions";
4
4
  import { SSTConstruct } from "./Construct.js";
5
5
  import { Function as Fn, FunctionProps, FunctionInlineDefinition, FunctionDefinition } from "./Function.js";
6
6
  import { Queue } from "./Queue.js";
@@ -36,7 +36,7 @@ export interface TopicQueueSubscriberProps {
36
36
  /**
37
37
  * This allows you to override the default settings this construct uses internally to create the subscriber.
38
38
  */
39
- subscription?: snsSubscriptions.SqsSubscriptionProps;
39
+ subscription?: SqsSubscriptionProps;
40
40
  };
41
41
  }
42
42
  /**
@@ -64,7 +64,7 @@ export interface TopicFunctionSubscriberProps {
64
64
  /**
65
65
  * This allows you to override the default settings this construct uses internally to create the subscriber.
66
66
  */
67
- subscription?: snsSubscriptions.LambdaSubscriptionProps;
67
+ subscription?: LambdaSubscriptionProps;
68
68
  };
69
69
  }
70
70
  export interface TopicProps {
@@ -108,7 +108,7 @@ export interface TopicProps {
108
108
  /**
109
109
  * Override the default settings this construct uses internally to create the topic.
110
110
  */
111
- topic?: sns.ITopic | sns.TopicProps;
111
+ topic?: ITopic | AWSTopicProps;
112
112
  };
113
113
  }
114
114
  /**
@@ -133,7 +133,7 @@ export declare class Topic extends Construct implements SSTConstruct {
133
133
  /**
134
134
  * The internally created CDK `Topic` instance.
135
135
  */
136
- topic: sns.ITopic;
136
+ topic: ITopic;
137
137
  };
138
138
  private subscribers;
139
139
  private bindingForAllSubscribers;
@@ -151,7 +151,7 @@ export declare class Topic extends Construct implements SSTConstruct {
151
151
  /**
152
152
  * Get a list of subscriptions for this topic
153
153
  */
154
- get subscriptions(): sns.Subscription[];
154
+ get subscriptions(): Subscription[];
155
155
  /**
156
156
  * A list of the internally created function instances for the subscribers.
157
157
  */
@@ -1,6 +1,6 @@
1
+ import { Topic as AWSTopic, } from "aws-cdk-lib/aws-sns";
2
+ import { LambdaSubscription, SqsSubscription, } from "aws-cdk-lib/aws-sns-subscriptions";
1
3
  import { Construct } from "constructs";
2
- import * as sns from "aws-cdk-lib/aws-sns";
3
- import * as snsSubscriptions from "aws-cdk-lib/aws-sns-subscriptions";
4
4
  import { getFunctionRef, isCDKConstruct, isCDKConstructOf, } from "./Construct.js";
5
5
  import { Function as Fn, } from "./Function.js";
6
6
  import { Queue } from "./Queue.js";
@@ -215,7 +215,7 @@ export class Topic extends Construct {
215
215
  }
216
216
  else {
217
217
  const snsTopicProps = (cdk?.topic || {});
218
- this.cdk.topic = new sns.Topic(this, "Topic", {
218
+ this.cdk.topic = new AWSTopic(this, "Topic", {
219
219
  topicName: app.logicalPrefixedName(this.node.id),
220
220
  ...snsTopicProps,
221
221
  });
@@ -232,7 +232,7 @@ export class Topic extends Construct {
232
232
  this.addFunctionSubscriber(scope, subscriberName, subscriber);
233
233
  }
234
234
  }
235
- addQueueSubscriber(scope, subscriberName, subscriber) {
235
+ addQueueSubscriber(_scope, subscriberName, subscriber) {
236
236
  // Parse subscriber props
237
237
  let subscriptionProps;
238
238
  let queue;
@@ -247,7 +247,7 @@ export class Topic extends Construct {
247
247
  }
248
248
  this.subscribers[subscriberName] = queue;
249
249
  // Create Subscription
250
- this.cdk.topic.addSubscription(new snsSubscriptions.SqsSubscription(queue.cdk.queue, subscriptionProps));
250
+ this.cdk.topic.addSubscription(new SqsSubscription(queue.cdk.queue, subscriptionProps));
251
251
  }
252
252
  addFunctionSubscriber(scope, subscriberName, subscriber) {
253
253
  // Parse subscriber props
@@ -265,7 +265,7 @@ export class Topic extends Construct {
265
265
  const fn = Fn.fromDefinition(scope, `Subscriber_${this.node.id}_${subscriberName}`, functionDefinition, this.props.defaults?.function, `The "defaults.function" cannot be applied if an instance of a Function construct is passed in. Make sure to define all the subscribers using FunctionProps, so the Topic construct can apply the "defaults.function" to them.`);
266
266
  this.subscribers[subscriberName] = fn;
267
267
  // Create Subscription
268
- this.cdk.topic.addSubscription(new snsSubscriptions.LambdaSubscription(fn, subscriptionProps));
268
+ this.cdk.topic.addSubscription(new LambdaSubscription(fn, subscriptionProps));
269
269
  // Attach existing permissions
270
270
  this.permissionsAttachedForAllSubscribers.forEach((permissions) => fn.attachPermissions(permissions));
271
271
  fn.bind(this.bindingForAllSubscribers);
package/credentials.js CHANGED
@@ -67,8 +67,7 @@ export function useAWSClient(client, force = false) {
67
67
  credentials: credentials,
68
68
  retryStrategy: new StandardRetryStrategy(async () => 10000, {
69
69
  retryDecider: (err) => {
70
- if (err.$fault === "client")
71
- return false;
70
+ // Handle credential errors => no retry
72
71
  if (err.name === "CredentialsProviderError")
73
72
  return false;
74
73
  if (err.message === "Could not load credentials from any providers")
@@ -5,6 +5,7 @@ export function AuthHandler(input) {
5
5
  return ApiHandler(async (evt) => {
6
6
  const step = usePathParam("step");
7
7
  if (!step) {
8
+ const clients = await input.clients();
8
9
  return {
9
10
  statusCode: 200,
10
11
  headers: {
@@ -13,9 +14,17 @@ export function AuthHandler(input) {
13
14
  body: `
14
15
  <html>
15
16
  <body>
17
+ <table>
18
+ <tr>${Object.keys(clients).map((client) => `<td>${client}</td>`)}</tr>
16
19
  ${Object.keys(input.providers).map((name) => {
17
- return `<a href="/authorize?provider=${name}&response_type=code&client_id=local&redirect_uri=http://localhost:300">${name}</a>`;
20
+ return `<tr>
21
+ ${Object.keys(clients).map((client_id) => {
22
+ const redirect_uri = clients[client_id];
23
+ return `<td><a href="/authorize?provider=${name}&response_type=token&client_id=${client_id}&redirect_uri=${redirect_uri}">${name} - ${client_id}</a></td>`;
24
+ })}
25
+ </tr>`;
18
26
  })}
27
+ </table>
19
28
  </body>
20
29
  </html>
21
30
  `,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sst",
3
- "version": "2.1.31",
3
+ "version": "2.1.32",
4
4
  "bin": {
5
5
  "sst": "cli/sst.js"
6
6
  },
package/sst.mjs CHANGED
@@ -1620,8 +1620,6 @@ function useAWSClient(client, force = false) {
1620
1620
  credentials,
1621
1621
  retryStrategy: new StandardRetryStrategy(async () => 1e4, {
1622
1622
  retryDecider: (err) => {
1623
- if (err.$fault === "client")
1624
- return false;
1625
1623
  if (err.name === "CredentialsProviderError")
1626
1624
  return false;
1627
1625
  if (err.message === "Could not load credentials from any providers")