sst 2.1.33 → 2.1.35

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,4 +1,5 @@
1
1
  import { Construct } from "constructs";
2
+ import { RetentionDays } from "aws-cdk-lib/aws-logs";
2
3
  import { SSTConstruct } from "./Construct.js";
3
4
  import { Function, NodeJSProps } from "./Function.js";
4
5
  import { Duration } from "./util/duration.js";
@@ -105,6 +106,18 @@ export interface JobProps {
105
106
  * ```
106
107
  */
107
108
  permissions?: Permissions;
109
+ /**
110
+ * The duration logs are kept in CloudWatch Logs.
111
+ * @default Logs retained indefinitely
112
+ * @example
113
+ * ```js
114
+ * new Job(stack, "MyJob", {
115
+ * handler: "src/job.handler",
116
+ * logRetention: "one_week"
117
+ * })
118
+ * ```
119
+ */
120
+ logRetention?: Lowercase<keyof typeof RetentionDays>;
108
121
  cdk?: {
109
122
  /**
110
123
  * Allows you to override default id for this construct.
@@ -185,6 +198,7 @@ export declare class Job extends Construct implements SSTConstruct {
185
198
  */
186
199
  addEnvironment(name: string, value: string): void;
187
200
  private createCodeBuildProject;
201
+ private createLogRetention;
188
202
  private buildCodeBuildProjectCode;
189
203
  private updateCodeBuildProjectCode;
190
204
  private createLocalInvoker;
package/constructs/Job.js CHANGED
@@ -1,4 +1,3 @@
1
- // import path from "path";
2
1
  import url from "url";
3
2
  import path from "path";
4
3
  import fs from "fs/promises";
@@ -6,6 +5,7 @@ import { Construct } from "constructs";
6
5
  import { PolicyStatement, Effect } from "aws-cdk-lib/aws-iam";
7
6
  import { AssetCode } from "aws-cdk-lib/aws-lambda";
8
7
  import { Project, LinuxBuildImage, BuildSpec, ComputeType, } from "aws-cdk-lib/aws-codebuild";
8
+ import { RetentionDays, LogRetention } from "aws-cdk-lib/aws-logs";
9
9
  import { Stack } from "./Stack.js";
10
10
  import { Function, useFunctions } from "./Function.js";
11
11
  import { toCdkDuration } from "./util/duration.js";
@@ -54,6 +54,7 @@ export class Job extends Construct {
54
54
  .replace(/\./g, "-");
55
55
  const isLiveDevEnabled = app.local && (this.props.enableLiveDev === false ? false : true);
56
56
  this.job = this.createCodeBuildProject();
57
+ this.createLogRetention();
57
58
  if (isLiveDevEnabled) {
58
59
  this._jobInvoker = this.createLocalInvoker();
59
60
  }
@@ -127,9 +128,10 @@ export class Job extends Construct {
127
128
  this.addEnvironmentForCodeBuild(name, value);
128
129
  }
129
130
  createCodeBuildProject() {
131
+ const { cdk, memorySize, timeout } = this.props;
130
132
  const app = this.node.root;
131
133
  return new Project(this, "JobProject", {
132
- vpc: this.props.cdk?.vpc,
134
+ vpc: cdk?.vpc,
133
135
  projectName: app.logicalPrefixedName(this.node.id),
134
136
  environment: {
135
137
  // CodeBuild offers different build images. The newer ones have much quicker
@@ -139,14 +141,14 @@ export class Job extends Construct {
139
141
  //buildImage: codebuild.LinuxBuildImage.STANDARD_6_0,
140
142
  //buildImage: codebuild.LinuxBuildImage.STANDARD_5_0,
141
143
  buildImage: LinuxBuildImage.fromDockerRegistry("amazon/aws-lambda-nodejs:16"),
142
- computeType: this.normalizeMemorySize(this.props.memorySize || "3 GB"),
144
+ computeType: this.normalizeMemorySize(memorySize || "3 GB"),
143
145
  },
144
146
  environmentVariables: {
145
147
  SST_APP: { value: app.name },
146
148
  SST_STAGE: { value: app.stage },
147
149
  SST_SSM_PREFIX: { value: useProject().config.ssmPrefix },
148
150
  },
149
- timeout: this.normalizeTimeout(this.props.timeout || "8 hours"),
151
+ timeout: this.normalizeTimeout(timeout || "8 hours"),
150
152
  buildSpec: BuildSpec.fromObject({
151
153
  version: "0.2",
152
154
  phases: {
@@ -159,6 +161,18 @@ export class Job extends Construct {
159
161
  }),
160
162
  });
161
163
  }
164
+ createLogRetention() {
165
+ const { logRetention } = this.props;
166
+ if (!logRetention)
167
+ return;
168
+ new LogRetention(this, "LogRetention", {
169
+ logGroupName: `/aws/codebuild/${this.job.projectName}`,
170
+ retention: RetentionDays[logRetention.toUpperCase()],
171
+ logRetentionRetryOptions: {
172
+ maxRetries: 100,
173
+ },
174
+ });
175
+ }
162
176
  buildCodeBuildProjectCode() {
163
177
  const app = this.node.root;
164
178
  // Handle remove (ie. sst remove)
package/credentials.js CHANGED
@@ -66,17 +66,24 @@ export function useAWSClient(client, force = false) {
66
66
  region: project.config.region,
67
67
  credentials: credentials,
68
68
  retryStrategy: new StandardRetryStrategy(async () => 10000, {
69
- retryDecider: (err) => {
70
- // Handle credential errors => no retry
71
- if (err.name === "CredentialsProviderError")
72
- return false;
73
- if (err.message === "Could not load credentials from any providers")
74
- return false;
75
- // Handle no internet connection
76
- if (err.code === "ENOTFOUND") {
69
+ retryDecider: (e) => {
70
+ // Handle no internet connection => retry
71
+ if (e.code === "ENOTFOUND") {
77
72
  printNoInternet();
78
73
  }
79
- return true;
74
+ // Handle throttling errors => retry
75
+ if ([
76
+ "ThrottlingException",
77
+ "Throttling",
78
+ "TooManyRequestsException",
79
+ "OperationAbortedException",
80
+ "TimeoutError",
81
+ "NetworkingError",
82
+ ].includes(e.name)) {
83
+ Logger.debug("Retry AWS call", e.name, e.message);
84
+ return true;
85
+ }
86
+ return false;
80
87
  },
81
88
  delayDecider: (_, attempts) => {
82
89
  return Math.min(1.5 ** attempts * 100, 5000);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sst",
3
- "version": "2.1.33",
3
+ "version": "2.1.35",
4
4
  "bin": {
5
5
  "sst": "cli/sst.js"
6
6
  },
package/sst.mjs CHANGED
@@ -1619,15 +1619,22 @@ function useAWSClient(client, force = false) {
1619
1619
  region: project.config.region,
1620
1620
  credentials,
1621
1621
  retryStrategy: new StandardRetryStrategy(async () => 1e4, {
1622
- retryDecider: (err) => {
1623
- if (err.name === "CredentialsProviderError")
1624
- return false;
1625
- if (err.message === "Could not load credentials from any providers")
1626
- return false;
1627
- if (err.code === "ENOTFOUND") {
1622
+ retryDecider: (e) => {
1623
+ if (e.code === "ENOTFOUND") {
1628
1624
  printNoInternet();
1629
1625
  }
1630
- return true;
1626
+ if ([
1627
+ "ThrottlingException",
1628
+ "Throttling",
1629
+ "TooManyRequestsException",
1630
+ "OperationAbortedException",
1631
+ "TimeoutError",
1632
+ "NetworkingError"
1633
+ ].includes(e.name)) {
1634
+ Logger.debug("Retry AWS call", e.name, e.message);
1635
+ return true;
1636
+ }
1637
+ return false;
1631
1638
  },
1632
1639
  delayDecider: (_, attempts) => {
1633
1640
  return Math.min(1.5 ** attempts * 100, 5e3);