During the implementation of my CDK Stack, I encountered an issue when creating a Bucket, uploading files to it, and then creating a CodeCommit repository to store those files. Everything was going smoothly until I tried to create a new codecommit.CfnRepository and received the following error:
CREATE_FAILED | AWS::CodeCommit::Repository | CfnRepository
Not Found (Service: Amazon S3; Status Code: 404; Error Code: 404 Not Found;
Request ID: 2608A90CD11E9729; S3 Extended Request ID: 1iVrjbDpcwqSrsNc7s/aF
9UpNMg0DGe9ABTAJMuoRkA3f9qSYMqVN0sWeLRdT6ETck/DRx6dDCM=)
I found that splitting the s3 creation/deployment and Repository creation into two separate stacks resolved the issue, but if they are in one constructor, the CDK deployment fails.
Below is the code snippet that I am using:
export class CdkBeeStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, name: string, props?: cdk.StackProps) {
super(scope, id, props);
const myBucket = new s3.Bucket(this, 'Bucket', {
bucketName: name,
removalPolicy: cdk.RemovalPolicy.DESTROY,
});
new s3deploy.BucketDeployment(this, 'DeployFiles', {
sources: [s3deploy.Source.asset('./lib/Files.zip')],
destinationBucket: myBucket
});
new codecommit.CfnRepository(this, 'CfnRepository' , {
repositoryName: 'MyFetucinyName',
code: {
s3: {
bucket: name,
key: 'Files/SourceCode.zip'
}
}
});
}
}
If anyone has any ideas on how to make this work, I would greatly appreciate it.