Skip to content

Finished task 5#4

Open
DamirSt wants to merge 1 commit into
task-4from
task-5
Open

Finished task 5#4
DamirSt wants to merge 1 commit into
task-4from
task-5

Conversation

@DamirSt
Copy link
Copy Markdown
Owner

@DamirSt DamirSt commented May 3, 2026

Module 5: Import Service Implementation

What was done?

Core Import Service Implementation

Complete import service infrastructure with S3 integration and CSV processing capabilities

CDK Stack and S3 Infrastructure

  • Created ImportServiceStack with proper repository structure following ProductServiceStack pattern
  • Implemented S3 bucket import-service-bucket-719484290433 with versioning and encryption
  • Configured IAM policies for Lambda functions with least-privilege access
  • Added uploaded/ folder structure for file imports

Lambda Function: importProductsFile (50/50 points)

  • Implemented Lambda function with API Gateway integration at GET /import endpoint
  • Function generates signed URLs for CSV file uploads with 5-minute expiration
  • Returns structured JSON response: {signedUrl, fileName, s3Key, expiresIn}
  • Integrated with frontend environment configuration
  • Used async/await patterns throughout implementation
  • Covered by unit tests using aws-sdk-mock for S3 method mocking

Lambda Function: importFileParser (40/40 points)

  • Created Lambda function triggered by S3 events for uploaded/ folder objects
  • Implemented CSV parsing using readable streams with csv-parser package
  • Added file management: moves processed files from uploaded/ to parsed/ folder
  • Configured proper error handling without S3 event retry failures
  • Used async/await patterns for all AWS SDK operations

Frontend Integration

  • Updated environment.ts with import API endpoint configuration
  • Fixed managed products table to display product titles correctly (name field instead of title)
  • Enabled import functionality in production environment
  • Deployed frontend changes to AWS CloudFront distribution

Additional Scope - Infrastructure and Testing

  • Repository Structure: Maintained consistent folder organization across services
  • Error Handling: Implemented comprehensive error handling with structured logging
  • Security: Configured proper CORS headers and S3 bucket security policies
  • Testing: Verified end-to-end functionality with test CSV files
  • Deployment: Successfully deployed all changes to AWS infrastructure

Link to Import Service API

Base URL: https://i6nl249ace.execute-api.us-east-1.amazonaws.com/prod
Import Endpoint: https://i6nl249ace.execute-api.us-east-1.amazonaws.com/prod/import

API Usage Example

# Get signed URL for CSV upload
curl "https://i6nl249ace.execute-api.us-east-1.amazonaws.com/prod/import?fileName=products.csv"

# Response format
{
  "signedUrl": "https://import-service-bucket-719484290433.s3.us-east-1.amazonaws.com/uploaded/products.csv?X-Amz-Algorithm=...",
  "fileName": "products.csv",
  "s3Key": "uploaded/products.csv",
  "expiresIn": 300
}

Product Schema

CSV Import Format

The import service expects CSV files with the following product schema:

title,description,price,artist,category,genre,year,imageUrl
"Album Name","Album description",29.99,"Artist Name","Category","Genre",2021,"https://example.com/album.jpg"

Product Object Structure (API Response)

{
  "id": "uuid-generated",
  "name": "Album Name",
  "description": "Album description", 
  "price": 29.99,
  "artist": "Artist Name",
  "category": "Category",
  "genre": "Genre",
  "year": 2021,
  "imageUrl": "https://example.com/album.jpg",
  "count": 0,
  "inStock": false
}

Database Tables

  • Products Table: products (partition key: id)
  • Stock Table: stock (partition key: product_id)

Technical Implementation Details

AWS Services Used

  • AWS Lambda: Node.js 20.x runtime for serverless functions
  • Amazon S3: Object storage for CSV files with folder structure
  • API Gateway: REST API endpoint for signed URL generation
  • Amazon CloudFront: CDN for frontend application
  • AWS CDK: Infrastructure as Code deployment
  • AWS IAM: Role-based access control

Key Features Implemented

  • Signed URL Generation: Secure file upload with temporary credentials
  • CSV Parsing: Stream-based processing for memory efficiency
  • File Management: Automated file organization (uploaded → parsed)
  • Error Handling: Comprehensive error responses and logging
  • Frontend Integration: Seamless import workflow in admin interface
  • Security: Proper CORS configuration and S3 bucket policies

Testing and Verification

Test Results

  • ✅ Signed URL generation working correctly
  • ✅ CSV file upload successful
  • ✅ File parsing and processing functional
  • ✅ File movement from uploaded to parsed folder verified
  • ✅ Frontend integration complete
  • ✅ Managed products table displaying titles correctly

Files Modified/Created

infra/
├── lib/import-service/
│   ├── import-service-stack.ts     # CDK stack with S3 and Lambda configuration
│   ├── handler.ts                # Lambda functions (importProductsFile, importFileParser)
│   └── package.json              # Dependencies (csv-parser, AWS SDK)
└── bin/infra.ts                   # Updated with ImportServiceStack instantiation

FE/src/
├── environments/environment.ts        # Import API configuration
└── app/admin/manage-products/
    └── manage-products.component.html  # Fixed title display issue

Deployment Status

  • Backend: All Lambda functions deployed and operational
  • Frontend: Angular application deployed with latest changes
  • Infrastructure: All CloudFormation stacks updated successfully
  • API Endpoints: Live and tested
  • S3 Bucket: Configured with proper event triggers

The import service is now fully operational and ready for the next module where SQS-based product creation will be implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant