我们如何为使用SDK发送到AWS Lambda的通知启用SNS日志记录?

时间:2019-05-15 17:03:29

标签: amazon-web-services aws-lambda amazon-sns amazon-cloudwatch

要求:

为使用SDK(而非通过控制台)发送到AWS Lambda的通知启用SNS传递状态日志记录(到CloudWatch)

问题:

通过控制台,我们可以通过将协议选择为“ AWS Lambda”来轻松enable delivery status logging。但是,通过SDK there is only an option to set it for the "platform application endpoint" protocol,它具有强制性属性PlatformApplicationArn,因此它不能用于其他日志协议。

我是否缺少某些功能,或者此功能尚不可用?

2 个答案:

答案 0 :(得分:0)

好吧,由于文档极端引起误解,我已经弄清楚了。

为了启用Lambda协议的日志记录(我还没有测试其他协议),您必须使用SetTopicAttributes。即使文档指出AttributeName是包含DeliveryPolicyDisplayNamePolicy的映射,您实际上仍必须将AttributeName设置为{{1} },LambdaSuccessFeedbackRoleArnLambdaFailureFeedbackRoleArn 3个单独的SNS.setTopicAttributes()调用中。

因此,参数将如下所示:

LambdaSuccessFeedbackSampleRate

然后进行3次SNS调用,每个参数一个。

答案 1 :(得分:0)

要补充@Deiv anwser,可以在 if grad is None: return grad return _tf.clip_by_value(grad, -clip_value, clip_value) if clip_value is not None: grads_and_vars = opt.compute_gradients(loss) clipped_gradients = [(ClipIfNotNone(g, clip_value), v) for g, v in grads_and_vars] train_op = opt.apply_gradients(clipped_gradients, global_step=global_step) python中完成:

boto3

然后检查属性是否已设置,可以使用awc cli:

client = boto3.client('sns')

snsarn='SNS topic ARN'

snslogarn = 'ARN of role that can write to CloudWatch Logs'

response = client.set_topic_attributes(
        TopicArn=snsarn,
        AttributeName='LambdaFailureFeedbackRoleArn',
        AttributeValue=snslogarn)

response = client.set_topic_attributes(
        TopicArn=snsarn,
        AttributeName='LambdaSuccessFeedbackRoleArn',
        AttributeValue=snslogarn)  

response = client.set_topic_attributes(
        TopicArn=snsarn,
        AttributeName='LambdaSuccessFeedbackSampleRate',
        AttributeValue='0')