我很难使用 Beanstalk 和 Codepipeline 设置自动化...
我终于让它运行了,主要问题是 S3 Cloudwatch 事件触发 Codepipeline
的启动。我错过了必要的 Cloudtrail 部分,并且在任何文档中都找不到它。
所以当前的设置是: S3 文件上传 -> CloudWatch 事件触发 Codepipeline -> Codepipeline 部署到 ElasticBeanstalk 环境。
正如我所说,要获取 CloudWatch Event 触发器,您需要一个 Cloudtrail
跟踪,例如:
resource "aws_cloudtrail" "example" {
# ... other configuration ...
name = "codepipeline-source-trail" #"codepipeline-${var.project_name}-trail"
is_multi_region_trail = true
s3_bucket_name = "codepipeline-cloudtrail-placeholder-bucket-eu-west-1"
event_selector {
read_write_type = "WriteOnly"
include_management_events = true
data_resource {
type = "AWS::S3::Object"
values = ["${data.aws_s3_bucket.bamboo-deploy-bucket.arn}/${var.project_name}/file.zip"]
}
}
}
但这只是为了创建一条新路径。问题是 AWS 最多只允许 5 个路径。在 AWS 控制台上,您可以将多个数据事件添加到一个跟踪中,但我无法在 terraform 中做到这一点。我尝试使用相同的名称,但这只会引发错误
"Error creating CloudTrail: TrailAlreadyExistsException: Trail codepipeline-source-trail already exists for customer: XXXX"
我尽力解释我的问题。不确定是否可以理解。
简而言之:我想使用 terraform 在现有的 cloudtrail 跟踪中添加 data events:S3
。
感谢帮助, 丹尼尔
最佳答案
As I said to get the CloudWatch Event trigger you need a Cloudtrail trail like:
您不需要多个 CloudTrail
来调用 CloudWatch 事件。您还可以创建特定于服务的规则。
Create a CloudWatch Events rule for an Amazon S3 source (console)
从 CloudWatch
事件规则调用 CodePipeline
作为目标。假设您创建了此事件规则
{
"source": [
"aws.s3"
],
"detail-type": [
"AWS API Call via CloudTrail"
],
"detail": {
"eventSource": [
"s3.amazonaws.com"
],
"eventName": [
"PutObject"
]
}
}
您添加 CodePipeline
作为此规则的目标,最终 Codepipeline 会部署到 ElasticBeanstalk env。
关于amazon-web-services - Terraform 中 S3 存储桶的 AWS Cloudtrail 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66013433/