a little bit new to typescript and cdk.
In order to use an S3 bucket from one stack in another, I'm trying to specify it in one stack. The two stacks are in separate folders. how to use the bucket pipelined s3 bucket for ts. That bucket.
I need a solution that clarifies the idea so I can use it with other stacks as well.
bucket.ts
import * as cdk from 'aws-cdk-lib';
import * as s3 from 'aws-cdk-lib/aws-s3';
import { Construct } from 'constructs';
export class PipelineSourceBucket extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const sourceBucket = new s3.Bucket(this, 'pipelineSourceBucket', {
versioned: true, // a Bucket used as a source in CodePipeline must be versioned
});
}
}
pipeline.ts
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as codepipeline from 'aws-cdk-lib/aws-codepipeline';
import * as codepipeline_actions from 'aws-cdk-lib/aws-codepipeline-actions';
export class PipelineStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const pipeline = new codepipeline.Pipeline(this, 'CodePipeline', {
pipelineName: 'jatin-ci-cd',
crossAccountKeys: false, // not required as it wont be cross account deployment
})
const sourceAction = new codepipeline_actions.S3SourceAction({
actionName: 'S3Source',
bucket: sourceBucket, //how to access the bucket from other stack?
bucketKey: 'path/to/file.zip',
output: sourceOutput,
});
}
}