Skip to content

haandol/personalize-pipeline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Amazon Personalize Pipeline

Manage resources of Amazon Personalize using API Gateway

Running this repository may cost you to provision AWS resources

Prerequisites

  • awscli
  • Nodejs 14+
  • Python 3.10+
  • AWS Account and Locally configured AWS credential

Installation

Install project dependencies

$ cd infra
$ npm i

Install cdk in global context and run cdk bootstrap if you did not initailize cdk yet.

$ npm i -g cdk@2.97.1
$ cdk bootstrap

Deploy CDK Stacks on AWS

$ cdk deploy "*" --require-approval never

API Specification

APIs provided this repository are self-documented using API Gateway Models.

  1. Export Swagger your API specification on API Gateway Console

  1. place it at swagger/swagger.json

  2. Run Swagger UI using Docker

$ docker-compose up
  1. Visit localhost:80

Usage

  1. Verify your email on Amazon SES Console

If you are not yet request increasing SES limitation, you can only send email to verified email.

  1. open /infra/config/dev.toml and replace values for your environment

  2. copy dev.toml file under infra folder with name .toml

$ cd infra
$ cp config/dev.toml .toml
  1. Generate csv file by following intructions of Amazon Personalize Samples

  2. Upload csv file to S3 Bucket

Create Similarity Items campaign

  1. Create Schema
$ http post https://xyxyxy.execute-api.ap-northeast-2.amazonaws.com/dev/schema name=my-demo-schema schema={"type": "record", "name": "Interactions", "namespace": "com.amazonaws.personalize.schema", "fields": [{"name": "USER_ID", "type": "string"}, {"name": "ITEM_ID", "type": "string"}, {"name": "TIMESTAMP", "type": "long"}], "version": "1.0"}
  1. Invoke api to create Personalize Similar-Items campaign
$ http post https://xyxyxy.execute-api.ap-northeast-2.amazonaws.com/dev/similar-items name=my-similar-items-model schema="arn:aws:personalize:ap-northeast-2:776556808198:schema/my-demo-schema" bucket="s3://demo-similar-items-67914/DEMO-similar-items.csv"

Invoke API to get recommendations

  1. Invoke api to get list of campaign_arn and copy your campaign arn
$ http post https://xyxyxy.execute-api.ap-northeast-2.amazonaws.com/dev/campaigns
  1. Invoke api to get recommendations realtime
$ http post https://xyxyxy.execute-api.ap-northeast-2.amazonaws.com/dev/recommend/similar-items  campaign_arn=arn:aws:personalize:ap-northeast-2:929831892372:campaign/my-similar-items-model
 item_id=323
  1. Invoke api to get recommendations in batch
$ http post https://xyxyxy.execute-api.ap-northeast-2.amazonaws.com/dev/batch-inference name=my-batch-job solution_version_arn=arn:aws:personalize:ap-northeast-2:929831892372:solution/my-similar-items-model/84e322ff num_results=150 input_path="s3://demo-similar-items-67914/batch/input.json" output_path="s3://demo-similar-items-67914/batch/output/"

Put events

  1. Get tracking id for dataset group
$ http get http post https://xyxyxy.execute-api.ap-northeast-2.amazonaws.com/dev/tracking name==user-personalization-baseline
  1. Put event via API Gateway
http post https://xyxyxy.execute-api.ap-northeast-2.amazonaws.com/dev/events tracking_id=a6006e6f-8623-4684-bda4-33bec98aade9 session_id=user-personalization-session-1 event_type=click user_id=242 item_id=88 sent_at=1596258382

Cleanup Resources

  1. Invoke api to remove dataset-group
$ http post https://xyxyxy.execute-api.ap-northeast-2.amazonaws.com/dev/cleanup name=my-similar-items-model

Cleanup

destroy provisioned cloud resources

$ cdk destroy "*"