sst 2.1.33 → 2.1.34
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/Job.d.ts +14 -0
- package/constructs/Job.js +18 -4
- package/package.json +1 -1
package/constructs/Job.d.ts
CHANGED
|
@@ -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:
|
|
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(
|
|
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(
|
|
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)
|