sst 2.1.32 → 2.1.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.
@@ -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/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
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sst",
3
- "version": "2.1.32",
3
+ "version": "2.1.33",
4
4
  "bin": {
5
5
  "sst": "cli/sst.js"
6
6
  },