Project Overview
Project Overview
This project involves building a web application that allows users to upload images, analyze the
images using AWS Rekognition, and display the analysis results on a PHP web page. The workflow
includes:
2. Navigate to S3.
5. Configure the bucket to allow public read access (you can adjust permissions later for
security).
o AmazonS3ReadOnlyAccess
o AmazonRekognitionFullAccess
o AWSLambdaBasicExecutionRole
Replace the default code in your Lambda function with the following Python code:
python
Copy code
import boto3
client = boto3.client('rekognition')
bucket = event['Records'][0]['s3']['bucket']['name']
key = event['Records'][0]['s3']['object']['key']
return {
'statusCode': 200,
'body': labels
6. Click Add.
Step 3: Set Up the PHP Web Application
Ensure your server or local environment has PHP and Composer installed. Run the following
command to install the AWS SDK for PHP:
bash
Copy code
a. Create index.php
php
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
</form>
</body>
</html>
b. Create upload.php
php
Copy code
<?php
require 'vendor/autoload.php';
use Aws\S3\S3Client;
use Aws\Lambda\LambdaClient;
]);
try {
$result = $s3->putObject([
]);
]);
$lambdaResult = $lambda->invoke([
'Records' => [
's3' => [
]),
]);
echo "<ul>";
echo "<li>{$label}</li>";
echo "</ul>";
?>
Additional Considerations
Security: Ensure your S3 bucket and IAM roles have the least privilege necessary. Use IAM
policies to restrict access where possible.
Cost Management: Monitor AWS usage to avoid unexpected costs. S3 storage, Lambda
invocations, and Rekognition API calls may incur charges.
Error Handling: The PHP script includes basic error handling. Consider improving it to handle
various edge cases (e.g., large image uploads, network issues).
By following these steps, you'll have a complete web application that integrates AWS Lambda,
Rekognition, S3, and PHP. This setup allows for automated image analysis with a user-friendly
interface.