-
Notifications
You must be signed in to change notification settings - Fork 8
Backend Documentation
This service provides a REST API for managing user-uploaded images. Metadata is stored in DynamoDB, while image files are stored in S3. The API generates presigned URLs to allow secure, temporary access to images.
- AWS Lambda function
-DynamoDB table:
- Partition key:
userId - Sort key:
imageId
- Partition key:
- S3 bucket for image storage
- API Gateway with JWT authorizer
- IAM permissions for DynamoDB and S3 operations
- API Gateway forwards requests to Lambda.
- Authentication middleware extracts the user ID from the JWT.
- Exception middleware standardizes all error responses.
- Route handlers process requests using DynamoDB and S3.
- Presigned URLs are generated when image access is required.
- Metadata and file storage are separated (DynamoDB vs S3).
- All endpoints require authentication.
- Presigned URLs prevent direct public access to S3.
Retrieve metadata and a temporary download URL for a single specific image belonging to the authenticated user.
- Valid JWT token
- Image must exist for the user in DynamoDB
- Extract the authenticated user_id.
- Query DynamoDB using userId and imageId.
- Validate that the item exists.
- Ensure required fields (tags, s3Key) are present.
- Generate a presigned S3 URL for download.
- Return tags and the download URL.
- Returns only user-owned images.
- Missing items result in a 404 error.
- Presigned URLs expire (default: 1 hour).
Retrieve all images for the authenticated user, including metadata and download URLs.
- Valid JWT token
- Extract the authenticated user_id.
- Query DynamoDB using the partition key.
- Sort results in descending order.
- Generate presigned URLs for each image.
- Validate and normalize the response data.
- Convert non-JSON-compatible values (e.g., Decimal).
- Results are returned newest first.
- Each image includes a download URL.
- Data validation ensures consistent API responses.
Update the tags or description associated with an existing image.
- Valid JWT token
- Request body must include:
userIdimageIdtags
- Parse and validate the request body.
- Identify the target item using userId and imageId.
- Update the tags attribute in DynamoDB.
- Return a success response.
- Tags are fully replaced, not appended.
- Invalid payloads result in a 400 error.
Validates the image’s UUID and then deletes the image and corresponding metadata from S3 and DynamoDB.
- Valid JWT token
- Extract the authenticated user_id.
- Delete the image file from S3.
- Delete the corresponding metadata from DynamoDB.
- Return the deletion result.
- No rollback mechanism exists between S3 and DynamoDB.
- Consistent key structure is required for S3 objects.
Checks the availability of dependent AWS services and reports the per-service status.
- Permissions for:
- S3 bucket access
- DynamoDB table description
- Perform a health check on the S3 bucket.
- Retrieve DynamoDB table status.
- Mark services as healthy if available.
- Return overall system status.
- The current implementation always returns "OK" if no exception occurs.
- Does not distinguish partial failures.
- Useful for monitoring and uptime checks.
Validates incoming requests using JWT claims and attaches the user ID to the Lambda context.
- API Gateway JWT authorizer configured
- JWT must include a sub claim
- Extract authorizer data from the request context.
- Retrieve JWT claims.
- Extract the sub field as the user ID.
- Attach the user ID to the Lambda context.
- Continue request processing.
- Supports multiple API Gateway authorizer formats.
- Fails immediately if authentication data is missing.
- Centralizes user identity handling.
Handles all exceptions and converts them into consistent HTTP responses.
- Custom exceptions must extend the base application exception
- Wrap the Lambda handler with middleware.
- Catch known application exceptions.
- Convert them into structured HTTP responses.
- Catch unexpected errors and return a 500 response.
- Prevents unhandled runtime crashes.
- Ensures consistent error structure across endpoints.
- Separates error handling from business logic.