我的CloudWatch Event规则不会触发我的CodePipeline管道

问题描述 投票:1回答:1

我在使用AWS CloudWatch Events时遇到了一些问题。

我正在创建一个CodePipeline CI管道,它有一个CodeCommit存储库作为Source,一个CodeBuild项目作为构建/测试阶段(然后,它部署到Lambda,但问题不存在)。

我们有多个项目,我们将推动多个其他项目。因此,我创建了一个管理AWS CI内容的脚本(即创建管道,CodeBuild项目,......以及链接到管道的CloudWatch Events规则)。

我第一次推送我的代码,它的工作原理。但是,随着CodeCommit的推进,该过程停止了。

我找到了一个解决方案(但不是我想要的那个):我只需要修改管道,修改阶段(Source),不要触摸任何东西,并保存空修改:它可以工作(在保存之前,它要求授权创建与此管道关联的CloudWatch Events规则)。

有人遇到过这个问题吗?你做了什么绕过它?我真的想制作100%自动化的CI,每次我的团队创建新的存储库或在现有存储库上推送新的分支时,我都不想去AWS控制台。

编辑:

以下是我的CloudWatch Events规则的JSON:

{
    "Name": "company-ci_codepipeline_project-stage", 
    "EventPattern": "cf. second JSON", 
    "State": "ENABLED", 
    "Arn": "arn:aws:events:region:xxx:rule/company-ci_codepipeline_project-stage", 
    "Description": "CloudWatch Events rule to automatically trigger the needed pipeline from every push to project repository, on the stage branch on CodeCommit."
}

这是EventPattern JSON:

{
  "source": [
    "aws.codecommit"
  ],
  "detail-type": [
    "CodeCommit repository state change"
  ],
  "resources": [
    "arn:aws:codecommit:region:xxx:project"
  ],
  "detail": {
    "event": [
      "referenceCreated",
      "referenceUpdated"
    ],
    "referenceType": [
      "branch"
    ],
    "referenceName": [
      "stage"
    ]
  }
}
amazon-web-services continuous-integration amazon-cloudwatch aws-codepipeline
1个回答
2
投票

我发现此问题通常与事件规则/目标/角色配置有关。如果您没有与规则关联的目标,则在查看指标时不会看到调用的事件。由于您的EventPattern看起来正确,我认为目标可能是您的问题。

你应该有一个看似如下的配置目标:

{
    "Rule": "company-ci_codepipeline_project-stage",
    "Targets": [
        {
            "RoleArn": "arn:aws:iam::xxx:role/cwe-codepipeline",
            "Id": "ProjectPipelineTarget",
            "Arn": "arn:aws:codepipeline:region:xxx:your-pipeline"
        }
    ]
}

如果这似乎都很好,我接下来会检查与目标关联的角色是否授予正确的权限。我的角色看起来像:

{
    "Role": {
        "Description": "Allows CloudWatch Events to invoke targets and perform actions in built-in targets on your behalf.",
        "AssumeRolePolicyDocument": {
            "Version": "2012-10-17",
            "Statement": [
                {
                    "Action": "sts:AssumeRole",
                    "Principal": {
                        "Service": "events.amazonaws.com"
                    },
                    "Effect": "Allow",
                    "Sid": ""
                }
            ]
        },
        "MaxSessionDuration": 3600,
        "RoleId": "xxxx",
        "CreateDate": "2018-08-06T20:56:19Z",
        "RoleName": "cwe-codepipeline",
        "Path": "/",
        "Arn": "arn:aws:iam::xxx:role/cwe-codepipeline"
    }
}

它的内联政策是:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "codepipeline:StartPipelineExecution"
            ],
            "Resource": [
                "arn:aws:codepipeline:*:xxx:*"
            ]
        }
    ]
}

如需参考,请查看此documentation

© www.soinside.com 2019 - 2024. All rights reserved.