我正在尝试创建一个 cloudformation 堆栈来监视 S3 存储桶(由不同的堆栈创建)并在上传/覆盖某个文件时启动 codebuild 运行。我的模板看起来像:
NgBuildCodeBuild:
Type: AWS::CodeBuild::Project
...
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: !Sub
- 'myapp-frontend-built-${Branch}-watch-s3'
- { Branch: !Ref TrackedBranch }
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action: codebuild:StartBuild
Resource: !GetAtt NgBuildCodeBuild.Arn
AmazonCloudWatchEventRule:
Type: AWS::Events::Rule
Properties:
EventPattern:
source:
- aws.s3
detail-type:
- 'AWS API Call via CloudTrail'
detail:
eventSource:
- s3.amazonaws.com
eventName:
- PutObject
- CompleteMultipartUpload
requestParameters:
bucketName:
- 'my-app-src-s3-bucket'
key:
- !Sub
- 'myGitUsername/myRepoName/${Branch}/src.zip'
- { Branch: !Ref TrackedBranch }
Targets:
- Arn: !GetAtt NgBuildCodeBuild.Arn
RoleArn: !GetAtt AmazonCloudWatchEventRole.Arn
Id: codebuild-myapp-frontend
堆栈部署良好,但是当我将 a 上传src.zip
到正在监视的键/目标 ( 'myGitUsername/myRepoName/${Branch}
) 时……没有任何反应。我很确定我正在上传到正确的 S3 存储桶和路径。看起来该事件从未被触发。当我查看事件桥中已部署规则的指标时,没有数据。我期待这个 aws CLI 命令触发事件:
aws s3 cp $outputbucketkey s3://$outputbucket/$outputbucketpath
. 使用网络浏览器删除src.zip
并重新上传它也不会触发该事件。
我使用了错误的事件名称吗?还是我误解了事件桥的用途?