我还是 AWS 服务的新手。
我想使用 CloudFormation 模板 (CFT) 在现有 S3 存储桶上添加 Lambda 触发器。这可能吗?
以下 CFT 正在尝试创建新的 S3 存储桶并在其上添加事件通知。
S3BUCKET_NOTIFCATION = Bucket(
"S3Bucket",
BucketName=s3_bucket("confidential", Ref(ENV)),
NotificationConfiguration=NotificationConfiguration(
LambdaConfigurations=[
LambdaConfigurations(
Event="s3:ObjectCreated:*",
Filter=Filter(
S3Key=S3Key(
Rules=[Rules(Name="prefix", Value=Ref(inputKeyPrefix)),
Rules(Name="suffix", Value=".json")]
)
),
Function=Ref(cost_function)
)
]
)
)
是否可以将 NotificationConfiguration
添加到现有存储桶?
最佳答案
正如其他人所指出的,由于各种原因,这仍然是不允许的。
选项 1) 推荐
恕我直言,这里的理想方法是首先导入现有的云资源(在本例中为 S3)以由 IaC/CloudFormation 管理。然后,导入资源后,您可以将NotificationConfiguration 添加到您的CloudFormation 模板中。这种方法允许您管理现有资源,这些资源最初可能是手动配置的,以后将通过 IaC/Cfn 进行管理。
选项 2) 您的要求
如果您想通过 CloudFormation 将 NotificationConfiguration 添加到现有 S3 存储桶,解决方法是使用
a Lambda-backed custom resource created... The custom resource triggers a Lambda function, which triggers the PutBucketNotification API to add a notification configuration to your S3 bucket.
详情here
注意:请考虑选项 2) 的限制。其中一些记录在引用的链接中。
关于amazon-web-services - 是否可以使用 CFT 将NotificationConfiguration 添加到现有的S3 存储桶?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46454305/