Skip to content

Commit

Permalink
Region check for Personalize content generator (#568)
Browse files Browse the repository at this point in the history
  • Loading branch information
james-jory committed Apr 9, 2024
1 parent 1d67ab0 commit 287b27f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 26 deletions.
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ A sample retail web application and workshop platform intended as an educational

> [!NOTE]
> Jump directly to a section of the documentation:
>
>
> * [How to deploy an instance in your account ](#Deployment)
> * [Hands-on Workshops](#hands-on-workshops)
> * [Partner Integrations](#partner-integrations)
Expand All @@ -32,27 +32,29 @@ The architecture is supported by several managed services including [Amazon Cogn

## Deployment

> [!NOTE]
> [!NOTE]
> To deploy to your own AWS account please follow the [Deployment Instructions](./Deployment-Instructions.md) that will explain how to easily get started by staging the retail demo store to your own AWS account.
> [!WARNING]
> [!WARNING]
> Deploying this demo application in your AWS account will create and consume AWS resources, which will cost money. In addition, some features such as account registration via Amazon Cognito and the messaging workshop for Amazon Pinpoint require users to provide a valid email address and optionally a phone number to demonstrate completely. Therefore, to avoid ongoing charges and to clean up all data, be sure to follow all workshop clean up instructions and shutdown/remove all resources by deleting the CloudFormation stack once you are finished.
> [!IMPORTANT]
> [!IMPORTANT]
> The Retail Demo Store experience is for demonstration purposes only. You must comply with all applicable laws and regulations, including any laws and regulations related to email or text marketing, in any applicable country or region.

## Supported Regions

The Retail Demo Store has been tested in the AWS regions indicated in the deployment instructions below.

The Retail Demo Store has been tested in the AWS regions indicated in the deployment instructions below.

| Region | Supported |
| ------------- | ------------- |
| us-east-1 | fully-supported |
| us-west-2 | fully-supported |
| ap-northeast-1 | fully-supported |

| Region Name | Region | Supported |
| ------------- | ------------- | ------------- |
| US East (N. Virginia) | us-east-1 | Fully supported |
| US West (Oregon) | us-west-2 | Fully supported |
| Europe (Ireland) | eu-west-1 | Partial support (personalized product descriptions and thematic similar product descriptions not supported) |
| Europe (Frankfurt) | eu-central-1 | Partial support (thematic similar product descriptions not supported) |
| Asia Pacific (Tokyo) | ap-northeast-1 | Partial support (personalized product descriptions not supported) |
| Asia Pacific (Sydney) | ap-southeast-2 | Partial support (personalized product descriptions and thematic similar product descriptions not supported) |

> [Note]
> Additional regions may be supported depending on [service availability](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/) and having the Retail Demo Store's deployment resources staged to an S3 bucket in the targeted region.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@
# Info on CloudWatch event rule used to repeatedely call this function.
lambda_event_rule_name = os.environ['lambda_event_rule_name']

# Currently supported regions for Personalize Content Generator: https://docs.aws.amazon.com/personalize/latest/dg/themed-batch-recommendations.html#themes-regions
CONTENT_GENERATOR_REGIONS = [ "us-east-1", "us-west-2", "ap-northeast-1" ]

items_schema = {
"type": "record",
"name": "Items",
Expand Down Expand Up @@ -692,9 +695,12 @@ def get_featured_product_ids() -> List[str]:
def create_theme_generation_job(solution_conf: Dict, include_category_filter_arn: str) -> Tuple[str, bool]:
theme_job_exists = False

job_name = "retaildemostore-related-items-theme-job"
similar_items_solution_version_arn = solution_conf["solutionVersionArn"]

solution_version_name = similar_items_solution_version_arn.split('/')[-1]
# Create job name that incudes the SV name so avoid name colisions with old batch inference jobs
job_name = f"retaildemostore-related-items-theme-job-{solution_version_name}"

paginator = personalize.get_paginator('list_batch_inference_jobs')
for paginate_result in paginator.paginate(solutionVersionArn = similar_items_solution_version_arn):
for job in paginate_result['batchInferenceJobs']:
Expand Down Expand Up @@ -1014,25 +1020,28 @@ def update() -> bool:
else:
raise e

# Create theme batch inference jobs
# Run batch inference jobs
all_batch_inf_active = True
if all_svs_active and all_filters_active:
for solution_conf in dataset_group_conf.get('solutions', []):
if solution_conf.get("generateFeaturedProductThemes", False):
filter_arn = None
for filter_conf in dataset_group_conf["filters"]:
if filter_conf["name"] == "retaildemostore-filter-same-categories":
filter_arn = filter_conf["arn"]
break

_,job_created = create_theme_generation_job(solution_conf, filter_arn)
if job_created:
all_batch_inf_active = False
elif solution_conf['themeJobStatus'] == 'ACTIVE':
output_file = download_batch_inference_output(solution_conf)
update_products_with_themes(output_file)
if region in CONTENT_GENERATOR_REGIONS:
filter_arn = None
for filter_conf in dataset_group_conf["filters"]:
if filter_conf["name"] == "retaildemostore-filter-same-categories":
filter_arn = filter_conf["arn"]
break

_,job_created = create_theme_generation_job(solution_conf, filter_arn)
if job_created:
all_batch_inf_active = False
elif solution_conf['themeJobStatus'] == 'ACTIVE':
output_file = download_batch_inference_output(solution_conf)
update_products_with_themes(output_file)
else:
all_batch_inf_active = False
else:
all_batch_inf_active = False
logger.warn("Personalize content generator not supported in the current region (%s); skipping (https://docs.aws.amazon.com/personalize/latest/dg/themed-batch-recommendations.html#themes-regions)", region)

if all_recs_active and all_svs_active and all_campaigns_active and event_tracker_active and all_filters_active and all_batch_inf_active:
# All resources are active for the DSG. Set SSM params for filters, recommenders, and campaigns
Expand Down

0 comments on commit 287b27f

Please sign in to comment.