aws-solutions / qnabot-on-aws

AWS QnABot is a multi-channel, multi-language conversational interface (chatbot) that responds to your customer's questions, answers, and feedback. The solution allows you to deploy a fully functional chatbot across multiple channels including chat, voice, SMS and Amazon Alexa.
https://aws.amazon.com/solutions/implementations/aws-qnabot
Apache License 2.0
389 stars 249 forks source link

Stack fails to deploy when imported in a CDK application #473

Closed awskaran closed 1 year ago

awskaran commented 2 years ago

Describe the bug A clear and concise description of what the bug is.

To Reproduce Create a CDK App and a stack. Add the QnA bot as a stack that imports existing Cfn templates

import os

from aws_cdk import Stack
from aws_cdk import aws_sqs as sqs
from aws_cdk import cloudformation_include as cfn_inc
from constructs import Construct

dirname = os.path.dirname(__file__)

class QnABotStack(Stack):
    def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        cfn_inc.CfnInclude(
            self,
            "rQnATemplate",
            template_file=os.path.join(dirname, "cfn/aws-qnabot-main.template"),
            parameters={
                "DefaultKendraIndexId":"3d5710d0-2882-4ddb-bcea-15ad33acad6d",
                "ElasticSearchNodeCount": "2",
                "Email":"awskaran@amazon.co.uk",
                "Encryption":"ENCRYPTED",
                "FulfillmentConcurrency":"0",
                "KibanaDashboardRetentionMinutes": "43200",
                "LexBotVersion": "LexV2 Only",
                "LexV2BotLocaleIds": "en_GB",
                "PublicOrPrivate": "PRIVATE",
                "Username": "Admin",
                "XraySetting": "TRUE"
            },
            load_nested_stacks=dict(
                ExamplesStack=cfn_inc.CfnIncludeProps(
                    template_file=os.path.join(dirname, "cfn/examples.json")
                ),
                ExportStack=cfn_inc.CfnIncludeProps(
                    template_file=os.path.join(dirname, "cfn/export.json")
                ),
                ImportStack=cfn_inc.CfnIncludeProps(
                    template_file=os.path.join(dirname, "cfn/import.json")
                ),
                TestAllStack=cfn_inc.CfnIncludeProps(
                    template_file=os.path.join(dirname, "cfn/testall.json")
                ),
            ),
        )

Expected behavior Expected all the stacks in the solution to deploy correctly.

Please complete the following information about the solution:

Screenshots Issue 1

Screenshot 2022-06-21 at 14 59 10

Issue 2

Screenshot 2022-06-21 at 12 24 55

Additional context

Issue 1 The issue is caused by cyclic dependency in resources.

The solution is to remove "ESInfo" and updating "ESVar" to return "EMPTY" for "ESArn" & "ESAddress" when "CreateDomain" is false. "CreateDomain" will never be false as its hard-coded to be true and currently user is not able to supply information of existing OpenSearch domain.

Issue 2

Resources "Alexa" and "QNAInvokePermission" depends on resource "FulfillmentLambdaAliaslive" which is not defined. Both "Alexa" and "QNAInvokePermission" use the "FulfillmentLambda" arn to build the function alias although it looks like the function alias is not yet propagated/created.

the solution is to create the alias separately from the lambda function resource.

Below template works aws-qnabot-main.txt

iamcrisb commented 1 year ago

The issue still persists. @awskaran did you encounter any other problem except from these ones?

Trying to figure out if it's worth investing time into cdk with this. thx.

iamcrisb commented 1 year ago

Managed to make this work with the solution provided by @awskaran with a few mentions. The template provided above has a syntax error. Parse it as json and you'll easily find it using any modern code editor.

You'll also have to delete AutoPublishAlias & AutoPublishCodeSha256 from Resources/FulfillmentLambda/Properties

fbanespo1 commented 1 year ago

I am interested in this solution - Is there any entrypoint script? Is this inside a cdk app directory? Thanks Tony