Amazon web services AWS在ECR推送动作时触发管道?
AWS CodePipeline可以在对AWS CodeCommit执行提交操作时触发Amazon web services AWS在ECR推送动作时触发管道?,amazon-web-services,events,pipeline,aws-codecommit,aws-ecr,Amazon Web Services,Events,Pipeline,Aws Codecommit,Aws Ecr,AWS CodePipeline可以在对AWS CodeCommit执行提交操作时触发 我没有看到在AWS ECR的推送操作中触发AWS代码管道的选项/方法。有这样的选项吗?如果您从AWS CodePipeline控制台创建管道并选择Amazon ECR作为源提供程序,它将创建CloudWatch事件 { "source": [ "aws.ecr" ], "detail": { "eventName": [ "PutImage" ], "
我没有看到在AWS ECR的推送操作中触发AWS代码管道的选项/方法。有这样的选项吗?如果您从AWS CodePipeline控制台创建管道并选择Amazon ECR作为源提供程序,它将创建CloudWatch事件
{
"source": [
"aws.ecr"
],
"detail": {
"eventName": [
"PutImage"
],
"requestParameters": {
"repositoryName": [
"my-repo/nginx"
],
"imageTag": [
"0.1"
]
}
}
此事件的目标将是CodePipeline。您可以在AWS CloudWatch控制台中检查事件详细信息。每当ECR回购发生推送(PutImage)时,管道将被切断。因此,Cloudwatch事件就是这样做的。对于那些希望通过CFN方法实现的人,下面的CFN模板将有所帮助
{
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters": {
"CodePipelineName": {
"Type": "String",
"Description": "Name of the CodePipeline Project that needs to be triggered. NOTE: CodePipeline does not support ARN output but AWS::Events::Rule target expects an ARN"
},
"ECRRepoName": {
"Type": "String",
"Description": "Name of the ECR Repo on which the Trigger needs to be set-up"
},
"ECRImageTagName": {
"Type": "String",
"Description": "Name of the ECR Image tag on which the Trigger needs to be set-up",
"Default": "latest"
}
},
"Resources": {
"AmazonCloudWatchEventRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"events.amazonaws.com"
]
},
"Action": "sts:AssumeRole"
}
]
},
"Path": "/",
"Policies": [
{
"PolicyName": "cwe-pipeline-execution",
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "codepipeline:StartPipelineExecution",
"Resource": {
"Fn::Sub": "arn:aws:codepipeline:${AWS::Region}:${AWS::AccountId}:${CodePipelineName}"
}
}
]
}
}
]
}
},
"AmazonCloudWatchEventRule": {
"Type": "AWS::Events::Rule",
"Properties": {
"EventPattern": {
"detail": {
"action-type": [
"PUSH"
],
"image-tag": [
{
"Ref": "ECRImageTagName"
}
],
"repository-name": [
{
"Ref": "ECRRepoName"
}
],
"result": [
"SUCCESS"
]
},
"detail-type": [
"ECR Image Action"
],
"source": [
"aws.ecr"
]
},
"Targets": [
{
"Arn": {
"Fn::Sub": "arn:aws:codepipeline:${AWS::Region}:${AWS::AccountId}:${CodePipelineName}"
},
"RoleArn": {
"Fn::GetAtt": [
"AmazonCloudWatchEventRole",
"Arn"
]
},
"Id": {
"Ref": "CodePipelineName"
}
}
]
}
}
}
}
在此处输入代码
您需要结合这两个教程:和。