New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(lambda): Support SNS Topics as DLQs #16246
Comments
FYI. That can be achieved with a little bit of dlq: sns.Topic = ... # defined elsewhere
dlq.grant_publish(function)
set_dlq_action = custom.AwsSdkCall(
service='Lambda',
action='updateFunctionConfiguration',
parameters={
'FunctionName': function.function_name,
'DeadLetterConfig': {
'TargetArn': dlq.topic_arn,
},
},
output_paths=['DeadLetterConfig.TargetArn'],
physical_resource_id=custom.PhysicalResourceId.of(construct_id),
)
custom.AwsCustomResource(
self,
construct_id,
on_create=set_dlq_action,
on_update=set_dlq_action,
on_delete=custom.AwsSdkCall(
service='Lambda',
action='updateFunctionConfiguration',
parameters={
'FunctionName': function.function_name,
'DeadLetterConfig': {
'TargetArn': None,
},
},
output_paths=['DeadLetterConfig.TargetArn'],
),
policy=custom.AwsCustomResourcePolicy.from_sdk_calls(
resources=custom.AwsCustomResourcePolicy.ANY_RESOURCE,
),
) |
Probably using escape hatches instead of custom resources is a better solution for the workaround until it is supported. dlq = sns.Topic(self, 'dlq')
fun = fn.Function(
self,
'lambdaFn',
code=fn.Code.from_inline('def handler(event, context): ...'),
runtime=fn.Runtime.PYTHON_3_8,
handler='index.handler',
)
# add dead letter config using escape hatches
cfn_function = fun.node.default_child
cfn_function.dead_letter_config = {
"targetArn": dlq.topic_arn
} As proposed by @kornicameister, the permission has to be granted (I didn't test this part). dlq.grant_publish(fun) |
@jumic permission is needed, when I was dealing with custom resource, it failed on stacking up because of that. I think lambda detects whether is has permission to write to a topic/queue or not. Anyway, thx for suggesting escape hatches! much much cleaner. |
Adds possibility of using sns.Topic as a deadLetterQueue for a lambda function as described in `AWS::Lambda::Function` documentation. closes: aws#16246
Adds possibility of using sns.Topic as a deadLetterQueue for a lambda function as described in `AWS::Lambda::Function` documentation. closes: #16246 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
|
Adds possibility of using sns.Topic as a deadLetterQueue for a lambda function as described in `AWS::Lambda::Function` documentation. closes: aws#16246 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
aws_lambda.Function
does not support havingsns.Topic
as a target dead letter queue. It is incorrect as lambda does allow to set topic as a target.Such information can be found here as well as can be seen in attached screenshot.
Reproduction Steps
What did you expect to happen?
Expected lambda to deploy correctly and have topic configured as DQL.
What actually happened?
Environment
Other
I believe it makes sense to enable that for the sake of use cases where someone wishes to receive Slack or Email notification that one the lambda failed. Having only SQS as an option forces to write additional lambda to simply send an email.
This is 🐛 Bug Report
The text was updated successfully, but these errors were encountered: