AWS Lambda
The AWS Lambda rule is a powerful way to custom moderation solution to Ably Chat. It enables you to run custom moderation logic or integrate with your preferred moderation provider by configuring an AWS Lambda function that will be invoked before messages are published to a chat room.
This rule is particularly useful when you want to:
- Integrate with a custom moderation service
- Implement your own moderation logic
- Use a moderation provider that isn’t directly supported by Ably
Integration setup
Configure the integration rule in your Ably dashboard or using the Control API.
The following fields are specific to the Lambda transport. You can also configure the general fields.
- AWS region
- The region where your Lambda function is deployed.
- Function name
- The name of your AWS Lambda function.
- AWS authentication scheme
- The authentication method to use. Either
AWS Credentials
orARN of an assumable role
. See the Ably AWS authentication documentation.
Lambda-specific response
When invoking Lambda functions, the response code received is from the Lambda runtime, not a response code specific to your function. Therefore, for Lambda transports, the standard response format is wrapped to give you the ability to specify a status code in your response. The lambda-specific response is as follows:
{
"statusCode": "integer",
"body": "{\"action\": \"accept|reject\", \"rejectionReason\": {\"key\": \"any\"}}"
}
CopyCopied!
statusCode
: The HTTP status code of the responsebody
: A JSON string that is the serialization of the standard moderation response.
Best Practices
When implementing your Lambda function, consider the following:
- Keep your function execution time as low as possible to minimize latency
- Implement proper error handling and logging
- Consider implementing rate limiting if you’re using a third-party moderation service
- Use appropriate IAM roles and permissions for your Lambda function
- Consider implementing caching for frequently occurring content