Please expose Distribution in sst/constructs
iliazlobin opened this issue · comments
When trying to import and use Distribution constructs:
import { Bucket, Distribution, StackContext, Table } from 'sst/constructs'
It's complaining that Distribution isn't available, despite having this construct exported in source code...
Problem is index.d.ts, index.js do not include Distribution module and as such, a consumer code can't use it
Workaround, use pnpm patch or patch-package to slightly modify the sts package. Eg:
diff --git a/constructs/index.d.ts b/constructs/index.d.ts
index fc4a47f61b678e41885284164be183fc6271bb90..190a543219b23c6bd3e14255ed685d5ebe58a6a5 100644
--- a/constructs/index.d.ts
+++ b/constructs/index.d.ts
@@ -11,6 +11,7 @@ export * from "./Stack.js";
export * from "./Table.js";
export * from "./Topic.js";
export * from "./Bucket.js";
+export * from "./Distribution.js";
export * from "./Script.js";
export * from "./Service.js";
export * from "./EventBus.js";
diff --git a/constructs/index.js b/constructs/index.js
index c25058cf32bad913e241f502f7fd4782ad1018d5..2b2fe2763d3537cfcdeba882c6ed3cf21e108939 100644
--- a/constructs/index.js
+++ b/constructs/index.js
@@ -11,6 +11,7 @@ export * from "./Stack.js";
export * from "./Table.js";
export * from "./Topic.js";
export * from "./Bucket.js";
+export * from "./Distribution.js";
export * from "./Script.js";
export * from "./Service.js";
export * from "./EventBus.js";
Author, please export/expose this object for usage out of 'sst/constructs', find it necessary.
Thank you so much!
Hmm it's an internal construct. Is there a reason you want to use it?
Yes, sure, there's quite a reason to use it, and I don't see a reason not to, cause everything is well-put and ready to be used for the only exception being not exposed, which you can fix with a simple patch (tested).
I want to use SST Distribution to create a CloudFront distribution and couple it up with a S3 bucket while having other things (like ACM cert) to be taken care of for me. I considered that for image hosting, or other static assets off of alternative origin relative to a website (not necessarily for a fully-fledged static website though, which I know there's another construct exists for)
The simplest pattern I've come up is this:
import { Bucket, Distribution, StackContext, use } from 'sst/constructs'
export function DataStack({ stack }: StackContext) {
const notionBucket = new Bucket(stack, 'NotionBucket')
const distribution = new Distribution(stack, 'NotionDistribution', {
customDomain: staticDomain.value,
cdk: {
distribution: {
comment: 'Static assets for a website',
defaultBehavior: {
// viewerProtocolPolicy: ViewerProtocolPolicy.HTTPS_ONLY,
// allowedMethods: AllowedMethods.ALLOW_ALL,
origin: new S3Origin(notionBucket.cdk.bucket),
},
},
},
})
...
Though, requires a bit of patching to work. But I hate patching, let's do it properly with author's confirmation
Yes +1 I would use this.