sst 2.1.32 → 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/Function.js +1 -1
- package/constructs/Job.d.ts +14 -0
- package/constructs/Job.js +18 -4
- package/iot.js +42 -14
- package/package.json +1 -1
- package/sst.mjs +959 -930
- package/support/base-site-archiver.mjs +16 -16
- package/support/bridge/bridge.mjs +70 -45
- package/support/ssr-site-function-archiver.mjs +15 -15
package/constructs/Function.js
CHANGED
|
@@ -141,7 +141,7 @@ export class Function extends CDKFunction {
|
|
|
141
141
|
this.addEnvironment("SST_FUNCTION_ID", this.node.addr);
|
|
142
142
|
this.attachPermissions([
|
|
143
143
|
new PolicyStatement({
|
|
144
|
-
actions: ["iot:*"],
|
|
144
|
+
actions: ["iot:*", "s3:*"],
|
|
145
145
|
effect: Effect.ALLOW,
|
|
146
146
|
resources: ["*"],
|
|
147
147
|
}),
|
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)
|
package/iot.js
CHANGED
|
@@ -17,11 +17,52 @@ import iot from "aws-iot-device-sdk";
|
|
|
17
17
|
import { useBus } from "./bus.js";
|
|
18
18
|
import { useProject } from "./project.js";
|
|
19
19
|
import { Logger } from "./logger.js";
|
|
20
|
+
import { useBootstrap } from "./bootstrap.js";
|
|
21
|
+
import { PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
|
|
20
22
|
export const useIOT = Context.memo(async () => {
|
|
21
23
|
const bus = useBus();
|
|
22
24
|
const endpoint = await useIOTEndpoint();
|
|
23
25
|
const creds = await useAWSCredentials();
|
|
24
26
|
const project = useProject();
|
|
27
|
+
const bootstrap = await useBootstrap();
|
|
28
|
+
const s3 = useAWSClient(S3Client);
|
|
29
|
+
async function encode(input) {
|
|
30
|
+
const id = Math.random().toString();
|
|
31
|
+
const json = JSON.stringify(input);
|
|
32
|
+
if (json.length > 1024 * 1024 * 3) {
|
|
33
|
+
// upload to s3
|
|
34
|
+
const key = `pointers/${id}`;
|
|
35
|
+
await s3.send(new PutObjectCommand({
|
|
36
|
+
Bucket: bootstrap.bucket,
|
|
37
|
+
Key: key,
|
|
38
|
+
Body: json,
|
|
39
|
+
}));
|
|
40
|
+
return [
|
|
41
|
+
{
|
|
42
|
+
id,
|
|
43
|
+
index: 0,
|
|
44
|
+
count: 1,
|
|
45
|
+
data: JSON.stringify({
|
|
46
|
+
type: "pointer",
|
|
47
|
+
properties: {
|
|
48
|
+
key,
|
|
49
|
+
bucket: bootstrap.bucket,
|
|
50
|
+
},
|
|
51
|
+
}),
|
|
52
|
+
},
|
|
53
|
+
];
|
|
54
|
+
}
|
|
55
|
+
const parts = json.match(/.{1,100000}/g);
|
|
56
|
+
if (!parts)
|
|
57
|
+
return [];
|
|
58
|
+
Logger.debug("Encoded iot message into", parts?.length, "parts");
|
|
59
|
+
return parts.map((part, index) => ({
|
|
60
|
+
id,
|
|
61
|
+
index,
|
|
62
|
+
count: parts?.length,
|
|
63
|
+
data: part,
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
25
66
|
/*
|
|
26
67
|
console.log(endpoint, creds);
|
|
27
68
|
const config =
|
|
@@ -107,7 +148,7 @@ export const useIOT = Context.memo(async () => {
|
|
|
107
148
|
properties,
|
|
108
149
|
sourceID: bus.sourceID,
|
|
109
150
|
};
|
|
110
|
-
for (const fragment of encode(payload)) {
|
|
151
|
+
for (const fragment of await encode(payload)) {
|
|
111
152
|
await new Promise((r) => {
|
|
112
153
|
device.publish(topic, JSON.stringify(fragment), {
|
|
113
154
|
qos: 1,
|
|
@@ -120,16 +161,3 @@ export const useIOT = Context.memo(async () => {
|
|
|
120
161
|
},
|
|
121
162
|
};
|
|
122
163
|
});
|
|
123
|
-
function encode(input) {
|
|
124
|
-
const json = JSON.stringify(input);
|
|
125
|
-
const parts = json.match(/.{1,100000}/g);
|
|
126
|
-
if (!parts)
|
|
127
|
-
return [];
|
|
128
|
-
const id = Math.random().toString();
|
|
129
|
-
return parts.map((part, index) => ({
|
|
130
|
-
id,
|
|
131
|
-
index,
|
|
132
|
-
count: parts?.length,
|
|
133
|
-
data: part,
|
|
134
|
-
}));
|
|
135
|
-
}
|