--- AWSTemplateFormatVersion: 2010-09-09 Description: > This template deploys the Retail Demo Store Evidently project and features. Parameters: Uid: Type: String Resources: EvidentlyProject: Type: AWS::Evidently::Project Properties: Name: !Ref Uid Description: Retail Demo Store features and experiments FeatureHomeProductRecs: Type: AWS::Evidently::Feature Properties: DefaultVariation: Personalize-UserPersonalization Description: Home page product recommendations EvaluationStrategy: ALL_RULES Name: home_product_recs Project: !Ref EvidentlyProject Variations: - VariationName: FeaturedProducts StringValue: '{"type":"product"}' - VariationName: Personalize-UserPersonalization StringValue: !Sub '{"type":"personalize-recommendations","arn":"arn:${AWS::Partition}:personalize:${AWS::Region}:${AWS::AccountId}:recommender/retaildemostore-recommended-for-you"}' FeatureHomeProductRecsCold: Type: AWS::Evidently::Feature Properties: DefaultVariation: Personalize-PopularItems Description: Home page product recommendations for new/cold users EvaluationStrategy: ALL_RULES Name: home_product_recs_cold Project: !Ref EvidentlyProject Variations: - VariationName: FeaturedProducts StringValue: '{"type":"product"}' - VariationName: Personalize-PopularItems StringValue: !Sub '{"type":"personalize-recommendations","arn":"arn:${AWS::Partition}:personalize:${AWS::Region}:${AWS::AccountId}:recommender/retaildemostore-popular-items"}' FeatureHomeFeaturedRerank: Type: AWS::Evidently::Feature Properties: DefaultVariation: Personalize-PersonalizedRanking Description: Home page featured products carousel EvaluationStrategy: ALL_RULES Name: home_featured_rerank Project: !Ref EvidentlyProject Variations: - VariationName: RankingNoOp StringValue: '{"type":"ranking-no-op"}' - VariationName: Personalize-PersonalizedRanking StringValue: !Sub '{"type":"personalize-ranking","arn":"arn:${AWS::Partition}:personalize:${AWS::Region}:${AWS::AccountId}:campaign/retaildemostore-personalized-ranking"}' FeatureProductDetailRelated: Type: AWS::Evidently::Feature Properties: DefaultVariation: Personalize-Similar-Items Description: Product detail related products carousel EvaluationStrategy: ALL_RULES Name: product_detail_related Project: !Ref EvidentlyProject Variations: - VariationName: ProductsInSameCategory StringValue: '{"type":"product"}' - VariationName: OpenSearchMoreLikeThis StringValue: '{"type":"similar"}' - VariationName: Personalize-Similar-Items StringValue: !Sub '{"type":"personalize-recommendations","arn":"arn:${AWS::Partition}:personalize:${AWS::Region}:${AWS::AccountId}:campaign/retaildemostore-related-items"}' FeatureSearchResults: Type: AWS::Evidently::Feature Properties: DefaultVariation: Personalize-PersonalizedRanking Description: Search control auto-complete EvaluationStrategy: ALL_RULES Name: search_results Project: !Ref EvidentlyProject Variations: - VariationName: RankingNoOp StringValue: '{"type":"ranking-no-op"}' - VariationName: Personalize-PersonalizedRanking StringValue: !Sub '{"type":"personalize-ranking","arn":"arn:${AWS::Partition}:personalize:${AWS::Region}:${AWS::AccountId}:campaign/retaildemostore-personalized-ranking"}' FeatureLiveStreamProductRecs: Type: AWS::Evidently::Feature Properties: DefaultVariation: Personalize-PersonalizedRanking Description: Live stream product recommendations EvaluationStrategy: ALL_RULES Name: live_stream_prod_recommendation Project: !Ref EvidentlyProject Variations: - VariationName: RankingNoOp StringValue: '{"type":"ranking-no-op"}' - VariationName: Personalize-PersonalizedRanking StringValue: !Sub '{"type":"personalize-ranking","arn":"arn:${AWS::Partition}:personalize:${AWS::Region}:${AWS::AccountId}:campaign/retaildemostore-personalized-ranking"}' FeatureLiveStreamProductDiscounts: Type: AWS::Evidently::Feature Properties: DefaultVariation: Personalize-PersonalizedRanking Description: Live stream product discounts EvaluationStrategy: ALL_RULES Name: live_stream_prod_discounts Project: !Ref EvidentlyProject Variations: - VariationName: RankingNoOp StringValue: '{"type":"ranking-no-op"}' - VariationName: Personalize-PersonalizedRanking StringValue: !Sub '{"type":"personalize-ranking","arn":"arn:${AWS::Partition}:personalize:${AWS::Region}:${AWS::AccountId}:campaign/retaildemostore-personalized-ranking"}' EvidentlyCleanupLambdaFunction: Type: AWS::Lambda::Function Properties: Description: 'Retail Demo Store deployment utility function that cancels and deletes experiments to allow project to be fully deleted' Code: ZipFile: | import boto3 import cfnresponse def handler(event, context): print(event) response_data = {} response_status = cfnresponse.SUCCESS try: project_name = event['ResourceProperties']['EvidentlyProjectName'] if event['RequestType'] == 'Delete': evidently = boto3.client('evidently') experiments_stopped = 0 experiments_deleted = 0 paginator = evidently.get_paginator('list_experiments') for paginate_result in paginator.paginate(project = project_name): for experiment in paginate_result['experiments']: if experiment['status'] == 'RUNNING': print(f"Experiment {experiment['name']} is still running; cancelling") evidently.stop_experiment(desiredState='CANCELLED', experiment=experiment['name'], project=project_name ) experiments_stopped += 1 print(f"Deleting experiment {experiment['name']}") evidently.delete_experiment(experiment=experiment['name'], project=project_name ) experiments_deleted += 1 message = f"Stopped {experiments_stopped} experiments and deleted {experiments_deleted} experiments" response_data['Message'] = message else: response_data['Message'] = "Nothing to do for this request type" except Exception as e: print("Error: " + str(e)) response_status = cfnresponse.FAILED response_data['Message'] = "Resource {} failed: {}".format(event['RequestType'], e) cfnresponse.send(event, context, response_status, response_data) Handler: index.handler Runtime: python3.9 Timeout: 120 Role: !GetAtt EvidentlyCleanupLambdaExecutionRole.Arn CustomEvidentlyCleanup: Type: Custom::EvidentlyCleanup DependsOn: [ FeatureHomeProductRecs, FeatureHomeProductRecsCold, FeatureHomeFeaturedRerank, FeatureProductDetailRelated, FeatureSearchResults, FeatureLiveStreamProductRecs, FeatureLiveStreamProductDiscounts ] Properties: ServiceToken: !GetAtt EvidentlyCleanupLambdaFunction.Arn EvidentlyProjectName: !Ref Uid EvidentlyCleanupLambdaExecutionRole: Type: AWS::IAM::Role Properties: AssumeRolePolicyDocument: Version: 2012-10-17 Statement: - Effect: Allow Principal: Service: lambda.amazonaws.com Action: - 'sts:AssumeRole' Policies: - PolicyName: LoggingPolicy PolicyDocument: Version: 2012-10-17 Statement: - Effect: Allow Action: - logs:CreateLogGroup - logs:CreateLogStream - logs:PutLogEvents Resource: '*' - PolicyName: Evidently PolicyDocument: Version: 2012-10-17 Statement: - Effect: Allow Action: - evidently:* Resource: - '*' Outputs: EvidentlyProjectName: Description: Evidently project name Value: !Ref Uid