问题描述
这更像是我缺乏理解,但我似乎无法调试它。 我创建了一个运行 terraform apply 的代码管道(它在内部为我创建了 aws 基础设施)。代码管道似乎正在运行。
我尝试使用以下命令获取 json 脚本。
aws codepipeline get-pipeline --name
我将 json 脚本转换为 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 模板,但您有多种选择。
- 使用 former2(由 AWS Hero,Ian Mckay 构建和维护)根据您选择的资源生成 CloudFormation 模板。
- 从您使用的
aws codepipeline get-pipeline --name
命令中获取 JSON 输出并手动制作 CloudFormation 模板。管道将是 the full template 中资源列表中的一个资源。它包含的信息非常接近,但需要进行一些调整以符合 CodePipeline 的 CloudFormation 资源规范,您可以找到 here。您还需要对需要带入模板的其他资源执行相同的操作,使用aws <service name> describe
。
如果您选择选项 2(即使您不选择),我建议您在代码编辑器中使用 cfn-lint 以帮助遵守规范。