Init CodeCommit库,使用CDK将种子代码存储在S3中



我正在尝试将模型构建,培训和部署的MLOps模板CloudFormation模板转换为CDK项目,以便我可以轻松地更新定义,合成模板并将其上传到CloudCatalog,以便在SageMaker Studio中用作项目模板。

我对CDK很陌生,但是我在尝试初始化CodeCommit存储库时遇到了一些麻烦,其中包含存储在S3中的sagemaker管道seed-code,这是在原始模板中完成的:

'ModelBuildCodeCommitRepository':
'Type': 'AWS::CodeCommit::Repository'
'Properties':
'RepositoryName':
'Fn::Sub': 'sagemaker-${SageMakerProjectName}-${SageMakerProjectId}-modelbuild'
'RepositoryDescription':
'Fn::Sub': 'SageMaker Model building workflow infrastructure as code for the
Project ${SageMakerProjectName}'
'Code':
'S3':
'Bucket': 'sagemaker-servicecatalog-seedcode-sa-east-1'
'Key': 'toolchain/model-building-workflow-v1.0.zip'
'BranchName': 'main'

CDK API文档在代码提交中确实引用了code参数。存储库作为初始化选项,但它只适用于压缩本地文件并将其上传到S3等。这是因为它假设部署了CDK项目,但我只想要由cdk synth生成的模板。

当然,我总是可以使用代码提交。CfnRepository及其code参数指向S3,但随后我无法将其插入codepipeline的阶段codepipeline_actions。CodeCommitSourceAction的repository参数,因为它期望一个IRepository对象。

我也想坚持aws-cdk-lib.aws_codepipeline来掌握CloudPipeline的基本逻辑(我也是很新的),避免使用高级aws-cdk-lib.pipelines

我该怎么做呢?

构建一个没有Code道具的Repository。获取其L1CfnRepository层的逃生舱口引用。手动将CfnRepository的属性设置为现有的S3桶:

const repo = new codecommit.Repository(this, 'Repo', { repositoryName: 'my-great-repo' });
const cfnRepo = repo.node.defaultChild as codecommit.CfnRepository;
cfnRepo.addPropertyOverride('Code', {
S3: {
Bucket: 'sagemaker-servicecatalog-seedcode-sa-east-1',
Key: 'toolchain/model-building-workflow-v1.0.zip',
},
BranchName: 'main',
});

上面的代码将在op中合成YAML输出。传递repo作为管道的源操作。

不要忘记在S3桶上授予必要的IAM权限。

最新更新