The ImageOptimizer API is a serverless solution for automatically resizing images using AWS Lambda and Amazon S3. This documentation provides details on how to set up, deploy, and use the API.
- AWS Account: You need an AWS account to deploy the Lambda function and API Gateway.
- Postman: For testing API requests.
-
Deploy the Lambda Function:
- Create an S3 bucket for image storage.
- Create an IAM role with necessary permissions for Lambda to access S3.
- Deploy the Lambda function using the provided code.
-
Set Up API Gateway:
- Create a new API in API Gateway.
- Create a resource and method to trigger the Lambda function.
- Deploy the API to obtain the endpoint URL.
Use Postman or any HTTP client to send POST requests to the API endpoint. The payload should resemble the following:
{
"Records": [
{
"s3": {
"bucket": {
"name": "your-s3-bucket-name"
},
"object": {
"key": "path/to/your/image.jpg"
}
}
}
]
}
For detailed insights into the execution of your Lambda function, you can check the CloudWatch Logs. Follow these steps:
- Open the AWS Lambda console.
- Navigate to your Lambda function (
ImageOptimizer
). - Click on the "Monitoring" tab.
- Scroll down to the "Log groups" section and click on the associated CloudWatch Log Group link.
Monitor API Gateway for request and error metrics. Follow these steps:
- Open the API Gateway console.
- Navigate to your API.
- In the API Gateway dashboard, explore the available metrics.
If you encounter issues, consider the following steps:
-
IAM Roles and Permissions:
- Ensure that the IAM role associated with your Lambda function has the necessary permissions to read from and write to the S3 bucket.
-
CloudWatch Logs:
- Check CloudWatch Logs for your Lambda function to identify any error messages or unexpected behavior.
-
API Gateway Settings:
- Review API Gateway settings and logs for any issues related to request handling or Lambda function integration.
Contributions are welcome! If you have suggestions, find a bug, or want to contribute to the project, feel free to open issues or pull requests.
This project is licensed under the MIT License.