amazon-s3 - 使用 CDK 使用存储在 S3 中的种子代码初始化 CodeCommit 存储库

我正在尝试将用于模型构建、训练和部署的 https://docs.aws.amazon.com/sagemaker/latest/dg/sagemaker-projects-templates-sm.html#sagemaker-projects-templates-code-commit CloudFormation 模板转换为 CDK 项目,以便我可以轻松更新定义、合成模板并将其上传到 CloudCatalog 中,以便在 SageMaker Studio 中用作项目模板。

不过,我对 CDK 还是很陌生,尝试使用存储在 S3 中的 sagemaker pipeline seed-code 初始化 CodeCommit 存储库时遇到了一些麻烦,这在原始模板中完成如下:

'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 文档确实将 https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_codecommit.Repository.html#code 中的 code 参数作为初始化选项,但它仅适用于本地文件被压缩并上传到 S3 等。那是因为它假设部署了 CDK 项目,但我只想要 cdk synth 生成的模板。

当然,我总是可以使用 https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_codecommit.CfnRepository.html#code 及其 code 参数指向 S3,但是我无法将其插入 codepipeline 的阶段 https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_codepipeline_actions.CodeCommitSourceAction.htmlrepository 参数,因为它需要一个 IRepository 对象。

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

关于如何做到这一点的任何想法?

回答1

构造一个没有 Code prop 的 Repository。获取对其 L1 CfnRepository 层的 https://docs.aws.amazon.com/cdk/v2/guide/cfn_layer.html 引用。将 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 作为 pipeline 的源操作传递。

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

相似文章

随机推荐

最新文章