Pavan Kumar
11/10/2021, 3:30 PMstackA.js
this.bucket = new s3.Bucket(this, "MyBucket");
And in stackB.js
// stackA's bucket is passed to stackB
const { bucket } = this.props;
// SST will implicitly set the exports in stackA
// and imports in stackB
bucket.bucketArn;
Is the bucket
props passed automatically to stackB? Don't we have to do something like following?
const stackA = new StackA(app, 'stack-a');
new StackB(app, 'stack-b', { bucket: stackA.bucket });
arda
11/10/2021, 3:40 PMPavan Kumar
11/10/2021, 5:04 PMnew StackB(app, 'stack-b', { bucket: stackA.bucket });
Argument of type '{ bucket: string; }' is not assignable to parameter of type 'StackProps'.
Frank
StackProps
like this:
interface StackBProps extends StackProps {
readonly bucket: sst.Bucket;
}
You an find an example here of sharing an sst.Api
across stack, but the idea is the same for sharing an sst.Table
.Frank
new StackB(app, 'stack-b', stackA.bucket);
And update `StackB`’s constructor to be:
constructor(scope: App, id: string, bucket: sst.Bucket, props?: StackProps)
This way, you don’t need to create the new interface.Frank
Pavan Kumar
11/11/2021, 3:12 AMconstructor(scope: App, id: string, bucket: sst.Bucket, props?: StackProps)
Pavan Kumar
11/11/2021, 3:13 AMprops?: StackProps
if it is usually something we pass.
Dose it has some other purpose?arda
11/11/2021, 1:33 PMthdxr
11/11/2021, 1:43 PMthdxr
11/11/2021, 1:43 PMPavan Kumar
11/12/2021, 4:51 AMStackProps
May be something like this.
interface GenericProps {
[key: string]: any;
}
type NewStackProps = StackProps && GenericProps
Then the Stack constructer would have following signature.
new Stack(scope: Construct, id: string, props: NewStackProps)
thdxr
11/12/2021, 4:57 AM