微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何将现有 CodePipeline 导出到 CloudFormation 模板

如何解决如何将现有 CodePipeline 导出到 CloudFormation 模板

这更像是我缺乏理解,但我似乎无法调试它。 我创建了一个运行 terraform apply 的代码管道(它在内部为我创建了 aws 基础设施)。代码管道似乎正在运行。

我需要为另一个帐户实现相同的代码管道,我该怎么做。

我尝试使用以下命令获取 json 脚本。 aws codepipeline get-pipeline --name

我将 json 脚本转换为 yaml 脚本。

当我尝试在另一个帐户上运行 yaml 脚本时,出现以下错误

Template format error: At least one Resources member must be defined.

问题: 1.) 我可以将代码管道导出到 cloudformation 模板的最佳方式 2.) 我用的方法不行,怎么解决

{
    "pipeline": {
        "name": "my-code-pipeline","roleArn": "arn:aws:iam::aws-account-id:role/service-role/AWSCodePipelineserviceRole-aws-region-my-code-pipeline","artifactStore": {
            "type": "S3","location": "codepipeline-aws-region-45856771421"
        },"stages": [
            {
                "name": "Source","actions": [
                    {
                        "name": "Source","actionTypeId": {
                            "category": "Source","owner": "ThirdParty","provider": "GitHub","version": "1"
                        },"runorder": 1,"configuration": {
                            "Branch": "master","OAuthToken": "****","Owner": "github-account-name","PollForSourceChanges": "false","Repo": "repo-name"
                        },"outputArtifacts": [
                            {
                                "name": "SourceArtifact"
                            }
                        ],"inputArtifacts": [],"region": "aws-region","namespace": "SourceVariables"
                    }
                ]
            },{
                "name": "codebuild-for-terraform-init-and-plan","actions": [
                    {
                        "name": "codebuild-for-terraform-init","actionTypeId": {
                            "category": "Build","owner": "AWS","provider": "CodeBuild","configuration": {
                            "ProjectName": "my-code-pipeline-build-stage"
                        },"outputArtifacts": [],"inputArtifacts": [
                            {
                                "name": "SourceArtifact"
                            }
                        ],"region": "aws-region"
                    }
                ]
            },{
                "name": "manual-approve","actions": [
                    {
                        "name": "approval","actionTypeId": {
                            "category": "Approval","provider": "Manual","configuration": {
                            "NotificationArn": "arn:aws:sns:aws-region:aws-account-id:Email-Service"
                        },{
                "name": "codebuild-for-terraform-apply","actions": [
                    {
                        "name": "codebuild-for-terraform-apply","configuration": {
                            "ProjectName": "codebuild-project-for-apply"
                        },"region": "aws-region"
                    }
                ]
            }
        ],"version": 11
    },"Metadata": {
        "pipelineArn": "arn:aws:codepipeline:aws-region:aws-account-id:my-code-pipeline","created": "2020-09-17T13:12:50.085000+05:30","updated": "2020-09-21T15:46:19.613000+05:30"
    }
}

给定的代码是我用来创建 cloudformation 模板的 yaml 模板。

解决方法

aws codepipeline get-pipeline --name CLI 命令返回有关管道结构和管道元数据的信息,但它与 CloudFormation 模板(或其资源部分)的格式不同。

没有内置支持导出现有 AWS 资源以创建 CloudFormation 模板,但您有多种选择。

  1. 使用 former2(由 AWS Hero,Ian Mckay 构建和维护)根据您选择的资源生成 CloudFormation 模板。
  2. 从您使用的 aws codepipeline get-pipeline --name 命令中获取 JSON 输出并手动制作 CloudFormation 模板。管道将是 the full template 中资源列表中的一个资源。它包含的信息非常接近,但需要进行一些调整以符合 CodePipeline 的 CloudFormation 资源规范,您可以找到 here。您还需要对需要带入模板的其他资源执行相同的操作,使用 aws <service name> describe

如果您选择选项 2(即使您不选择),我建议您在代码编辑器中使用 cfn-lint 以帮助遵守规范。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。