You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Content safety with Image Moderation using AWS API Gateway and AWS Lambda
2
+
3
+
Using this sample pattern, users can access AWS API Gateway to generate a pre-signed URL through an AWS Lambda function, using which they can upload images to an Amazon S3 bucket. This URL allows secure and temporary access for uploading files directly to S3.
4
+
5
+
Once an image is uploaded, an S3 event triggers another Lambda function that uses the DetectModerationLabels API to analyze the content. If the image is identified as inappropriate, a notification is sent via Amazon SNS, ensuring automated content moderation and alerting.
6
+
7
+
Learn more about this pattern at Serverless Land Patterns: https://serverlessland.com/patterns/apigw-lambda-rekognition
8
+
9
+
Important: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the [AWS Pricing page](https://aws.amazon.com/pricing/) for details. You are responsible for any AWS costs incurred. No warranty is implied in this example.
10
+
11
+
## Requirements
12
+
13
+
*[Create an AWS account](https://portal.aws.amazon.com/gp/aws/developer/registration/index.html) if you do not already have one and log in. The IAM user that you use must have sufficient permissions to make necessary AWS service calls and manage AWS resources.
14
+
*[AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured
Note: Replace 'api-id' with the generated API ID from Terraform, 'region' with the region where the API is deployed, 'object_name' with your desired name for the S3 object and 'content_type' with the content type of the image, for ex, png or jpeg
53
+
54
+
1. Get the pre-signed URL from the previous step and use the following cURL command to upload the object in S3:
55
+
56
+
curl --location --request PUT '<presigned-url>' --header 'Content-Type: image/png' --data '<path-of-the-object>.png'
57
+
58
+
Note: Replace 'presigned-url' with pre-signed URL generated in the previous step. 'Content-Type' should match the content type used to generate the pre-signed URL in the previous step. Make sure you are passing the correct path of the object in the --data parameter.
59
+
60
+
1. Once the object is uploaded successfully, the Lambda function will be invoked and if the image is inappropirate, a message is sent to the SNS Topic, which is then received by the subscriber.
61
+
62
+
## Cleanup
63
+
64
+
1. Delete the SNS Subscription:
65
+
Go to SNS > Subsciptions > Select your Subscription and click on Delete
"title": "Content safety with Image Moderation using AWS API Gateway and AWS Lambda",
3
+
"description": "Create a Lambda function which will send a notification when an inappropriate image is uploaded in Amazon S3",
4
+
"language": "Python",
5
+
"level": "200",
6
+
"framework": "Terraform",
7
+
"introBox": {
8
+
"headline": "How it works",
9
+
"text": [
10
+
"This sample project utilizes API Gateway to generate an S3 Pre-signed URL via Lambda function, enabling users to upload images to an S3 bucket. Upon successful upload, an S3 event triggers another Lambda function to analyze the image using DetectModerationLabels API. If the image is deemed inappropriate, a notification is sent through SNS. This ensure secure uploads and automated content moderation. Use cases include user-generated content platforms and e-commerce websites, where secure image uploads and automated content moderation are essential."
0 commit comments