sst 2.0.0-rc.8 → 2.0.0

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.
Files changed (243) hide show
  1. package/bootstrap.d.ts +2 -4
  2. package/bootstrap.js +208 -61
  3. package/bus.d.ts +3 -3
  4. package/bus.js +1 -1
  5. package/cache.js +1 -1
  6. package/cdk/cloudformation-deployments-wrapper.d.ts +3 -0
  7. package/cdk/cloudformation-deployments-wrapper.js +117 -0
  8. package/cdk/cloudformation-deployments.d.ts +19 -4
  9. package/cdk/deploy-stack.d.ts +17 -2
  10. package/cdk/deploy-stack.js +6 -1
  11. package/cli/colors.d.ts +28 -0
  12. package/cli/colors.js +27 -0
  13. package/cli/commands/bind.d.ts +4 -0
  14. package/cli/commands/bind.js +10 -7
  15. package/cli/commands/bootstrap.d.ts +13 -0
  16. package/cli/commands/bootstrap.js +11 -0
  17. package/cli/commands/build.d.ts +6 -2
  18. package/cli/commands/build.js +13 -8
  19. package/cli/commands/console.d.ts +5 -1
  20. package/cli/commands/console.js +8 -6
  21. package/cli/commands/deploy.d.ts +4 -2
  22. package/cli/commands/deploy.js +71 -29
  23. package/cli/commands/dev.d.ts +5 -1
  24. package/cli/commands/dev.js +157 -79
  25. package/cli/commands/diff.d.ts +15 -0
  26. package/cli/commands/diff.js +61 -0
  27. package/cli/commands/env.d.ts +5 -1
  28. package/cli/commands/env.js +14 -15
  29. package/cli/commands/plugins/kysely.js +13 -5
  30. package/cli/commands/plugins/pothos.js +9 -4
  31. package/cli/commands/remove.d.ts +4 -0
  32. package/cli/commands/remove.js +26 -18
  33. package/cli/commands/secrets/get.d.ts +7 -3
  34. package/cli/commands/secrets/get.js +11 -24
  35. package/cli/commands/secrets/list.d.ts +6 -2
  36. package/cli/commands/secrets/list.js +15 -7
  37. package/cli/commands/secrets/remove.d.ts +8 -4
  38. package/cli/commands/secrets/remove.js +18 -16
  39. package/cli/commands/secrets/secrets.js +3 -3
  40. package/cli/commands/secrets/set.d.ts +8 -6
  41. package/cli/commands/secrets/set.js +16 -33
  42. package/cli/commands/telemetry.d.ts +15 -0
  43. package/cli/commands/telemetry.js +17 -0
  44. package/cli/commands/transform.d.ts +15 -0
  45. package/cli/commands/transform.js +55 -0
  46. package/cli/commands/update.d.ts +6 -2
  47. package/cli/commands/update.js +41 -33
  48. package/cli/commands/version.d.ts +13 -0
  49. package/cli/commands/version.js +7 -0
  50. package/cli/local/router.d.ts +6 -6
  51. package/cli/local/router.js +3 -3
  52. package/cli/local/server.d.ts +5 -3
  53. package/cli/local/server.js +21 -14
  54. package/cli/program.d.ts +5 -1
  55. package/cli/program.js +29 -5
  56. package/cli/spinner.js +2 -0
  57. package/cli/sst.js +35 -23
  58. package/cli/telemetry/environment.d.ts +1 -1
  59. package/cli/telemetry/environment.js +1 -1
  60. package/cli/terminal.d.ts +1 -0
  61. package/cli/terminal.js +8 -0
  62. package/cli/ui/deploy.d.ts +3 -2
  63. package/cli/ui/deploy.js +106 -106
  64. package/cli/ui/functions.d.ts +2 -0
  65. package/cli/ui/functions.js +132 -0
  66. package/cli/ui/header.d.ts +5 -0
  67. package/cli/ui/header.js +16 -0
  68. package/cli/ui/stack.d.ts +1 -0
  69. package/cli/ui/stack.js +6 -0
  70. package/config.d.ts +1 -1
  71. package/config.js +8 -8
  72. package/constructs/Api.d.ts +3 -71
  73. package/constructs/Api.js +3 -42
  74. package/constructs/ApiGatewayV1Api.d.ts +3 -3
  75. package/constructs/ApiGatewayV1Api.js +4 -3
  76. package/constructs/App.d.ts +2 -22
  77. package/constructs/App.js +12 -25
  78. package/constructs/AppSyncApi.d.ts +4 -5
  79. package/constructs/AppSyncApi.js +8 -5
  80. package/constructs/AstroSite.d.ts +2 -3
  81. package/constructs/AstroSite.js +43 -53
  82. package/constructs/Auth.js +27 -16
  83. package/constructs/BaseSite.d.ts +10 -10
  84. package/constructs/BaseSite.js +2 -2
  85. package/constructs/Cognito.js +28 -28
  86. package/constructs/EdgeFunction.d.ts +6 -4
  87. package/constructs/EdgeFunction.js +56 -59
  88. package/constructs/EventBus.js +1 -1
  89. package/constructs/Function.d.ts +4 -44
  90. package/constructs/Function.js +14 -50
  91. package/constructs/FunctionalStack.d.ts +2 -2
  92. package/constructs/Job.d.ts +23 -63
  93. package/constructs/Job.js +11 -32
  94. package/constructs/Metadata.d.ts +18 -20
  95. package/constructs/NextjsSite.d.ts +21 -5
  96. package/constructs/NextjsSite.js +67 -101
  97. package/constructs/Queue.js +10 -10
  98. package/constructs/RDS.d.ts +1 -1
  99. package/constructs/RDS.js +1 -1
  100. package/constructs/RemixSite.d.ts +0 -2
  101. package/constructs/RemixSite.js +20 -20
  102. package/constructs/Script.js +1 -1
  103. package/constructs/Secret.js +5 -3
  104. package/constructs/SolidStartSite.d.ts +2 -3
  105. package/constructs/SolidStartSite.js +42 -52
  106. package/constructs/SsrFunction.d.ts +22 -0
  107. package/constructs/SsrFunction.js +113 -0
  108. package/constructs/SsrSite.d.ts +104 -104
  109. package/constructs/SsrSite.js +196 -217
  110. package/constructs/Stack.d.ts +1 -20
  111. package/constructs/Stack.js +3 -65
  112. package/constructs/StaticSite.d.ts +33 -53
  113. package/constructs/StaticSite.js +92 -118
  114. package/constructs/Table.d.ts +1 -1
  115. package/constructs/Table.js +4 -4
  116. package/constructs/Topic.js +1 -1
  117. package/constructs/cdk/certificate-base.d.ts +18 -0
  118. package/constructs/cdk/certificate-base.js +26 -0
  119. package/constructs/cdk/dns-validated-certificate.d.ts +77 -0
  120. package/constructs/cdk/dns-validated-certificate.js +125 -0
  121. package/constructs/cdk/website-redirect.d.ts +53 -0
  122. package/constructs/cdk/website-redirect.js +77 -0
  123. package/constructs/deferred_task.d.ts +1 -1
  124. package/constructs/deprecated/NextjsSite.js +8 -6
  125. package/constructs/index.d.ts +0 -6
  126. package/constructs/index.js +0 -6
  127. package/constructs/util/apiGatewayV1AccessLog.d.ts +1 -1
  128. package/constructs/util/apiGatewayV2AccessLog.js +4 -4
  129. package/constructs/util/apiGatewayV2Domain.js +9 -2
  130. package/constructs/util/appSyncApiDomain.d.ts +1 -1
  131. package/constructs/util/appSyncApiDomain.js +9 -15
  132. package/constructs/util/duration.d.ts +1 -1
  133. package/constructs/util/functionBinding.js +1 -1
  134. package/constructs/util/permission.d.ts +3 -3
  135. package/constructs/util/permission.js +16 -18
  136. package/constructs/util/size.d.ts +1 -1
  137. package/constructs/util/warning.js +2 -2
  138. package/context/context.d.ts +2 -2
  139. package/context/context.js +4 -4
  140. package/context/handler.d.ts +1 -1
  141. package/credentials.d.ts +1 -1
  142. package/credentials.js +42 -6
  143. package/index.d.ts +1 -0
  144. package/index.js +1 -0
  145. package/iot.js +6 -2
  146. package/logger.js +3 -1
  147. package/node/api/index.d.ts +4 -3
  148. package/node/api/index.js +8 -2
  149. package/node/auth/adapter/adapter.d.ts +1 -1
  150. package/node/auth/adapter/facebook.js +1 -1
  151. package/node/auth/adapter/github.js +4 -4
  152. package/node/auth/adapter/google.d.ts +1 -1
  153. package/node/auth/adapter/google.js +2 -2
  154. package/node/auth/adapter/twitch.js +1 -1
  155. package/node/auth/session.d.ts +1 -1
  156. package/node/config/index.d.ts +2 -2
  157. package/node/config/index.js +3 -8
  158. package/node/job/index.d.ts +2 -2
  159. package/node/site/index.js +3 -5
  160. package/package.json +26 -21
  161. package/pothos.js +1 -0
  162. package/project.d.ts +47 -0
  163. package/{app.js → project.js} +60 -53
  164. package/runtime/handlers/dotnet.d.ts +1 -1
  165. package/runtime/handlers/dotnet.js +4 -4
  166. package/runtime/handlers/go.d.ts +1 -1
  167. package/runtime/handlers/go.js +3 -3
  168. package/runtime/handlers/java.d.ts +1 -1
  169. package/runtime/handlers/java.js +4 -4
  170. package/runtime/handlers/node.d.ts +1 -1
  171. package/runtime/handlers/node.js +60 -39
  172. package/runtime/handlers/python.d.ts +1 -1
  173. package/runtime/handlers/python.js +3 -3
  174. package/runtime/handlers.js +15 -12
  175. package/runtime/iot.js +3 -0
  176. package/runtime/runtime.d.ts +4 -0
  177. package/runtime/server.d.ts +3 -3
  178. package/runtime/server.js +11 -5
  179. package/runtime/workers.d.ts +4 -2
  180. package/runtime/workers.js +13 -3
  181. package/site-env.js +2 -1
  182. package/sst.mjs +6357 -20846
  183. package/stacks/app-metadata.d.ts +7 -0
  184. package/stacks/app-metadata.js +78 -0
  185. package/stacks/assembly.d.ts +1 -0
  186. package/stacks/assembly.js +4 -0
  187. package/stacks/build.d.ts +1 -1
  188. package/stacks/build.js +41 -48
  189. package/stacks/deploy.d.ts +1 -0
  190. package/stacks/deploy.js +128 -7
  191. package/stacks/diff.d.ts +8 -0
  192. package/stacks/diff.js +62 -0
  193. package/stacks/index.d.ts +3 -0
  194. package/stacks/index.js +3 -0
  195. package/stacks/metadata.d.ts +2 -0
  196. package/stacks/metadata.js +14 -12
  197. package/stacks/monitor.d.ts +8 -3
  198. package/stacks/monitor.js +38 -4
  199. package/stacks/remove.js +0 -4
  200. package/stacks/synth.d.ts +1 -0
  201. package/stacks/synth.js +27 -13
  202. package/support/base-site-archiver.mjs +1 -1
  203. package/support/bootstrap-metadata-function/index.mjs +68740 -0
  204. package/support/bridge/bridge.mjs +28 -28
  205. package/support/certificate-requestor/index.js +549 -0
  206. package/support/custom-resources/index.mjs +3824 -26567
  207. package/support/dotnet6-bootstrap/release/dotnet-bootstrap.deps.json +1 -1
  208. package/support/dotnet6-bootstrap/release/dotnet-bootstrap.runtimeconfig.json +1 -1
  209. package/support/edge-function/edge-lambda.mjs +2 -2
  210. package/support/job-invoker/index.mjs +26 -0
  211. package/support/nodejs-runtime/index.mjs +75 -72
  212. package/support/rds-migrator/index.mjs +22 -23
  213. package/support/remix-site-function/edge-server.js +1 -1
  214. package/support/script-function/index.mjs +30485 -0
  215. package/support/{edge-function-code-replacer → sls-nextjs-site-function-code-replacer}/lambda-code-updater.py +0 -0
  216. package/support/ssr-site-function-archiver.mjs +96 -0
  217. package/util/process.d.ts +0 -1
  218. package/watcher.js +1 -1
  219. package/app.d.ts +0 -36
  220. package/constructs/DebugApp.d.ts +0 -49
  221. package/constructs/DebugApp.js +0 -63
  222. package/constructs/DebugStack.d.ts +0 -34
  223. package/constructs/DebugStack.js +0 -132
  224. package/constructs/GraphQLApi.d.ts +0 -98
  225. package/constructs/GraphQLApi.js +0 -80
  226. package/constructs/ReactStaticSite.d.ts +0 -20
  227. package/constructs/ReactStaticSite.js +0 -54
  228. package/constructs/Script/cfn-response.d.ts +0 -19
  229. package/constructs/Script/cfn-response.js +0 -77
  230. package/constructs/Script/index.d.ts +0 -1
  231. package/constructs/Script/index.js +0 -78
  232. package/constructs/Script/outbound.d.ts +0 -10
  233. package/constructs/Script/outbound.js +0 -42
  234. package/constructs/Script/util.d.ts +0 -2
  235. package/constructs/Script/util.js +0 -11
  236. package/constructs/ViteStaticSite.d.ts +0 -32
  237. package/constructs/ViteStaticSite.js +0 -66
  238. package/support/astro-site-html-stub/index.html +0 -99
  239. package/support/base-site-archiver.cjs +0 -116
  240. package/support/nextjs-site-html-stub/index.html +0 -99
  241. package/support/remix-site-html-stub/index.html +0 -99
  242. package/support/solid-start-site-html-stub/index.html +0 -99
  243. package/support/static-site-stub/index.html +0 -90
@@ -1,14 +1,15 @@
1
1
  import fs from "fs";
2
2
  import url from "url";
3
3
  import path from "path";
4
- import { buildErrorResponsesForRedirectToIndex } from "./BaseSite.js";
5
- import { Fn, Duration, RemovalPolicy, } from "aws-cdk-lib";
4
+ import { Fn, Duration as CdkDuration, RemovalPolicy } from "aws-cdk-lib";
6
5
  import * as logs from "aws-cdk-lib/aws-logs";
7
6
  import * as lambda from "aws-cdk-lib/aws-lambda";
8
7
  import * as cloudfront from "aws-cdk-lib/aws-cloudfront";
9
8
  import * as origins from "aws-cdk-lib/aws-cloudfront-origins";
10
- import { SsrSite } from "./SsrSite.js";
9
+ import { SsrFunction } from "./SsrFunction.js";
11
10
  import { EdgeFunction } from "./EdgeFunction.js";
11
+ import { SsrSite } from "./SsrSite.js";
12
+ import { toCdkSize } from "./util/size.js";
12
13
  const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
13
14
  /**
14
15
  * The `NextjsSite` construct is a higher level CDK construct that makes it easy to create a Next.js app.
@@ -24,7 +25,7 @@ const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
24
25
  export class NextjsSite extends SsrSite {
25
26
  constructor(scope, id, props) {
26
27
  super(scope, id, {
27
- buildCommand: "npm_config_yes=true npx open-next@latest build",
28
+ buildCommand: "npx --yes open-next@latest build",
28
29
  ...props,
29
30
  });
30
31
  }
@@ -33,33 +34,68 @@ export class NextjsSite extends SsrSite {
33
34
  serverBuildOutputFile: ".open-next/server-function/index.mjs",
34
35
  clientBuildOutputDir: ".open-next/assets",
35
36
  clientBuildVersionedSubDir: "_next",
36
- siteStub: path.resolve(__dirname, "../support/nextjs-site-html-stub"),
37
37
  };
38
38
  }
39
39
  createFunctionForRegional() {
40
- const { defaults, environment } = this.props;
41
- let bundlePath, handler;
42
- if (this.isPlaceholder) {
43
- bundlePath = path.resolve(__dirname, "../support/ssr-site-function-stub");
44
- handler = "server.handler";
45
- }
46
- else {
47
- bundlePath = path.join(this.props.path, path.dirname(this.buildConfig.serverBuildOutputFile));
48
- handler = "index.handler";
49
- }
50
- return new lambda.Function(this, `ServerFunction`, {
40
+ const { timeout, memorySize, permissions, environment, cdk } = this.props;
41
+ const ssrFn = new SsrFunction(this, `ServerFunction`, {
51
42
  description: "Server handler for Next.js",
52
- handler,
43
+ bundlePath: path.join(this.props.path, ".open-next", "server-function"),
44
+ handler: "index.handler",
45
+ timeout,
46
+ memorySize,
47
+ permissions,
48
+ environment,
49
+ ...cdk?.server,
50
+ });
51
+ return ssrFn.function;
52
+ }
53
+ createImageOptimizationFunctionForRegional() {
54
+ const { imageOptimization, path: sitePath } = this.props;
55
+ return new lambda.Function(this, `ImageFunction`, {
56
+ description: "Image optimization handler for Next.js",
57
+ handler: "index.handler",
53
58
  currentVersionOptions: {
54
59
  removalPolicy: RemovalPolicy.DESTROY,
55
60
  },
56
61
  logRetention: logs.RetentionDays.THREE_DAYS,
57
- code: lambda.Code.fromAsset(bundlePath),
62
+ code: lambda.Code.fromAsset(path.join(sitePath, ".open-next/image-optimization-function")),
58
63
  runtime: lambda.Runtime.NODEJS_18_X,
59
- memorySize: defaults?.function?.memorySize || 512,
60
- timeout: Duration.seconds(defaults?.function?.timeout || 10),
64
+ memorySize: imageOptimization?.memorySize
65
+ ? typeof imageOptimization.memorySize === "string"
66
+ ? toCdkSize(imageOptimization.memorySize).toMebibytes()
67
+ : imageOptimization.memorySize
68
+ : 1536,
69
+ timeout: CdkDuration.seconds(25),
70
+ architecture: lambda.Architecture.ARM_64,
71
+ environment: {
72
+ BUCKET_NAME: this.cdk.bucket.bucketName,
73
+ },
74
+ });
75
+ }
76
+ createMiddlewareEdgeFunctionForRegional() {
77
+ const { permissions, environment, path: sitePath } = this.props;
78
+ const middlewarePath = path.resolve(sitePath, ".open-next/middleware-function");
79
+ const isMiddlewareEnabled = fs.existsSync(middlewarePath);
80
+ let bundlePath, handler;
81
+ if (isMiddlewareEnabled) {
82
+ bundlePath = middlewarePath;
83
+ handler = "index.handler";
84
+ }
85
+ else {
86
+ bundlePath = path.resolve(__dirname, "../support/ssr-site-function-stub");
87
+ handler = "server.handler";
88
+ }
89
+ const fn = new EdgeFunction(this, "Middleware", {
90
+ bundlePath,
91
+ handler,
92
+ timeout: 5,
93
+ memorySize: 128,
94
+ permissions,
61
95
  environment,
96
+ format: "esm",
62
97
  });
98
+ return { fn, isMiddlewareEnabled };
63
99
  }
64
100
  createCloudFrontDistributionForRegional() {
65
101
  const { cdk } = this.props;
@@ -76,13 +112,14 @@ export class NextjsSite extends SsrSite {
76
112
  allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,
77
113
  cachedMethods: cloudfront.CachedMethods.CACHE_GET_HEAD_OPTIONS,
78
114
  compress: true,
79
- cachePolicy: cdk?.cachePolicies?.serverRequests ??
80
- this.createCloudFrontServerCachePolicy(),
81
- edgeLambdas: isMiddlewareEnabled && !this.isPlaceholder
82
- ? [{
115
+ cachePolicy: cdk?.serverCachePolicy ?? this.createCloudFrontServerCachePolicy(),
116
+ edgeLambdas: isMiddlewareEnabled
117
+ ? [
118
+ {
83
119
  eventType: cloudfront.LambdaEdgeEventType.VIEWER_REQUEST,
84
120
  functionVersion: middlewareFn.currentVersion,
85
- }]
121
+ },
122
+ ]
86
123
  : undefined,
87
124
  };
88
125
  // Create image optimization behavior
@@ -109,9 +146,8 @@ export class NextjsSite extends SsrSite {
109
146
  };
110
147
  // Create default behavior
111
148
  // default handler for requests that don't match any other path:
112
- // - try S3 first
113
- // - if 403, fall back to lambda handler (mostly for /)
114
- // - if 404, fall back to lambda handler
149
+ // - try lambda handler first first
150
+ // - if failed, fall back to S3
115
151
  const fallbackOriginGroup = new origins.OriginGroup({
116
152
  primaryOrigin: serverBehavior.origin,
117
153
  fallbackOrigin: s3Origin,
@@ -191,22 +227,6 @@ export class NextjsSite extends SsrSite {
191
227
  },
192
228
  });
193
229
  }
194
- createCloudFrontDistributionForStub() {
195
- // Keep creating middleware edge function b/c edge function cannot be removed
196
- // immediately.
197
- this.createMiddlewareEdgeFunctionForRegional();
198
- // Create placeholder distribution
199
- return new cloudfront.Distribution(this, "Distribution", {
200
- defaultRootObject: "index.html",
201
- errorResponses: buildErrorResponsesForRedirectToIndex("index.html"),
202
- domainNames: this.buildDistributionDomainNames(),
203
- certificate: this.cdk.certificate,
204
- defaultBehavior: {
205
- origin: new origins.S3Origin(this.cdk.bucket),
206
- viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
207
- },
208
- });
209
- }
210
230
  createCloudFrontServerCachePolicy() {
211
231
  return new cloudfront.CachePolicy(this, "ServerCache", {
212
232
  queryStringBehavior: cloudfront.CacheQueryStringBehavior.all(),
@@ -216,70 +236,16 @@ export class NextjsSite extends SsrSite {
216
236
  // required by server request
217
237
  "x-op-middleware-request-headers", "x-op-middleware-response-headers", "x-nextjs-data", "x-middleware-prefetch"),
218
238
  cookieBehavior: cloudfront.CacheCookieBehavior.all(),
219
- defaultTtl: Duration.days(0),
220
- maxTtl: Duration.days(365),
221
- minTtl: Duration.days(0),
239
+ defaultTtl: CdkDuration.days(0),
240
+ maxTtl: CdkDuration.days(365),
241
+ minTtl: CdkDuration.days(0),
222
242
  enableAcceptEncodingBrotli: true,
223
243
  enableAcceptEncodingGzip: true,
224
244
  comment: "SST server response cache policy",
225
245
  });
226
246
  }
227
247
  generateBuildId() {
228
- if (this.isPlaceholder) {
229
- return "live";
230
- }
231
248
  const filePath = path.join(this.props.path, ".next/BUILD_ID");
232
249
  return fs.readFileSync(filePath).toString();
233
250
  }
234
- createImageOptimizationFunctionForRegional() {
235
- const { defaults, path: sitePath } = this.props;
236
- let bundlePath, handler;
237
- if (this.isPlaceholder) {
238
- bundlePath = path.resolve(__dirname, "../support/ssr-site-function-stub");
239
- handler = "server.handler";
240
- }
241
- else {
242
- bundlePath = path.join(sitePath, ".open-next/image-optimization-function");
243
- handler = "index.handler";
244
- }
245
- return new lambda.Function(this, `ImageFunction`, {
246
- description: "Image optimization handler for Next.js",
247
- handler,
248
- currentVersionOptions: {
249
- removalPolicy: RemovalPolicy.DESTROY,
250
- },
251
- logRetention: logs.RetentionDays.THREE_DAYS,
252
- code: lambda.Code.fromAsset(bundlePath),
253
- runtime: lambda.Runtime.NODEJS_18_X,
254
- memorySize: defaults?.function?.memorySize || 512,
255
- timeout: Duration.seconds(defaults?.function?.timeout || 10),
256
- environment: {
257
- BUCKET_NAME: this.cdk.bucket.bucketName,
258
- }
259
- });
260
- }
261
- createMiddlewareEdgeFunctionForRegional() {
262
- const { defaults, environment, path: sitePath } = this.props;
263
- const middlewarePath = path.resolve(sitePath, ".open-next/middleware-function");
264
- const isMiddlewareEnabled = fs.existsSync(middlewarePath);
265
- let bundlePath, handler;
266
- if (this.isPlaceholder || !isMiddlewareEnabled) {
267
- bundlePath = path.resolve(__dirname, "../support/ssr-site-function-stub");
268
- handler = "server.handler";
269
- }
270
- else {
271
- bundlePath = middlewarePath;
272
- handler = "index.handler";
273
- }
274
- const fn = new EdgeFunction(this, "Middleware", {
275
- bundlePath,
276
- handler,
277
- timeout: 5,
278
- memory: 128,
279
- permissions: defaults?.function?.permissions,
280
- environment,
281
- format: "esm",
282
- });
283
- return { fn, isMiddlewareEnabled };
284
- }
285
251
  }
@@ -2,7 +2,7 @@ import { Construct } from "constructs";
2
2
  import * as sqs from "aws-cdk-lib/aws-sqs";
3
3
  import * as lambdaEventSources from "aws-cdk-lib/aws-lambda-event-sources";
4
4
  import { getFunctionRef, isCDKConstruct } from "./Construct.js";
5
- import { Function as Fn } from "./Function.js";
5
+ import { Function as Fn, } from "./Function.js";
6
6
  import { toCdkDuration } from "./util/duration.js";
7
7
  /////////////////////
8
8
  // Construct
@@ -105,7 +105,7 @@ export class Queue extends Construct {
105
105
  const fn = Fn.fromDefinition(scope, `Consumer_${this.node.id}`, functionDefinition);
106
106
  fn.addEventSource(new lambdaEventSources.SqsEventSource(this.cdk.queue, eventSourceProps));
107
107
  // Attach permissions
108
- this.permissionsAttachedForAllConsumers.forEach(permissions => {
108
+ this.permissionsAttachedForAllConsumers.forEach((permissions) => {
109
109
  fn.attachPermissions(permissions);
110
110
  });
111
111
  fn.bind(this.bindingForAllConsumers);
@@ -151,8 +151,8 @@ export class Queue extends Construct {
151
151
  data: {
152
152
  name: this.cdk.queue.queueName,
153
153
  url: this.cdk.queue.queueUrl,
154
- consumer: getFunctionRef(this.consumerFunction)
155
- }
154
+ consumer: getFunctionRef(this.consumerFunction),
155
+ },
156
156
  };
157
157
  }
158
158
  /** @internal */
@@ -162,12 +162,12 @@ export class Queue extends Construct {
162
162
  variables: {
163
163
  queueUrl: {
164
164
  environment: this.queueUrl,
165
- parameter: this.queueUrl
166
- }
165
+ parameter: this.queueUrl,
166
+ },
167
167
  },
168
168
  permissions: {
169
- "sqs:*": [this.queueArn]
170
- }
169
+ "sqs:*": [this.queueArn],
170
+ },
171
171
  };
172
172
  }
173
173
  createQueue() {
@@ -191,7 +191,7 @@ export class Queue extends Construct {
191
191
  // TODO
192
192
  console.log(toCdkDuration("900 seconds"));
193
193
  debugOverrideProps = {
194
- visibilityTimeout: toCdkDuration("900 seconds")
194
+ visibilityTimeout: toCdkDuration("900 seconds"),
195
195
  };
196
196
  }
197
197
  }
@@ -199,7 +199,7 @@ export class Queue extends Construct {
199
199
  this.cdk.queue = new sqs.Queue(this, "Queue", {
200
200
  queueName: name,
201
201
  ...sqsQueueProps,
202
- ...debugOverrideProps
202
+ ...debugOverrideProps,
203
203
  });
204
204
  }
205
205
  }
@@ -134,7 +134,7 @@ export interface RDSProps {
134
134
  secret?: secretsManager.ISecret;
135
135
  };
136
136
  }
137
- export declare type RDSEngineType = RDSProps["engine"];
137
+ export type RDSEngineType = RDSProps["engine"];
138
138
  export interface RDSCdkServerlessClusterProps extends Omit<rds.ServerlessClusterProps, "vpc" | "engine" | "defaultDatabaseName" | "scaling"> {
139
139
  vpc?: ec2.IVpc;
140
140
  }
package/constructs/RDS.js CHANGED
@@ -294,7 +294,7 @@ export class RDS extends Construct {
294
294
  const app = this.node.root;
295
295
  // Create custom resource handler
296
296
  const handler = new lambda.Function(this, "MigrationHandler", {
297
- code: lambda.Code.fromAsset(path.join(__dirname, "Script")),
297
+ code: lambda.Code.fromAsset(path.join(__dirname, "../support/script-function")),
298
298
  runtime: lambda.Runtime.NODEJS_16_X,
299
299
  handler: "index.handler",
300
300
  timeout: cdk.Duration.minutes(15),
@@ -19,10 +19,8 @@ export declare class RemixSite extends SsrSite {
19
19
  serverBuildOutputFile: string;
20
20
  clientBuildOutputDir: string;
21
21
  clientBuildVersionedSubDir: string;
22
- siteStub: string;
23
22
  };
24
23
  private createServerLambdaBundle;
25
- private createServerLambdaBundleWithStub;
26
24
  protected createFunctionForRegional(): lambda.Function;
27
25
  protected createFunctionForEdge(): EdgeFunction;
28
26
  }
@@ -4,12 +4,15 @@ import path from "path";
4
4
  import * as esbuild from "esbuild";
5
5
  import { createRequire } from "module";
6
6
  const require = createRequire(import.meta.url);
7
- import { Duration, RemovalPolicy } from "aws-cdk-lib";
7
+ import { Duration as CdkDuration, RemovalPolicy } from "aws-cdk-lib";
8
8
  import * as logs from "aws-cdk-lib/aws-logs";
9
9
  import * as lambda from "aws-cdk-lib/aws-lambda";
10
10
  import { Logger } from "../logger.js";
11
11
  import { SsrSite } from "./SsrSite.js";
12
+ import { useProject } from "../project.js";
12
13
  import { EdgeFunction } from "./EdgeFunction.js";
14
+ import { toCdkSize } from "./util/size.js";
15
+ import { toCdkDuration } from "./util/duration.js";
13
16
  const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
14
17
  /**
15
18
  * The `RemixSite` construct is a higher level CDK construct that makes it easy to create a Remix app.
@@ -55,7 +58,6 @@ export class RemixSite extends SsrSite {
55
58
  serverBuildOutputFile: "build/index.js",
56
59
  clientBuildOutputDir: "public",
57
60
  clientBuildVersionedSubDir: "build",
58
- siteStub: path.resolve(__dirname, "../support/remix-site-html-stub"),
59
61
  };
60
62
  }
61
63
  createServerLambdaBundle(wrapperFile) {
@@ -84,7 +86,7 @@ export class RemixSite extends SsrSite {
84
86
  Logger.debug(`Bundling server`);
85
87
  // Create a directory that we will use to create the bundled version
86
88
  // of the "core server build" along with our custom Lamba server handler.
87
- const outputPath = path.resolve(path.join(this.sstBuildDir, `RemixSiteFunction-${this.node.id}-${this.node.addr}`));
89
+ const outputPath = path.resolve(path.join(useProject().paths.artifacts, `RemixSiteFunction-${this.node.id}-${this.node.addr}`));
88
90
  // Copy the Remix polyfil to the server build directory
89
91
  const polyfillSource = path.resolve(__dirname, "../support/remix-site-function/polyfill.js");
90
92
  const polyfillDest = path.join(this.props.path, "build/polyfill.js");
@@ -109,15 +111,9 @@ export class RemixSite extends SsrSite {
109
111
  }
110
112
  return outputPath;
111
113
  }
112
- createServerLambdaBundleWithStub() {
113
- // Use existing stub bundle in assets
114
- return path.resolve(__dirname, "../support/ssr-site-function-stub");
115
- }
116
114
  createFunctionForRegional() {
117
- const { defaults, environment } = this.props;
118
- const bundlePath = this.isPlaceholder
119
- ? this.createServerLambdaBundleWithStub()
120
- : this.createServerLambdaBundle("regional-server.js");
115
+ const { timeout, memorySize, environment, cdk } = this.props;
116
+ const bundlePath = this.createServerLambdaBundle("regional-server.js");
121
117
  return new lambda.Function(this, `ServerFunction`, {
122
118
  description: "Server handler for Remix",
123
119
  handler: "server.handler",
@@ -127,23 +123,27 @@ export class RemixSite extends SsrSite {
127
123
  logRetention: logs.RetentionDays.THREE_DAYS,
128
124
  code: lambda.Code.fromAsset(bundlePath),
129
125
  runtime: lambda.Runtime.NODEJS_16_X,
130
- memorySize: defaults?.function?.memorySize || 512,
131
- timeout: Duration.seconds(defaults?.function?.timeout || 10),
126
+ memorySize: typeof memorySize === "string"
127
+ ? toCdkSize(memorySize).toMebibytes()
128
+ : memorySize,
129
+ timeout: typeof timeout === "string"
130
+ ? toCdkDuration(timeout)
131
+ : CdkDuration.seconds(timeout),
132
132
  environment,
133
+ ...cdk?.server,
133
134
  });
134
135
  }
135
136
  createFunctionForEdge() {
136
- const { defaults, environment } = this.props;
137
- const bundlePath = this.isPlaceholder
138
- ? this.createServerLambdaBundleWithStub()
139
- : this.createServerLambdaBundle("edge-server.js");
137
+ const { timeout, memorySize, permissions, environment } = this.props;
138
+ const bundlePath = this.createServerLambdaBundle("edge-server.js");
140
139
  return new EdgeFunction(this, `Server`, {
141
140
  scopeOverride: this,
141
+ format: "cjs",
142
142
  bundlePath,
143
143
  handler: "server.handler",
144
- timeout: defaults?.function?.timeout,
145
- memory: defaults?.function?.memorySize,
146
- permissions: defaults?.function?.permissions,
144
+ timeout,
145
+ memorySize,
146
+ permissions,
147
147
  environment,
148
148
  });
149
149
  }
@@ -113,7 +113,7 @@ export class Script extends Construct {
113
113
  }
114
114
  createCustomResourceFunction() {
115
115
  const handler = new lambda.Function(this, "ScriptHandler", {
116
- code: lambda.Code.fromAsset(path.join(__dirname, "Script")),
116
+ code: lambda.Code.fromAsset(path.join(__dirname, "../support/script-function")),
117
117
  runtime: lambda.Runtime.NODEJS_16_X,
118
118
  handler: "index.handler",
119
119
  timeout: cdk.Duration.minutes(15),
@@ -1,5 +1,6 @@
1
1
  import { Construct } from "constructs";
2
- import { ENVIRONMENT_PLACEHOLDER, getParameterPath, getParameterFallbackPath } from "./util/functionBinding.js";
2
+ import { Stack } from "./Stack.js";
3
+ import { ENVIRONMENT_PLACEHOLDER, getParameterPath, getParameterFallbackPath, } from "./util/functionBinding.js";
3
4
  /**
4
5
  * The `Secret` construct is a higher level CDK construct that makes it easy to manage app secrets.
5
6
  *
@@ -32,6 +33,7 @@ export class Secret extends Construct {
32
33
  /** @internal */
33
34
  getFunctionBinding() {
34
35
  const app = this.node.root;
36
+ const partition = Stack.of(this).partition;
35
37
  return {
36
38
  clientPackage: "config",
37
39
  variables: {
@@ -43,8 +45,8 @@ export class Secret extends Construct {
43
45
  },
44
46
  permissions: {
45
47
  "ssm:GetParameters": [
46
- `arn:aws:ssm:${app.region}:${app.account}:parameter${getParameterPath(this, "value")}`,
47
- `arn:aws:ssm:${app.region}:${app.account}:parameter${getParameterFallbackPath(this, "value")}`
48
+ `arn:${partition}:ssm:${app.region}:${app.account}:parameter${getParameterPath(this, "value")}`,
49
+ `arn:${partition}:ssm:${app.region}:${app.account}:parameter${getParameterFallbackPath(this, "value")}`,
48
50
  ],
49
51
  },
50
52
  };
@@ -1,4 +1,4 @@
1
- import * as lambda from "aws-cdk-lib/aws-lambda";
1
+ import { Function as CdkFunction } from "aws-cdk-lib/aws-lambda";
2
2
  import { SsrSite } from "./SsrSite.js";
3
3
  import { EdgeFunction } from "./EdgeFunction.js";
4
4
  /**
@@ -17,8 +17,7 @@ export declare class SolidStartSite extends SsrSite {
17
17
  serverBuildOutputFile: string;
18
18
  clientBuildOutputDir: string;
19
19
  clientBuildVersionedSubDir: string;
20
- siteStub: string;
21
20
  };
22
- protected createFunctionForRegional(): lambda.Function;
21
+ protected createFunctionForRegional(): CdkFunction;
23
22
  protected createFunctionForEdge(): EdgeFunction;
24
23
  }
@@ -1,11 +1,11 @@
1
1
  import fs from "fs";
2
- import url from "url";
3
2
  import path from "path";
4
- import * as esbuild from "esbuild";
3
+ import { buildSync } from "esbuild";
4
+ import { Architecture } from "aws-cdk-lib/aws-lambda";
5
5
  import { SsrSite } from "./SsrSite.js";
6
6
  import { Function } from "./Function.js";
7
+ import { useProject } from "../project.js";
7
8
  import { EdgeFunction } from "./EdgeFunction.js";
8
- const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
9
9
  /**
10
10
  * The `SolidStartSite` construct is a higher level CDK construct that makes it easy to create a SolidStart app.
11
11
  * @example
@@ -23,79 +23,69 @@ export class SolidStartSite extends SsrSite {
23
23
  serverBuildOutputFile: "dist/server/index.mjs",
24
24
  clientBuildOutputDir: "dist/client",
25
25
  clientBuildVersionedSubDir: "assets",
26
- siteStub: path.resolve(__dirname, "../support/solid-start-site-html-stub"),
27
26
  };
28
27
  }
29
28
  createFunctionForRegional() {
30
- const { defaults, environment } = this.props;
29
+ const { timeout, memorySize, environment, cdk } = this.props;
31
30
  // Bundle code
32
- const handler = this.isPlaceholder
33
- ? path.resolve(__dirname, "../support/ssr-site-function-stub/index.handler")
34
- : path.join(this.props.path, "dist", "server", "index.handler");
31
+ const handler = path.join(this.props.path, "dist", "server", "index.handler");
35
32
  // Create function
36
33
  const fn = new Function(this, `ServerFunction`, {
37
34
  description: "Server handler",
38
35
  handler,
39
36
  logRetention: "three_days",
40
37
  runtime: "nodejs16.x",
41
- memorySize: defaults?.function?.memorySize || "512 MB",
42
- timeout: defaults?.function?.timeout || "10 seconds",
38
+ memorySize,
39
+ timeout,
43
40
  nodejs: {
44
41
  format: "esm",
45
42
  },
46
- enableLiveDev: false,
47
43
  environment,
44
+ ...cdk?.server,
45
+ architecture: cdk?.server?.architecture === Architecture.ARM_64 ? "arm_64" : "x86_64",
48
46
  });
49
47
  fn._disableBind = true;
50
48
  return fn;
51
49
  }
52
50
  createFunctionForEdge() {
53
- const { defaults, environment } = this.props;
51
+ const { timeout, memorySize, permissions, environment } = this.props;
52
+ // Create a directory that we will use to create the bundled version
53
+ // of the "core server build" along with our custom Lamba server handler.
54
+ const outputPath = path.resolve(path.join(useProject().paths.artifacts, `SolidStartSiteFunction-${this.node.id}-${this.node.addr}`));
54
55
  // Bundle code
55
- let bundlePath;
56
- let handler;
57
- if (this.isPlaceholder) {
58
- bundlePath = path.resolve(__dirname, "../support/ssr-site-function-stub");
59
- handler = "index.handler";
60
- }
61
- else {
62
- // Create a directory that we will use to create the bundled version
63
- // of the "core server build" along with our custom Lamba server handler.
64
- const outputPath = path.resolve(path.join(this.sstBuildDir, `SolidStartSiteFunction-${this.node.id}-${this.node.addr}`));
65
- const result = esbuild.buildSync({
66
- entryPoints: [path.join(this.props.path, this.buildConfig.serverBuildOutputFile)],
67
- target: "esnext",
68
- format: "esm",
69
- platform: "node",
70
- metafile: true,
71
- bundle: true,
72
- write: true,
73
- allowOverwrite: true,
74
- outfile: path.join(outputPath, "server.mjs"),
75
- banner: {
76
- js: [
77
- `import { createRequire as topLevelCreateRequire } from 'module';`,
78
- `const require = topLevelCreateRequire(import.meta.url);`,
79
- ].join(""),
80
- },
81
- });
82
- if (result.errors.length > 0) {
83
- result.errors.forEach((error) => console.error(error));
84
- throw new Error(`There was a problem bundling the function code for the ${this.id} SolidStartSite.`);
85
- }
86
- // Create package.json
87
- fs.writeFileSync(path.join(outputPath, "package.json"), `{"type":"module"}`);
88
- bundlePath = outputPath;
89
- handler = "server.handler";
56
+ const result = buildSync({
57
+ entryPoints: [
58
+ path.join(this.props.path, this.buildConfig.serverBuildOutputFile),
59
+ ],
60
+ target: "esnext",
61
+ format: "esm",
62
+ platform: "node",
63
+ metafile: true,
64
+ bundle: true,
65
+ write: true,
66
+ allowOverwrite: true,
67
+ outfile: path.join(outputPath, "server.mjs"),
68
+ banner: {
69
+ js: [
70
+ `import { createRequire as topLevelCreateRequire } from 'module';`,
71
+ `const require = topLevelCreateRequire(import.meta.url);`,
72
+ ].join(""),
73
+ },
74
+ });
75
+ if (result.errors.length > 0) {
76
+ result.errors.forEach((error) => console.error(error));
77
+ throw new Error(`There was a problem bundling the function code for the ${this.id} SolidStartSite.`);
90
78
  }
79
+ // Create package.json
80
+ fs.writeFileSync(path.join(outputPath, "package.json"), `{"type":"module"}`);
91
81
  // Create function
92
82
  return new EdgeFunction(this, `Server`, {
93
83
  scopeOverride: this,
94
- bundlePath,
95
- handler,
96
- timeout: defaults?.function?.timeout,
97
- memory: defaults?.function?.memorySize,
98
- permissions: defaults?.function?.permissions,
84
+ bundlePath: outputPath,
85
+ handler: "server.handler",
86
+ timeout,
87
+ memorySize,
88
+ permissions,
99
89
  environment,
100
90
  format: "esm",
101
91
  });
@@ -0,0 +1,22 @@
1
+ import { Construct } from "constructs";
2
+ import * as lambda from "aws-cdk-lib/aws-lambda";
3
+ import { Permissions } from "./util/permission.js";
4
+ import { Size } from "./util/size.js";
5
+ import { Duration } from "./util/duration.js";
6
+ import { FunctionOptions } from "aws-cdk-lib/aws-lambda";
7
+ export interface SsrFunctionProps extends Omit<FunctionOptions, "memorySize" | "timeout" | "runtime"> {
8
+ bundlePath: string;
9
+ handler: string;
10
+ timeout: number | Duration;
11
+ memorySize: number | Size;
12
+ permissions?: Permissions;
13
+ }
14
+ export declare class SsrFunction extends Construct {
15
+ function: lambda.Function;
16
+ private props;
17
+ constructor(scope: Construct, id: string, props: SsrFunctionProps);
18
+ attachPermissions(permissions: Permissions): void;
19
+ private createFunction;
20
+ private createLambdaCodeReplacer;
21
+ private getLambdaContentReplaceValues;
22
+ }