This Python-based AWS Lambda function dynamically generates placeholder images based on specified dimensions. The dimensions are provided through a URL parameter in the format /{width}x{height}
, for example, /300x100
. The generated image contains the dimensions as text, centered within the image.
- Dynamic Placeholder Image Generation: Creates images with custom dimensions and text indicating those dimensions.
- URL-Based Parameters: Dimensions are specified via a URL parameter in the format
/{width}x{height}
. - Custom Fonts: Uses a custom font (Arial Narrow) for text rendering within the image.
- Python >= 3.9
- Node >= 18.12.0
- AWS Lambda for hosting and executing the function.
- The 'serverless' framework for deployment and offline debugging.
- Serverless Offline: The project is configured to use
serverless-offline
for local development and debugging. This allows for simulating the AWS Lambda environment on your local machine.
- Deploy to Production: Use the command
serverless deploy --stage prod
to deploy the application to the production environment.
Generates an image of specified width and height. The image displays the dimensions as text.
image_width
(str): Width of the image.image_height
(str): Height of the image.image_name
(str): Text to be displayed on the image, typically the dimensions.
Prepares the generated image for HTTP response.
image_bytes
(bytes): Byte stream of the generated image.status_code
(int): HTTP status code for the response.
Lambda function handler. Extracts dimensions from the URL, generates the image, and returns it in the HTTP response.
event
(dict): Contains the request details and parameters.context
: AWS Lambda context object (not used in this function).
- Deploy the Lambda function.
- Make a request to the Lambda URL with the desired dimensions, e.g.,
https://your-lambda-url.com/300x100
. - The function will return a 300x100 image with "300x100" text displayed in the center.