【问题标题】:AWS CodePipeLine :Execute deploy action in diffent region than the one codepipeline is triggered inAWS CodePipeLine :在不同的区域执行部署操作,而不是触发一个代码管道
【发布时间】:2018-10-04 12:52:18
【问题描述】:

我正在设置一个管道来自动化 cloudformation 堆栈模板部署。

管道本身在 aws eu-west-1 区域中创建,但 cloudformation 堆栈模板将部署在任何其他区域中。

实际上我知道并且可以在不同的帐户中执行管道操作,但是我看不到在哪里指定我希望我的模板部署到的区域,就像我们使用 aws cli 所做的那样:aws --region cloudformation deploy....

请问是否可以在一个区域触发管道并在另一个区域执行deploy action

动作配置属性不提供这种可能性...

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation aws-codepipeline


    【解决方案1】:

    一种解决方法是从 codebuild 容器中的 cli 运行 aws cli deploy 命令并指定好区域,但我想知道是否有更优雅的方法来做到这一点

    【讨论】:

      【解决方案2】:

      如果您希望一个接一个地部署到多个区域,您可以在要部署到的每个区域中创建一个代码管道管道,并设置 S3 跨区域复制,以便第一个的输出管道成为下一个区域中管道的输入。

      这里有一篇博文进一步解释了这一点:https://aws.amazon.com/blogs/devops/building-a-cross-regioncross-account-code-deployment-solution-on-aws/

      【讨论】:

      • 顺便说一句,不支持跨区域部署是 Code Pipeline 功能集中的一个显着差距,这是显而易见的事情。
      【解决方案3】:

      自 2018 年 11 月下旬起,CodePipeline 支持cross regional deploys。但是,它仍然有很多不足之处,因为您需要在每个区域中创建工件存储桶,并在触发部署操作之前将部署工件(例如,在您提到的 codebuild 容器中)复制到它们。因此,它并没有达到应有的自动化程度,但如果您完成了设置过程,它会运行良好。

      【讨论】:

        【解决方案4】:

        CodePipeline 现在支持跨区域部署,为了触发不同区域的管道,我们可以在 CloudFormation 的操作阶段指定 "Region": "us-west-2" 属性,这将触发该特定区域的部署。

        此设置要遵循的步骤:

        1. 在两个不同的区域创建两个存储桶,例如“us-east-1”中的存储桶和“us-west-2”中的存储桶(当您第一次设置管道时,我们也可以使用 CodePipeline 已经创建的存储桶任何地区)
        2. 以这样一种方式配置管道,即可以在相应帐户中执行操作时使用相应的存储桶。
        3. 为 CodePipeline 指定操作中的区域。

        注意:我已附上示例 CloudFormation 模板,它将帮助您进行跨区域 CloudFormation 部署。

        {
            "Parameters": {
                "BranchName": {
                    "Description": "CodeCommit branch name for all the resources",
                    "Type": "String",
                    "Default": "master"
                },
                "RepositoryName": {
                    "Description": "CodeComit repository name",
                    "Type": "String",
                    "Default": "aws-account-resources"
                },
                "CFNServiceRoleDeployA": {
                    "Description": "CFN service role for create resourcecs for account-A",
                    "Type": "String",
                    "Default": "arn:aws:iam::xxxxxxxxxxxxxx:role/CloudFormation-service-role-cp"
                },
                "CodePipelineServiceRole": {
                    "Description": "Service role for codepipeline",
                    "Type": "String",
                    "Default": "arn:aws:iam::xxxxxxxxxxxxxx:role/AWS-CodePipeline-Service"
                },
                "CodePipelineArtifactStoreBucket1": {
                    "Description": "S3 bucket to store the artifacts",
                    "Type": "String",
                    "Default": "bucket-us-east-1"
                },
                "CodePipelineArtifactStoreBucket2": {
                    "Description": "S3 bucket to store the artifacts",
                    "Type": "String",
                    "Default": "bucket-us-west-2"
                }
            },
            "Resources": {
                "AppPipeline": {
                    "Type": "AWS::CodePipeline::Pipeline",
                    "Properties": {
                        "Name": {"Fn::Sub": "${AWS::StackName}-cross-account-pipeline" },
                        "ArtifactStores": [
                            {
                                "ArtifactStore": {
                                    "Type": "S3",
                                    "Location": {
                                        "Ref": "CodePipelineArtifactStoreBucket1"
                                    }
                                },
                                "Region": "us-east-1"
                            },
                            {
                                "ArtifactStore": {
                                    "Type": "S3",
                                    "Location": {
                                        "Ref": "CodePipelineArtifactStoreBucket2"
                                    }
                                },
                                "Region": "us-west-2"
                            }
                        ],
                        "RoleArn": {
                            "Ref": "CodePipelineServiceRole"
                        },
                        "Stages": [
                            {
                                "Name": "Source",
                                "Actions": [
                                    {
                                        "Name": "SourceAction",
                                        "ActionTypeId": {
                                            "Category": "Source",
                                            "Owner": "AWS",
                                            "Version": 1,
                                            "Provider": "CodeCommit"
                                        },
                                        "OutputArtifacts": [
                                            {
                                                "Name": "SourceOutput"
                                            }
                                        ],
                                        "Configuration": {
                                            "BranchName": {
                                                "Ref": "BranchName"
                                            },
                                            "RepositoryName": {
                                                "Ref": "RepositoryName"
                                            },
                                            "PollForSourceChanges": true
                                        },
                                        "RunOrder": 1
                                    }
                                ]
                            },
                            {
                                "Name": "Deploy-to-account-A",
                                "Actions": [
                                    {
                                        "Name": "stage-1",
                                        "InputArtifacts": [
                                            {
                                                "Name": "SourceOutput"
                                            }
                                        ],
                                      
                                        
                                        "ActionTypeId": {
                                            "Category": "Deploy",
                                            "Owner": "AWS",
                                            "Version": 1,
                                            "Provider": "CloudFormation"
                                        },
                                        "Configuration": {
                                            "ActionMode": "CREATE_UPDATE",
                                            "StackName": "cloudformation-stack-name-account-A",
                                            "TemplatePath":"SourceOutput::accountA.json",
                                            "Capabilities": "CAPABILITY_IAM",
                                            "RoleArn": {
                                                "Ref": "CFNServiceRoleDeployA"
                                            }
                                        },
                                        "RunOrder": 2,
                                        "Region": "us-west-2"
                                    }
                                ]
                            }
        
                            
                        ]
                    }
                }
            }
        }

        【讨论】:

          猜你喜欢
          • 2019-08-05
          • 2022-01-26
          • 2019-09-16
          • 2019-06-25
          • 2019-07-04
          • 1970-01-01
          • 1970-01-01
          • 2020-10-05
          • 1970-01-01
          相关资源
          最近更新 更多