amazon-web-services - 如何将现有 CodePipeline 导出到 CloudFormation 模板

标签 amazon-web-services terraform aws-cloudformation aws-codepipeline aws-cloudformation-custom-resource

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

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

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

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

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

模板格式错误:必须至少定义一个资源成员。

问题: 1.) 将 codepipeline 导出到 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",
                            "version": "1"
                        },
                        "runOrder": 1,
                        "configuration": {
                            "ProjectName": "my-code-pipeline-build-stage"
                        },
                        "outputArtifacts": [],
                        "inputArtifacts": [
                            {
                                "name": "SourceArtifact"
                            }
                        ],
                        "region": "aws-region"
                    }
                ]
            },
            {
                "name": "manual-approve",
                "actions": [
                    {
                        "name": "approval",
                        "actionTypeId": {
                            "category": "Approval",
                            "owner": "AWS",
                            "provider": "Manual",
                            "version": "1"
                        },
                        "runOrder": 1,
                        "configuration": {
                            "NotificationArn": "arn:aws:sns:aws-region:aws-account-id:Email-Service"
                        },
                        "outputArtifacts": [],
                        "inputArtifacts": [],
                        "region": "aws-region"
                    }
                ]
            },
            {
                "name": "codebuild-for-terraform-apply",
                "actions": [
                    {
                        "name": "codebuild-for-terraform-apply",
                        "actionTypeId": {
                            "category": "Build",
                            "owner": "AWS",
                            "provider": "CodeBuild",
                            "version": "1"
                        },
                        "runOrder": 1,
                        "configuration": {
                            "ProjectName": "codebuild-project-for-apply"
                        },
                        "outputArtifacts": [],
                        "inputArtifacts": [
                            {
                                "name": "SourceArtifact"
                            }
                        ],
                        "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使用代码编辑器来帮助遵守规范。

关于amazon-web-services - 如何将现有 CodePipeline 导出到 CloudFormation 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67383997/

相关文章:

java - 创建一个程序来管理 Amazon EC2 实例

amazon-web-services - AWS CodePipeline 仅部署自上次部署以来已更改的文件,而不是简单地替换应用程序

provisioning - Terraform,寻找在命令中使用双引号的简单方法?

bash - 在 Terraform 中创建随机变量并将其传递给 GCE 启动脚本

amazon-web-services - AWS Cloud Formation - 不支持请求的配置 AWS::EC2::Instance

java - 如何在 AWS Java SDK v2 Apache 客户端上设置代理

python - 如何使用 boto 将文件上传到 S3 存储桶中的目录

terraform - 如何将多个AWS提供商传递给一个模块?

amazon-web-services - 是否可以就地定义 Cloudformation 资源?

amazon-web-services - 如何在 Cloudformation 模板上设置 AWS EC2 实例的内存大小?