CDK How to use import s3 defined in one stack to another stack In different file

0 votes

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,
    });
  }
}

Dec 13, 2022 in AWS by Ashwini
• 5,430 points
544 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In AWS

0 votes
2 answers

How to skip headers when reading a CSV file in S3 and creating a table in AWS Athena?

Thanks for the answer. This should be clear ...READ MORE

answered Aug 14, 2019 in AWS by athenauserz
11,234 views
0 votes
1 answer

How to download the latest file in a S3 bucket using AWS CLI?

You can use the below command $ aws ...READ MORE

answered Sep 6, 2018 in AWS by Archana
• 4,170 points
19,037 views
+1 vote
2 answers

How to read a csv file stored in Amazon S3 using csv.DictReader

The code would be something like this: import ...READ MORE

answered Oct 25, 2018 in AWS by Archana
• 5,640 points
53,624 views
0 votes
1 answer

AWS S3 uploading hidden files by default

versioning is enabled in your bucket. docs.aws.amazon.com/AmazonS3/latest/user-guide/….... the ...READ MORE

answered Oct 4, 2018 in AWS by Priyaj
• 58,090 points
5,439 views
–1 vote
1 answer

How to decrypt the encrypted S3 file using aws-encryption-cli --decrypt

Use command : aws s3 presign s3://mybucket/abc_count.png you get ...READ MORE

answered Oct 22, 2018 in AWS by Priyaj
• 58,090 points
4,858 views
0 votes
1 answer

Import my AWS credentials using python script

Using AWS Cli  Configure your IAM user then ...READ MORE

answered Nov 16, 2018 in AWS by Jino
• 5,810 points
2,588 views
0 votes
2 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP