Guest User

aws lex cloudformation

a guest
Nov 2nd, 2022
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.54 KB | Source Code | 0 0
  1. AWSTemplateFormatVersion: "2010-09-09"
  2. Transform: AWS::Serverless-2016-10-31
  3. Description: >
  4. ReHub Bot - Work in progress
  5.  
  6. Resources:
  7. BotRuntimeRole:
  8. Type: AWS::IAM::Role
  9. Properties:
  10. AssumeRolePolicyDocument:
  11. Version: "2012-10-17"
  12. Statement:
  13. - Effect: Allow
  14. Principal:
  15. Service:
  16. - lexv2.amazonaws.com
  17. Action:
  18. - "sts:AssumeRole"
  19. Path: "/"
  20. Policies:
  21. - PolicyName: LexRuntimeRolePolicy
  22. PolicyDocument:
  23. Version: 2012-10-17
  24. Statement:
  25. - Effect: Allow
  26. Action:
  27. - "polly:SynthesizeSpeech"
  28. - "comprehend:DetectSentiment"
  29. Resource: "*"
  30. - PolicyName: LexRunLambdaPolicy
  31. PolicyDocument:
  32. Version: 2012-10-17
  33. Statement:
  34. - Effect: Allow
  35. Action:
  36. - "lambda:InvokeFunction"
  37. Resource: "*"
  38.  
  39. ReHubBot:
  40. DependsOn: BotRuntimeRole
  41. Type: AWS::Lex::Bot
  42. Properties:
  43. Name: "ReHubBot"
  44. RoleArn: !GetAtt BotRuntimeRole.Arn
  45. DataPrivacy:
  46. ChildDirected: false
  47. IdleSessionTTLInSeconds: 300
  48. Description: "Provides voice control to the ReHub app."
  49. AutoBuildBotLocales: true
  50. BotLocales:
  51. - LocaleId: "es_ES"
  52. Description: "¿Qué quieres hacer?"
  53. NluConfidenceThreshold: 0.40
  54. VoiceSettings:
  55. VoiceId: "Lucia"
  56. SlotTypes:
  57. - Name: "ExerciceValues"
  58. Description: "Nombres de ejercicio"
  59. SlotTypeValues:
  60. - SampleValue:
  61. Value: "hombro"
  62. - SampleValue:
  63. Value: "brazo"
  64. - SampleValue:
  65. Value: "mano"
  66. ValueSelectionSetting:
  67. ResolutionStrategy: ORIGINAL_VALUE
  68. Intents:
  69. - Name: "Iniciar"
  70. Description: "Iniciar"
  71. SampleUtterances:
  72. - Utterance: "Iniciar"
  73. - Utterance: "Iniciar el ejercicio"
  74. - Utterance: "Quiero iniciar el ejercicio"
  75. Slots:
  76. - Name: "ExerciceId"
  77. Description: "something"
  78. SlotTypeName: "ExerciceValues"
  79. ValueElicitationSetting:
  80. SlotConstraint: "Required"
  81. PromptSpecification:
  82. MessageGroupsList:
  83. - Message:
  84. PlainTextMessage:
  85. Value: "Indica el ejercicio"
  86. MaxRetries: 3
  87. AllowInterrupt: false
  88. SlotPriorities:
  89. - Priority: 1
  90. SlotName: ExerciceId
  91. IntentConfirmationSetting:
  92. PromptSpecification:
  93. MessageGroupsList:
  94. - Message:
  95. PlainTextMessage:
  96. Value: "Ok, quieres iniciar el ejercicio {ExerciceId}. ¿Es correcto?"
  97. MaxRetries: 3
  98. AllowInterrupt: false
  99. DeclinationResponse:
  100. MessageGroupsList:
  101. - Message:
  102. PlainTextMessage:
  103. Value: "Ok, He cancelado la acción."
  104. AllowInterrupt: false
  105. FulfillmentCodeHook:
  106. Enabled: true
  107. PostFulfillmentStatusSpecification:
  108. FailureResponse:
  109. MessageGroupsList:
  110. - Message:
  111. PlainTextMessage:
  112. Value: "Esto es FailureResponse"
  113. AllowInterrupt: false
  114. SuccessResponse:
  115. MessageGroupsList:
  116. - Message:
  117. PlainTextMessage:
  118. Value: "Esto es SuccessResponse"
  119. AllowInterrupt: false
  120. TimeoutResponse:
  121. MessageGroupsList:
  122. - Message:
  123. PlainTextMessage:
  124. Value: "Esto es TimeoutResponse"
  125. AllowInterrupt: false
  126. - Name: "FallbackIntent"
  127. Description: "Default intent when no other intent matches"
  128. ParentIntentSignature: "AMAZON.FallbackIntent"
  129.  
  130. ReHubBotVersion:
  131. DependsOn: ReHubBot
  132. Type: AWS::Lex::BotVersion
  133. Properties:
  134. BotId: !Ref ReHubBot
  135. BotVersionLocaleSpecification:
  136. - LocaleId: es_ES
  137. BotVersionLocaleDetails:
  138. SourceBotVersion: DRAFT
  139. Description: ReHubBot Version
  140.  
  141. ReHubBotAlias:
  142. DependsOn: ReHubBotVersion
  143. Type: AWS::Lex::BotAlias
  144. Properties:
  145. BotId: !Ref ReHubBot
  146. BotAliasName: "Prod"
  147. BotVersion: !GetAtt ReHubBotVersion.BotVersion
  148. SentimentAnalysisSettings:
  149. DetectSentiment: false
  150. BotAliasLocaleSettings:
  151. - LocaleId: es_ES
  152. BotAliasLocaleSetting:
  153. Enabled: true
  154. CodeHookSpecification:
  155. LambdaCodeHook:
  156. CodeHookInterfaceVersion: "1.0"
  157. LambdaArn: !GetAtt TestLexFunction.Arn
  158.  
  159. LexInvokeLambdaPermission:
  160. Type: AWS::Lambda::Permission
  161. Properties:
  162. Action: "lambda:InvokeFunction"
  163. FunctionName: !GetAtt TestLexFunction.Arn
  164. Principal: "lexv2.amazonaws.com"
  165. SourceArn: !GetAtt ReHubBotAlias.Arn
  166.  
  167. TestLexFunction:
  168. Type: AWS::Lambda::Function
  169. Properties:
  170. FunctionName: !Sub ${AWS::StackName}-TestLex
  171. Code:
  172. ZipFile: |
  173. import logging
  174.  
  175. logger = logging.getLogger()
  176. logger.setLevel(logging.DEBUG)
  177.  
  178.  
  179. def lambda_handler(event, context):
  180. logger.debug(event)
  181. Handler: index.lambda_handler
  182. Role: !GetAtt LambdaRole.Arn
  183. Runtime: python3.9
  184. MemorySize: 128
  185. Timeout: 300
  186.  
  187. LambdaRole:
  188. Type: "AWS::IAM::Role"
  189. Properties:
  190. AssumeRolePolicyDocument:
  191. Version: 2012-10-17
  192. Statement:
  193. - Effect: Allow
  194. Principal:
  195. Service:
  196. - lambda.amazonaws.com
  197. Action:
  198. - "sts:AssumeRole"
  199. ManagedPolicyArns:
  200. - arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
  201. Path: /
  202.  
Add Comment
Please, Sign In to add comment