我正在使用 AWS CloudFormation 设置 EventBridge 总线 + 规则 + 目标(比如 SNS)。对于作为目标的 SNS,根据https://docs.aws.amazon.com/eventbridge/latest/userguide/resource-based-policies-eventbridge.html#sns-permissions上的文档,我需要在CloudFormation,我认为 CF 还不支持这个?对于作为目标的 CW 日志组,我使用aws logs put-resource-policy
来在脚本中进行设置。有没有更好的方法来自动化这个?
问问题
465 次
2 回答
1
您提供的链接是指设置SNS 主题的权限。CloudFormation支持通过AWS::SNS::TopicPolicy设置此类权限。
但是,您还声明要在 CloudWatch Logs ( aws logs put-resource-policy
) 上设置基于资源的策略。如果是这种情况,那么您是正确的,并且CloudFormation 不支持它。
您必须使用基于 lambda 函数的自定义资源来将此类功能添加到您的模板中。
于 2020-07-22T01:44:49.087 回答
1
这是我的 SAM 中的一个片段:
{
"MyDevQueue": {
"Properties": {
"QueueName": "my-dev-queue",
"ReceiveMessageWaitTimeSeconds": 20,
"Tags": [
{
"Key": "env",
"Value": "dev"
}
],
"VisibilityTimeout": 300
},
"Type": "AWS::SQS::Queue"
},
"MyDevQueuePolicy": {
"Properties": {
"PolicyDocument": {
"Statement": [
{
"Action": [
"SQS:SendMessage"
],
"Condition": {
"ArnEquals": {
"aws:SourceArn": "arn:aws:events:<region>:<AccountID>:rule/my-dev-queue/my-dev-queue"
}
},
"Effect": "Allow",
"Principal": {
"Service": [
"events.amazonaws.com"
]
},
"Resource": [
{
"Fn::GetAtt": [
"MyDevQueue",
"Arn"
]
}
]
}
]
},
"Queues": [
"MyDevQueue"
]
},
"Type": "AWS::SQS::QueuePolicy"
}
}
于 2020-07-24T00:26:25.333 回答