如何将现有的 CodePipeline 导出到 CloudFormation 模板
How to export an existing CodePipeline to CloudFormation template
-
amazon-web-services
-
amazon-cloudformation
-
terraform
-
aws-codepipeline
-
aws-cloudformation-custom-resource
这更多的是我缺乏理解,但我似乎无法调试它。
我创建了一个应用 运行s terraform 的代码管道(它在内部为我创建了 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",
"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 命令returns 关于管道结构和管道元数据的信息,但它与 CloudFormation 模板(或其资源部分)的格式不同。
没有内置支持导出现有 AWS 资源以创建 CloudFormation 模板,但您有几个选项。
- 使用 former2(由 AWS Hero Ian Mckay 构建和维护)从您 select.
的资源生成 CloudFormation 模板
- 从您使用的
aws codepipeline get-pipeline --name
命令中获取 JSON 输出并手动制作 CloudFormation 模板。管道将是 the full template. The info it contains is pretty close, but needs some adjustments to conform to the CloudFormation resource specification for a CodePipeline, which you can find here 中资源列表中的一项资源。您还需要对需要带入模板的其他资源执行相同的操作,使用 aws <service name> describe
.
如果您选择选项 2(即使您不选择),我建议将 cfn-lint 与您的代码编辑器一起使用以帮助遵守规范。
amazon-web-services
amazon-cloudformation
terraform
aws-codepipeline
aws-cloudformation-custom-resource
这更多的是我缺乏理解,但我似乎无法调试它。 我创建了一个应用 运行s terraform 的代码管道(它在内部为我创建了 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",
"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 命令returns 关于管道结构和管道元数据的信息,但它与 CloudFormation 模板(或其资源部分)的格式不同。
没有内置支持导出现有 AWS 资源以创建 CloudFormation 模板,但您有几个选项。
- 使用 former2(由 AWS Hero Ian Mckay 构建和维护)从您 select. 的资源生成 CloudFormation 模板
- 从您使用的
aws codepipeline get-pipeline --name
命令中获取 JSON 输出并手动制作 CloudFormation 模板。管道将是 the full template. The info it contains is pretty close, but needs some adjustments to conform to the CloudFormation resource specification for a CodePipeline, which you can find here 中资源列表中的一项资源。您还需要对需要带入模板的其他资源执行相同的操作,使用aws <service name> describe
.
如果您选择选项 2(即使您不选择),我建议将 cfn-lint 与您的代码编辑器一起使用以帮助遵守规范。