s3 Bucket referenced by CodeBuild/CodePipeline project is not created in time.
const bucket =
s3.BaseS3Bucket.fromBucketName(
this,
"fromBucketName",
props.bucket_name
) ||
new s3.BaseS3Bucket(this, "cdkBucket", {
bucketName: props.bucket_name,
});
const cdkCodePipeline = new codepipeline.Pipeline(this, "cdkCodePipeline", {
role: cdkPipelineRole,
pipelineName: props.pipeline_name,
artifactBucket: bucket,
So bucket is not created in a sequence it is introduced in construct. In case with IAM Roles which are referenced in Pipeline project, they are created before pipeline as dependencies , but bucket fails. How can I make Pipeline to wait for bucket to be created. Do constructs have any dependencies, or it was deprecated? What is the solution in this case?
###ERROR
An error occurred while validating the artifact bucket 'bucket_name': No bucket with the name bucket_name was found.
Environment
- CLI Version : 1.41.0
- Framework Version:
- OS : MacOS
- Language : TypeScript
Other
This is :bug: Bug Report
Thanks for opening the issue @CONJAUMCGCG , but I think the code you posted is not doing what you think it does.
s3.Bucket.fromBucketName() (not s3. BaseS3Bucket.fromBucketName()) never returns undefined (as its type shows), so what you're doing is referencing an existing bucket that probably doesn't exist. Hence the error you see during deployment.
What you want instead is:
const bucket = new s3.Bucket(this, 'PipelineBucket', {
bucketName: props.bucket_name,
});
const pipeline = new codepipeline.Pipeline(this, 'Pipeline', {
// ...
artifactBucket: bucket,
});
Thanks, Adam
@skinny85 Thank you for your respond. But how can I check if resource exist or not before creation?in this case bucket. Because it will fail if resource already exists
There is no way to do that.
The CDK assumes everything you need to create your infrastructure is mastered in your source code. Checking whether something exists or not, and changing your infrastructure depending on that, is directly against this philosophy (not to mention it would also require you to have AWS credentials present every time you do a build of your code, which is not desirable).
@skinny85 Thank you. Closing the issue
You're welcome @CONJAUMCGCG