AWS CloudFormation 템플릿을 통해 Amazon Lex 봇 관리 | 아마존 웹 서비스

AWS CloudFormation 템플릿을 통해 Amazon Lex 봇 관리 | 아마존 웹 서비스

아마존 렉스 애플리케이션에서 대화형 인터페이스를 설계, 구축, 테스트 및 배포하기 위한 고급 자연어 모델을 갖춘 완전 관리형 인공 지능(AI) 서비스입니다. 고급 딥 러닝 기술을 사용하여 사용자 입력을 이해하므로 개발자는 자연어로 사용자와 상호 작용할 수 있는 챗봇, 가상 비서 및 기타 애플리케이션을 만들 수 있습니다.

다음을 사용하여 Amazon Lex 봇 관리 AWS 클라우드 포메이션 봇과 봇이 의존하는 모든 AWS 리소스를 정의하는 템플릿을 생성할 수 있습니다. AWS CloudFormation은 사용자를 대신하여 이러한 리소스를 제공하고 구성하여 새로운 환경에 봇을 배포할 때 인적 오류가 발생할 위험을 제거합니다. CloudFormation을 사용하면 다음과 같은 이점이 있습니다.

  • 일관성 – CloudFormation 템플릿은 Amazon Lex 봇과 관련된 리소스를 배포하고 관리하는 보다 일관되고 자동화된 방법을 제공합니다.
  • 버전 관리 – AWS CloudFormation을 사용하면 Git과 같은 버전 제어 시스템을 사용하여 CloudFormation 템플릿을 관리할 수 있습니다. 이를 통해 봇의 다양한 버전을 유지 관리하고 필요한 경우 이전 버전으로 롤백할 수 있습니다.
  • 재사용 성 – 개발, 스테이징, 프로덕션 등 여러 환경에서 CloudFormation 템플릿을 재사용할 수 있습니다. 이렇게 하면 다양한 환경에서 동일한 봇을 정의하는 데 드는 시간과 노력이 절약됩니다.
  • 확장성 – Amazon Lex 봇이 복잡해짐에 따라 AWS 관리 콘솔 더욱 어려워집니다. AWS CloudFormation을 사용하면 봇의 정의와 리소스를 관리하는 데 더욱 간편하고 효율적인 접근 방식이 가능합니다.
  • 자동화 – CloudFormation 템플릿을 사용하면 배포 프로세스를 자동화할 수 있습니다. 다음과 같은 AWS 서비스를 사용할 수 있습니다. AWS 코드 파이프라인AWS 코드빌드 Amazon Lex 봇을 자동으로 구축, 테스트 및 배포합니다.

이 게시물에서는 Amazon Lex V2 봇용 CloudFormation 템플릿을 생성하는 단계를 안내합니다.

솔루션 개요

우리는 선택했다 도서 여행 이 연습의 시작점은 봇입니다. 우리는 CloudFormation 템플릿을 사용하여 의도, 슬롯 및 기타 필수 구성 요소 정의를 포함하여 처음부터 새로운 봇을 생성합니다. 또한 버전 제어, 별칭, 통합과 같은 주제를 탐구합니다. AWS 람다 함수, 조건부 분기 생성, 로깅 활성화 등이 있습니다.

사전 조건

다음과 같은 전제 조건이 있어야 합니다.

  • An AWS 계정 CloudFormation 템플릿 생성 및 배포
  • 필요한 것 AWS 자격 증명 및 액세스 관리 (나는) 권한 AWS CloudFormation 및 템플릿에 사용되는 리소스를 배포합니다.
  • Amazon Lex, Lambda 함수 및 관련 서비스에 대한 기본 지식
  • CloudFormation 템플릿 생성 및 배포에 대한 기본 지식

IAM 역할 생성

시작하려면 봇이 사용할 IAM 역할을 생성해야 합니다. CloudFormation 템플릿을 초기화하고 IAM 역할을 리소스로 추가하면 이를 달성할 수 있습니다. 다음 템플릿을 사용하여 역할을 생성할 수 있습니다. 만약 너라면 예제 템플릿 다운로드 배포하면 IAM 역할이 생성된 것을 볼 수 있습니다. 이 게시물을 진행하면서 템플릿의 예를 제공하고 계속 진행하면서 템플릿을 병합합니다.

AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: CloudFormation template for book hotel bot.
Resources:
  # 1. IAM role that is used by the bot at runtime
  BotRuntimeRole:    
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Effect: Allow
            Principal:
              Service:
                - lexv2.amazonaws.com
            Action:
              - "sts:AssumeRole"
      Path: "/"
      Policies:
        - PolicyName: LexRuntimeRolePolicy
          PolicyDocument:
            Version: 2012-10-17
            Statement:
              - Effect: Allow
                Action:
                  - "polly:SynthesizeSpeech"
                  - "comprehend:DetectSentiment"
                Resource: "*"

Amazon Lex 봇 구성

다음으로 봇 정의를 추가해야 합니다. 다음은 Amazon Lex 봇 정의를 위한 YAML 템플릿입니다. 필요한 구성 요소를 하나씩 구성합니다.

Type: AWS::Lex::Bot
Properties:
  AutoBuildBotLocales: Boolean
  BotFileS3Location: 
    S3Location
  BotLocales: 
    - BotLocale
  BotTags: 
    - Tag
  DataPrivacy: 
    DataPrivacy
  Description: String
  IdleSessionTTLInSeconds: Integer
  Name: String
  RoleArn: String
  TestBotAliasSettings: 
    TestBotAliasSettings
  TestBotAliasTags: 
    - Tag

의도 없이 봇 정의만 포함하는 봇을 생성하려면 다음 템플릿을 사용할 수 있습니다. 여기서는 봇 이름, 이전에 생성한 역할의 ARN, 데이터 개인 정보 보호 설정 등을 지정합니다.

BookHotelBot:
    DependsOn: BotRuntimeRole # The role created in the previous step
    Type: AWS::Lex::Bot
    Properties:
      Name: "BookHotel"
      Description: "Sample Bot to book a hotel"
      RoleArn: !GetAtt BotRuntimeRole.Arn      
      #For each Amazon Lex bot created with the Amazon Lex Model Building Service, you must specify whether your use of Amazon Lex 
      #is related to a website, program, or other application that is directed or targeted, in whole or in part, to children under 
      #age 13 and subject to the Children's Online Privacy Protection Act (COPPA) by specifying true or false in the 
      #childDirected field.
      DataPrivacy:
        ChildDirected: false
      IdleSessionTTLInSeconds: 300

여러분의 시간과 재능으로 업데이트된 템플릿을 다운로드하세요. 업데이트된 템플릿을 배포하면 역할과 봇 정의를 모두 생성할 수 있습니다. 당신은 스택 업데이트 중 이전 단계에서 생성했습니다.

마지막 단계에서는 BotLocales봇 기능의 대부분을 구성합니다. 여기에는 예를 들어 다음이 포함됩니다. IntentsSlot types. 다음은 YAML 템플릿입니다.

  CustomVocabulary: 
    CustomVocabulary
  Description: String
  Intents: 
    - Intent
  LocaleId: String
  NluConfidenceThreshold: Number
  SlotTypes: 
    - SlotType
  VoiceSettings: 
    VoiceSettings

이 경우에는 BookHotel 이는 객실 유형에 대한 사용자 정의 슬롯 유형이 필요합니다. 당신은 LocaleId, 그 다음에 VoiceSettings. 그런 다음 SlotTypes 그리고 그에 상응하는 값.

다음 단계는 Intents, 첫 번째 인텐트부터 시작하여 BookHotel, 여기에는 발화, 슬롯 및 슬롯 우선순위를 추가하는 작업이 포함됩니다. 이러한 노드의 세부정보는 제공된 템플릿에 설명되어 있습니다. 마지막으로 두 번째 인텐트를 추가합니다. FallbackIntent. 다음 코드를 참조하십시오.

BotLocales:
        - LocaleId: "en_US"
          Description: "en US locale"
          NluConfidenceThreshold: 0.40
          VoiceSettings:
            VoiceId: "Matthew"
          SlotTypes:
            - Name: "RoomTypeValues"
              Description: "Type of room"
              SlotTypeValues:
                - SampleValue:
                    Value: queen
                - SampleValue:
                    Value: king
                - SampleValue:
                    Value: deluxe
              ValueSelectionSetting:
                ResolutionStrategy: ORIGINAL_VALUE
          Intents:
            - Name: "BookHotel"
              Description: "Intent to book a hotel room"
              SampleUtterances:
                - Utterance: "Book a hotel"
                - Utterance: "I want a make hotel reservations"
                - Utterance: "Book a {Nights} night stay in {Location}"
              IntentConfirmationSetting:
                PromptSpecification:
                  MessageGroupsList:
                    - Message:
                        PlainTextMessage:
                          Value: "Okay, I have you down for a {Nights} night stay in {Location} starting {CheckInDate}.  Shall I book the reservation?"
                  MaxRetries: 3
                  AllowInterrupt: false
                DeclinationResponse:
                  MessageGroupsList:
                    - Message:
                        PlainTextMessage:
                          Value: "Okay, I have cancelled your reservation in progress."
                  AllowInterrupt: false
              SlotPriorities:
                - Priority: 1
                  SlotName: Location
                - Priority: 2
                  SlotName: CheckInDate
                - Priority: 3
                  SlotName: Nights
                - Priority: 4
                  SlotName: RoomType
              Slots:
                - Name: "Location"
                  Description: "Location of the city in which the hotel is located"
                  SlotTypeName: "AMAZON.City"
                  ValueElicitationSetting:
                    SlotConstraint: "Required"
                    PromptSpecification:
                      MessageGroupsList:
                        - Message:
                            PlainTextMessage:
                              Value: "What city will you be staying in?"
                      MaxRetries: 2
                      AllowInterrupt: false
                - Name: "CheckInDate"
                  Description: "Date of check-in"
                  SlotTypeName: "AMAZON.Date"
                  ValueElicitationSetting:
                    SlotConstraint: "Required"
                    PromptSpecification:
                      MessageGroupsList:
                        - Message:
                            PlainTextMessage:
                              Value: "What day do you want to check in?"
                      MaxRetries: 2
                      AllowInterrupt: false
                - Name: "Nights"
                  Description: "something"
                  SlotTypeName: "AMAZON.Number"
                  ValueElicitationSetting:
                    SlotConstraint: "Required"
                    PromptSpecification:
                      MessageGroupsList:
                        - Message:
                            PlainTextMessage:
                              Value: "How many nights will you be staying?"
                      MaxRetries: 2
                      AllowInterrupt: false
                - Name: "RoomType"
                  Description: "Enumeration of types of rooms that are offered by a hotel."
                  SlotTypeName: "RoomTypeValues"
                  ValueElicitationSetting:
                    SlotConstraint: "Required"
                    PromptSpecification:
                      MessageGroupsList:
                        - Message:
                            PlainTextMessage:
                              Value: "What type of room would you like, queen, king or deluxe?"
                      MaxRetries: 2
                      AllowInterrupt: false
            - Name: "FallbackIntent"
              Description: "Default intent when no other intent matches"
              ParentIntentSignature: "AMAZON.FallbackIntent"

여러분의 시간과 재능으로 CloudFormation 템플릿 다운로드 지금까지 한 일 때문에. 당신 후 스택을 업데이트하세요 이 템플릿을 사용하면 기능적인 봇이 배포됩니다. Amazon Lex 콘솔에서 봇의 초안 버전과 이름이 지정된 기본 별칭이 있는지 확인할 수 있습니다. TestBotAlias 이 생성되었습니다.

봇 별칭

새 봇 버전 및 별칭 만들기

Amazon Lex는 게시를 지원합니다. 버전 클라이언트 애플리케이션의 구현을 제어할 수 있도록 봇, 인텐트, 슬롯 유형을 제어합니다. 버전은 개발, 베타 배포, 프로덕션 등 워크플로의 다양한 부분에서 사용하기 위해 게시할 수 있는 봇 정의의 번호가 매겨진 스냅샷입니다. Amazon Lex 봇도 지원합니다. 별칭. 별칭은 특정 버전의 봇을 가리키는 포인터입니다. 별칭을 사용하면 클라이언트 애플리케이션 버전을 업데이트할 수 있습니다. 실제 시나리오에서 봇 별칭은 블루/그린 배포와 개발 및 프로덕션 환경과 같은 환경별 구성 관리에 사용됩니다.

설명을 위해 봇 버전 1에 대한 별칭을 지정한다고 가정해 보겠습니다. 봇을 업데이트할 때가 되면 버전 2를 게시하고 새 버전을 가리키도록 별칭을 변경할 수 있습니다. 애플리케이션이 특정 버전 대신 별칭을 사용하기 때문에 모든 클라이언트는 업데이트 없이도 새 기능을 받습니다.

CloudFormation 템플릿을 수정하고 배포를 시작하면 변경 사항은 주로 테스트용으로 초안 버전 내에서 구현됩니다. 테스트 단계를 완료한 후 새 버전을 설정하여 지금까지 통합한 변경 사항을 마무리할 수 있습니다.

다음으로 초안을 기반으로 새 봇 버전을 만들고, 새 별칭을 설정하고, 버전을 이 별칭에 연결합니다. 다음은 템플릿에 추가할 두 가지 새로운 리소스입니다.

BookHotelInitialVersion:
    DependsOn: BookHotelBot
    Type: AWS::Lex::BotVersion
    Properties:
      BotId: !Ref BookHotelBot
      BotVersionLocaleSpecification:
        - LocaleId: en_US
          BotVersionLocaleDetails:
            SourceBotVersion: DRAFT
      Description: Hotel Bot initial version

  BookHotelDemoAlias:
    Type: AWS::Lex::BotAlias
    Properties:
      BotId: !Ref BookHotelBot
      BotAliasName: "BookHotelDemoAlias"
      BotVersion: !GetAtt BookHotelInitialVersion.BotVersion

여러분의 시간과 재능으로 새 버전의 템플릿을 다운로드하세요. 스택을 업데이트하여 배포하세요. Amazon Lex 콘솔에서 새 버전이 생성되고 다음과 같은 새 별칭과 연결되는 것을 볼 수 있습니다. BookHotelDemoAlias.

데모 별칭

Amazon Lex 봇의 새 버전을 생성하면 일반적으로 버전 번호가 1부터 시작하여 순차적으로 증가합니다. 특정 버전을 식별하려면 해당 설명을 참조할 수 있습니다.

초기 버전

Lambda 함수 추가

봇에 대한 값을 초기화하거나 사용자 입력의 유효성을 검사하려면 Lambda 함수를 봇에 코드 후크로 추가하면 됩니다. 마찬가지로 이행을 위해 Lambda 함수를 사용할 수도 있습니다. 예를 들어 데이터베이스에 데이터를 쓰거나 API를 호출하면 수집된 정보가 저장됩니다. 자세한 내용은 다음을 참조하세요. AWS Lambda 함수로 사용자 지정 로직 활성화.

CloudFormation 템플릿에 Lambda 함수에 대한 새 리소스를 추가해 보겠습니다. 일반적으로 CloudFormation 템플릿에 코드를 포함하는 것은 권장되지 않지만 여기서는 데모 배포를 덜 복잡하게 만들기 위한 목적으로만 그렇게 합니다. 다음 코드를 참조하세요.

HotelBotFunction:
    DependsOn: BotRuntimeRole # So that the Lambda function is ready before the bot deployment
    Type: AWS::Serverless::Function
    Properties:
      FunctionName: book_hotel_lambda
      Runtime: python3.11
      Timeout: 15
      Handler: index.lambda_handler
      InlineCode: |
        import os
        import json

        def close(intent_request):
            intent_request['sessionState']['intent']['state'] = 'Fulfilled'

            message = {"contentType": "PlainText",
                      "content": "Your Booking is confirmed"}

            session_attributes = {}
            sessionState = intent_request['sessionState']
            if 'sessionAttributes' in sessionState:
                session_attributes = sessionState['sessionAttributes']

            requestAttributes = None
            if 'requestAttributes' in intent_request:
                requestAttributes = intent_request['requestAttributes']

            return {
                'sessionState': {
                    'sessionAttributes': session_attributes,
                    'dialogAction': {
                        'type': 'Close'
                    },
                    'intent': intent_request['sessionState']['intent'],
                    'originatingRequestId': 'xxxxxxx-xxxx-xxxx-xxxx'
                },
                'messages':  [message],
                'sessionId': intent_request['sessionId'],
                'requestAttributes': requestAttributes
            }

        def router(event):
            intent_name = event['sessionState']['intent']['name']
            slots = event['sessionState']['intent']['slots']
            if (intent_name == 'BookHotel'):
                # invoke lambda and return result
                return close(event)

            raise Exception(
                'The intent is not supported by Lambda: ' + intent_name)

        def lambda_handler(event, context):
            response = router(event)
            return response

이행을 위해 이 Lambda 함수를 사용하려면 의도에서 코드 후크 설정을 활성화합니다.

Intents:
  - Name: "BookHotel"
    Description: "Intent to book a hotel room"
    FulfillmentCodeHook:
      Enabled: true
    SampleUtterances:
      - Utterance: "Book a hotel"
      - Utterance: "I want a make hotel reservations"
      - Utterance: "Book a {Nights} night stay in {Location}"

봇을 변경했으므로 다음과 같은 새 리소스를 추가하여 봇의 새 버전을 생성할 수 있습니다. BookHotelVersionWithLambda 템플릿에서:

BookHotelVersionWithLambda:
    DependsOn: BookHotelInitialVersion
    Type: AWS::Lex::BotVersion
    Properties:
      BotId: !Ref BookHotelBot
      BotVersionLocaleSpecification:
        - LocaleId: en_US
          BotVersionLocaleDetails:
            SourceBotVersion: DRAFT
      Description: Hotel Bot with a lambda function

Lambda 함수는 봇 별칭과 연결되어 있습니다. Amazon Lex V2는 언어당 봇 별칭당 하나의 Lambda 함수를 사용할 수 있습니다. 따라서 Lambda 함수 리소스를 추가하려면 템플릿에서 별칭을 업데이트해야 합니다. 다음에서 그렇게 할 수 있습니다. BotAliasLocalSettings 부분. 또한 생성한 새 버전을 별칭으로 가리켜야 합니다. 다음 코드는 수정된 별칭 구성입니다.

  BookHotelDemoAlias:
    Type: AWS::Lex::BotAlias
    Properties:
      BotId: !Ref BookHotelBot
      BotAliasName: "BookHotelDemoAlias"
      BotVersion: !GetAtt BookHotelVersionWithLambda.BotVersion
      # Remove BotAliasLocaleSettings if you aren't concerned with Lambda setup.
      # If you are you can modify the LambdaArn below to get started.
      BotAliasLocaleSettings:
        - LocaleId: en_US
          BotAliasLocaleSetting:
            Enabled: true
            CodeHookSpecification:
              LambdaCodeHook:
                CodeHookInterfaceVersion: "1.0"
                LambdaArn: !GetAtt HotelBotFunction.Arn

지금까지는 Lambda 함수를 별칭과 연결하기만 했습니다. 그러나 별칭이 Lambda 함수를 호출할 수 있도록 권한을 부여해야 합니다. 다음 코드에서는 Amazon Lex에 대한 Lambda 호출 권한을 추가하고 별칭 ARN을 소스 ARN으로 지정합니다.

  LexInvokeLambdaPermission:
    Type: AWS::Lambda::Permission
    Properties:
      Action: "lambda:InvokeFunction"
      FunctionName: !GetAtt HotelBotFunction.Arn
      Principal: "lexv2.amazonaws.com"
      SourceArn: !GetAtt BookHotelDemoAlias.Arn

여러분의 시간과 재능으로 최신 버전 다운로드 템플릿의 이 버전으로 스택을 업데이트하면 Amazon Lex 봇이 Lambda 함수와 통합됩니다.

두 번째 버전

업데이트된 알리스

조건부 분기

이제 Amazon Lex 봇의 조건부 분기 기능을 살펴보고 다음 주 동안 시애틀에서 5박 이상 예약이 허용되지 않는 시나리오를 고려해 보겠습니다. 비즈니스 요구 사항에 따라 사용자가 시애틀에서 5박 이상 예약을 시도하는 경우 대화는 적절한 메시지로 끝나야 합니다. 이에 대한 조건부 분기는 CloudFormation 템플릿 아래에 표시됩니다. SlotCaptureSetting:

- Name: "Nights"
                  Description: “Number of nights.”
                  SlotTypeName: "AMAZON.Number"
                  ValueElicitationSetting:
                    SlotConstraint: "Required"
                    SlotCaptureSetting:
                      CaptureConditional:
                        DefaultBranch:
                          NextStep:
                            DialogAction:
                              Type: "ElicitSlot"
                              SlotToElicit: "RoomType"
                        ConditionalBranches:
                          - Name: "Branch1"
                            Condition:
                              ExpressionString: '{Nights}>5 AND {Location} = "Seattle"'
                            Response:
                              AllowInterrupt: true
                              MessageGroupsList:
                                - Message:
                                    PlainTextMessage:
                                      Value: “Sorry, we cannot book more than five nights in {Location} right now."
                            NextStep:
                              DialogAction:
                                Type: "EndConversation"
                        IsActive: true

                    PromptSpecification:
                      MessageGroupsList:
                        - Message:
                            PlainTextMessage:
                              Value: "How many nights will you be staying?"
                      MaxRetries: 2
                      AllowInterrupt: false

봇 정의를 변경했으므로 템플릿에 새 버전을 생성하고 이를 별칭과 연결해야 합니다. 해당 업체는 곧 시애틀에서 대규모 예약을 허용할 계획이므로 이는 일시적인 수정입니다. 다음은 템플릿에 추가하는 두 가지 새로운 리소스입니다.

BookHotelConditionalBranches:
    DependsOn: BookHotelVersionWithLambda
    Type: AWS::Lex::BotVersion
    Properties:
      BotId: !Ref BookHotelBot
      BotVersionLocaleSpecification:
        - LocaleId: en_US
          BotVersionLocaleDetails:
            SourceBotVersion: DRAFT
      Description: Hotel Bot Version with conditional branches

  BookHotelDemoAlias:
    Type: AWS::Lex::BotAlias
    Properties:
      BotId: !Ref BookHotelBot
      BotAliasName: "BookHotelDemoAlias"
      BotVersion: !GetAtt BookHotelConditionalBranches.BotVersion
      # Remove BotAliasLocaleSettings if you aren't concerned with Lambda setup.
      # If you are you can modify the LambdaArn below to get started.
      BotAliasLocaleSettings:
        - LocaleId: en_US
          BotAliasLocaleSetting:
            Enabled: true
            CodeHookSpecification:
              LambdaCodeHook:
                CodeHookInterfaceVersion: "1.0"
                LambdaArn: !GetAtt HotelBotFunction.Arn

여러분의 시간과 재능으로 업데이트된 템플릿을 다운로드하세요. 이 템플릿 버전으로 스택을 업데이트하면 별칭은 조건부 분기 기능을 통합하는 버전으로 이동됩니다. 이 수정 사항을 실행 취소하려면 별칭을 업데이트하여 이전 버전으로 되돌릴 수 있습니다.

세 번째 버전

세 번째 버전의 별칭

로그

Amazon Lex 봇에 대한 로그를 활성화할 수도 있습니다. 이렇게 하려면 쓰기 권한을 부여하도록 봇의 역할을 업데이트해야 합니다. 아마존 클라우드 워치 로그. 다음은 역할에 CloudWatch 정책을 추가하는 예입니다.

BotRuntimeRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Effect: Allow
            Principal:
              Service:
                - lexv2.amazonaws.com
            Action:
              - "sts:AssumeRole"
      Path: "/"
      Policies:
        - PolicyName: LexRuntimeRolePolicy
          PolicyDocument:
            Version: 2012-10-17
            Statement:
              - Effect: Allow
                Action:
                  - "polly:SynthesizeSpeech"
                  - "comprehend:DetectSentiment"
                Resource: "*"
        - PolicyName: CloudWatchPolicy
          PolicyDocument:
            Version: 2012-10-17
            Statement:
              - Effect: Allow
                Action:
                  - "logs:CreateLogStream"
                  - "logs:PutLogEvents"
                Resource: "*"

일관되고 예측 가능한 동작을 보장하려면 CloudFormation 템플릿에서 리소스 이름과 속성을 정의할 때 최대한 구체적이어야 합니다. CloudFormation 템플릿에서 와일드카드 문자(*)를 사용하면 잠재적인 보안 위험이 발생하고 의도하지 않은 결과가 발생할 수 있기 때문입니다. 따라서 와일드카드 사용을 피하고 가능하면 명시적인 값을 사용하는 것이 좋습니다.

다음으로, 다음 코드에 표시된 대로 CloudWatch 로그 그룹 리소스를 생성하여 로그를 이 그룹으로 보냅니다.

  #Log Group
  LexLogGroup:
    Type: AWS::Logs::LogGroup
    Properties:
      LogGroupName: /lex/hotel-bot
      RetentionInDays: 5

마지막으로 별칭을 업데이트하여 대화 로그 설정을 활성화합니다.

BookHotelDemoAlias:
    Type: AWS::Lex::BotAlias
    Properties:
      BotId: !Ref BookHotelBot
      BotAliasName: "BookHotelDemoAlias"
      BotVersion: !GetAtt BookHotelConditionalBranches.BotVersion
      BotAliasLocaleSettings:
        - LocaleId: en_US
          BotAliasLocaleSetting:
            Enabled: true
            CodeHookSpecification:
              LambdaCodeHook:
                CodeHookInterfaceVersion: "1.0"
                LambdaArn: !GetAtt HotelBotFunction.Arn
      ConversationLogSettings:
        TextLogSettings:
          - Destination:
              CloudWatch:
                CloudWatchLogGroupArn: !GetAtt LexLogGroup.Arn
                LogPrefix: bookHotel
            Enabled: true

이 템플릿으로 스택을 업데이트하면 봇에 대한 대화 로그가 활성화됩니다. 봇 리소스에 대한 변경 사항이 없으므로 이 단계에서는 새 버전이 생성되지 않습니다. 당신은 할 수 있습니다 최신 버전의 템플릿을 다운로드하세요..

정리

향후 요금이 발생하지 않도록 생성한 CloudFormation 스택을 삭제하세요.

결론

이 게시물에서는 Amazon Lex V2 봇용 CloudFormation 템플릿을 생성하는 단계별 프로세스에 대해 논의했습니다. 처음에는 기본 봇을 배포한 다음 별칭과 버전의 잠재력과 이를 템플릿과 함께 효율적으로 사용하는 방법을 탐색했습니다. 다음으로, Lambda 함수를 Amazon Lex V2 봇과 통합하고 비즈니스 요구 사항을 수용하기 위해 봇의 대화 흐름에 조건부 분기를 구현하는 방법을 배웠습니다. 마지막으로 CloudWatch 로그 그룹 리소스를 생성하고 필요한 권한으로 봇의 역할을 업데이트하여 로깅 기능을 추가했습니다.

템플릿을 사용하면 필요에 따라 변경 사항을 되돌릴 수 있는 기능을 통해 봇을 간단하게 배포하고 관리할 수 있습니다. 전반적으로 CloudFormation 템플릿은 Amazon Lex V2 봇을 관리하고 최적화하는 데 유용합니다.

다음 단계에서는 다음을 탐색할 수 있습니다. 샘플 Amazon Lex 봇 이 게시물에서 설명한 기술을 적용하여 CloudFormation 템플릿으로 변환합니다. 이 실습을 통해 코드형 인프라를 통해 Amazon Lex V2 봇 관리에 대한 이해가 강화됩니다.


저자에 관하여

AWS CloudFormation 템플릿을 통해 Amazon Lex 봇 관리 | Amazon Web Services PlatoBlockchain 데이터 인텔리전스. 수직 검색. 일체 포함.토마스 린드퍼스 Amazon Lex 팀의 수석 솔루션 설계자입니다. 그는 고객 경험을 개선하고 채택을 용이하게 하는 Language AI 서비스를 위한 새로운 기술 기능과 솔루션을 발명, 개발, 프로토타입 및 복음화합니다.

AWS CloudFormation 템플릿을 통해 Amazon Lex 봇 관리 | Amazon Web Services PlatoBlockchain 데이터 인텔리전스. 수직 검색. 일체 포함.리지쉬 아캄베스 카토스 AWS의 전문 서비스 컨설턴트입니다. 그는 고객이 원하는 비즈니스를 달성하도록 돕습니다.
Amazon Connect, Amazon Lex 및 GenAI 기능을 활용하여 Contact Center 공간에서 결과를 얻을 수 있습니다.

타임 스탬프 :

더보기 AWS 기계 학습