AWS Lambda

Open in

The AWS Lambda integration is a powerful way to add a 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 integration 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 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.

FieldDescription
AWS regionThe region where your Lambda function is deployed.
Function nameThe name of your AWS Lambda function.
AWS authentication schemeThe authentication method to use. Either AWS Credentials or ARN 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:

JSON

1

2

3

4

{
  "statusCode": "integer",
  "body": "{\"action\": \"accept|reject\", \"rejectionReason\": {\"key\": \"any\"}}"
}
  • statusCode: The HTTP status code of the response
  • body: A JSON string that is the serialization of the standard moderation response.

Best practice

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 recurring content.
  • Monitor the API request and integration error logs in the Ably dashboard to view errors .from your integration.