Claudia 5.8: More flexible SNS integrations

Claudia 5.8.0 is now on NPM, making it easier to work with SNS topics, both as an input for Lambda functions and a destination for dead letters. AWS introduced support for SNS message topic filter policies and Dead Letter SNS Queues a while ago, but until now Claudia users had to set those two features up manually after creating the functions. With this release, you can easily introduce both to your functions.

Send dead letters to SNS

With asynchronous invocation, Lambda automatically retries errors but gives up after three attempts. The client requesting asynchronous invocation does not get a notification about this, so in case of bad code, the original event gets lost. Dead Letter Queues are a way to preserve such events. You can set up a SNS topic to receive any events that could not be processed, and then direct the SNS topic to your logs, to send you an e-mail, or even to invoke a different Lambda function.

Add a dead letter SNS topic simply by adding --dlq-sns TOPIC after claudia create or claudia update. You can specify either a topic name, if it’s in the same AWS account and region as your function, or the full ARN for topics belonging to other accounts. Claudia will automatically set up the required IAM policies to allow publishing to the topic. For example:

claudia create --handler lambda.handler --dlq-sns admin_alerts

claudia update --dlq-sns arn:aws:sns:us-east-1:123456789012:dev_messages

Note that you can have only one dead letter queue in a function configuration, so if multiple aliases point to the same configuration version, they will use the same dead letter queue topic.

Apply a filter to incoming events

Topic filters are a way to stop irrelevant messages from invoking Lambda functions, in case many different functions listen to the same topic. For example, you can use a SNS topic for payment notifications, and provide metadata about the type of notification. You can then set up one Lambda functions to log notifications to S3 regardless of the type, but separate functions that only process payments or chargebacks.

To set up a topic filter when adding a subscription, use --filter-policy and provide the policy JSON inline:

claudia add-sns-event-source 
  --topic arn:aws:sns:us-east-1:123456789012:payments 
  --filter-policy '{"notification-type": ["chargeback"]}'

To work easier with more complex policies, and avoid problems with escaping quotes or whitespace on the command line, save the policy to a file and provide it with the --filter-policy-file option:

claudia add-sns-event-source 
  --topic arn:aws:sns:us-east-1:123456789012:payments 
  --filter-policy-file policy.json 

Use Claudia with other AWS partitions

Finally, we updated all the Claudia commands to support working with AWS Cloud Partitions, such as aws-us-gov and aws-cn, so you will be able to use Claudia outside the usual AWS public cloud. The partition should be recognised based on your profile region, so make sure to set the AWS_REGION environment variable, or provide the appropriate region with the --region command line option.

Interested in Claudia.js? Get notified when we release a new version.

Low-volume, high value mailing list, no ads or spam.