AWSTemplateFormatVersion: 2010-09-09 Description: > Amazon Lex for Banking offers pre-built solutions so you can enable experiences at scale and drive digital engagement. The purpose-built bots provide ready to use conversation flows along with training data and dialog prompts, for both voice and chat modalities. Metadata: AWS::CloudFormation::Interface: ParameterGroups: - Label: default: Amazon DynamoDB parameters Parameters: - DynamoDBTableName Mappings: BucketName: us-east-1: Name: 'ee-assets-prod-us-east-1' S3Path: LexImportSource: Name: 'modules/c16b965656fb4eba8676d6f0ac759300/v1/Lex-KR_BankingBot/Lambda-LexArtifact-Import/LexImport.zip' BusinessLogicSource: Name: 'modules/c16b965656fb4eba8676d6f0ac759300/v1/Lex-KR_BankingBot/Lambda-BizLogic-BankingService/BankingServiceFunction.zip' DBImportSource: Name: 'modules/c16b965656fb4eba8676d6f0ac759300/v1/Lex-KR_BankingBot/Lambda-BizLogic-DynamoDB/DDBInsert.zip' Parameters: BankingServicesBotName: Type: String Description: > Name of the Lex bot for card services Default: BankingServices BankingServicesLambdaFunctionName: Type: String Description: > Name of the Lambda function for validation and fulfilment of card services bot Default: BankingServiceFunction DynamoDBTableName: Type: String Description: > Name of the DynamoDB table that contains the sample policy data Default: BankingBot Resources: LexRole: Type: 'AWS::IAM::Role' Properties: AssumeRolePolicyDocument: Version: "2012-10-17" Statement: - Effect: Allow Principal: Service: - lambda.amazonaws.com Action: - 'sts:AssumeRole' Path: / Policies: - PolicyName: lex_policy PolicyDocument: Version: 2012-10-17 Statement: - Effect: Allow Action: 'polly:SynthesizeSpeech' Resource: '*' LambdaRole: Type: 'AWS::IAM::Role' Properties: AssumeRolePolicyDocument: Version: 2012-10-17 Statement: - Effect: Allow Principal: Service: - lambda.amazonaws.com Action: - 'sts:AssumeRole' Path: / Policies: - PolicyName: !Join [ "_", [ !Ref AWS::StackName, 'LambdaPolicy' ] ] PolicyDocument: Version: 2012-10-17 Statement: - Effect: Allow Action: - 'dynamodb:BatchGetItem' - 'dynamodb:GetItem' - 'dynamodb:Query' - 'dynamodb:Scan' - 'dynamodb:BatchWriteItem' - 'dynamodb:PutItem' - 'dynamodb:UpdateItem' - 'dynamodb:DescribeTable' - "autoscaling:Describe*" - "cloudwatch:*" - "logs:*" - "sns:*" - "iam:GetPolicy" - "iam:GetPolicyVersion" - "iam:GetRole" Resource: !GetAtt DynamoDBTable.Arn # 렉스 봇을 설치시에 사용하는 역할 LexImportRole: Type: 'AWS::IAM::Role' Properties: AssumeRolePolicyDocument: Version: 2012-10-17 Statement: - Effect: Allow Principal: Service: - lambda.amazonaws.com Action: - 'sts:AssumeRole' Path: / ManagedPolicyArns: - arn:aws:iam::aws:policy/AmazonLexFullAccess Policies: - PolicyName: !Join [ "_", [ !Ref AWS::StackName, 'LexImportPolicy' ] ] PolicyDocument: Version: 2012-10-17 Statement: - Effect: Allow Action: - 'lambda:PublishVersion' - 'lambda:AddPermission' - 'lambda:GetFunction' - 'sts:GetCallerIdentity' - 'iam:GetRole' - 'iam:PassRole' Resource: - !Sub arn:aws:lex:${AWS::Region}:${AWS::AccountId}:* - !Sub arn:aws:iam::${AWS::AccountId}:role/* - !Sub arn:aws:lex:${AWS::Region}:${AWS::AccountId}:bot/* - !Sub arn:aws:lex:${AWS::Region}:${AWS::AccountId}:bot-alias/* - !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:* # 렉스 봇을 설치하기 위한 사용자 정의 메인 함수 InvokeLexImportBankingServicesFunction: DependsOn: BankingServicesBusinessLogic Type: Custom::InvokeLexImportBankingServicesFunction Version: '1.0' Properties: ServiceToken: !GetAtt LexImportBankingServicesFunction.Arn RoleARN: !GetAtt LexRole.Arn LambdaFunctionName: !Ref BankingServicesLambdaFunctionName BotName: !Ref BankingServicesBotName # 렉스 봇의 모든 아테펙트 (봇 엘리아스, 인테트 등) 설치하기 위한 람다 함수 LexImportBankingServicesFunction: Type: 'AWS::Lambda::Function' Properties: Code: S3Bucket: !FindInMap [BucketName, !Ref "AWS::Region", 'Name'] S3Key: !FindInMap [S3Path, 'LexImportSource', 'Name'] Handler: lambda_function.lambda_handler Role: !GetAtt - LexImportRole - Arn Runtime: python3.9 FunctionName: !Join [ "_", [ !Ref AWS::StackName, 'LexImportBankingServicesFunction' ] ] MemorySize: 128 Timeout: 300 Environment: Variables: TopicArn: !Ref LexRole # 렉스 봇의 비즈니스 로직을 처리하기 위한 람다 함수 BankingServicesBusinessLogic: Type: 'AWS::Lambda::Function' Properties: Code: S3Bucket: !FindInMap [BucketName, !Ref "AWS::Region", 'Name'] S3Key: !FindInMap [S3Path, 'BusinessLogicSource', 'Name'] Handler: index.handler Role: !GetAtt - LambdaRole - Arn Runtime: nodejs14.x FunctionName: !Ref BankingServicesLambdaFunctionName MemorySize: 128 Timeout: 300 Environment: Variables: dynamodb_tablename: !Ref DynamoDBTableName databaseUser: admin # 렉스 못의 비즈니스 로직 처리 위한 람다 함수 실행 권한 추가 BankingServicesLambdaPermission: Type: AWS::Lambda::Permission Properties: FunctionName: !GetAtt BankingServicesBusinessLogic.Arn Action: lambda:InvokeFunction Principal: lexv2.amazonaws.com SourceArn: !GetAtt InvokeLexImportBankingServicesFunction.lex_arn # 다이나모 DB 테이블 정의 DynamoDBTable: Type: 'AWS::DynamoDB::Table' Properties: PointInTimeRecoverySpecification: PointInTimeRecoveryEnabled: true AttributeDefinitions: - AttributeName: "PK" AttributeType: "S" - AttributeName: "SK" AttributeType: "S" - AttributeName: "Balance" AttributeType: "N" KeySchema: - AttributeName: "PK" KeyType: "HASH" - AttributeName: "SK" KeyType: "RANGE" ProvisionedThroughput: ReadCapacityUnits: "1" WriteCapacityUnits: "1" GlobalSecondaryIndexes: - IndexName: Location-index KeySchema: - AttributeName: Balance KeyType: HASH Projection: NonKeyAttributes: - count ProjectionType: INCLUDE ProvisionedThroughput: WriteCapacityUnits: 5 ReadCapacityUnits: 5 TableName: !Ref DynamoDBTableName # 다이나모 DB 테이블 생성 요청을 위한 사용자 정의 함수 DynamoTableInsert: DependsOn: DynamoDBTable Type: 'Custom::DynamoTableInsert' Properties: ServiceToken: !GetAtt DynamoDBImport.Arn TableName: !Ref DynamoDBTable key2: - list key3: key4: map # 다이나모 DB 테이블 레코드 입력을 위한 람다 함수 DynamoDBImport: Type: 'AWS::Lambda::Function' Properties: Code: S3Bucket: !FindInMap [BucketName, !Ref "AWS::Region", 'Name'] S3Key: !FindInMap [S3Path, 'DBImportSource', 'Name'] Handler: lambda_function.lambda_handler Role: !GetAtt - LambdaRole - Arn Runtime: python3.9 FunctionName: !Join [ "_", [ !Ref AWS::StackName, 'DynamoDBImport' ] ] MemorySize: 128 Timeout: 300 Outputs: CustomerData: Description: 'Sample customer data' Value: 'TBD'