-
Notifications
You must be signed in to change notification settings - Fork 1
/
template.bedrock.yaml
62 lines (58 loc) · 1.94 KB
/
template.bedrock.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Telegram Bot Connector
Parameters:
EventBus:
Type: String
Description: "The connector event bus name"
UsernameWhitelist:
Type: CommaDelimitedList
Description: "Telegram allowed usernames, separated by comma"
BedRockModelId:
Type: String
Description: "Model identifier"
Default: "arn:aws:bedrock:us-east-1::foundation-model/ai21.j2-mid-v1"
BotInstructions:
Type: String
Description: "Model instruction about how to respond to /start message"
Default: "You are a multi-lingual chatbot named BedRock"
Conditions:
IsUsernameWhitelistEnabled: !Not [ !Equals [ !Join [ "", !Ref UsernameWhitelist ], "" ] ]
Resources:
MessageReceivedStateMachine:
Type: AWS::Serverless::StateMachine
Properties:
Name: !Sub "${AWS::StackName}-message"
DefinitionUri: states/bedrock/message.asl.yaml
DefinitionSubstitutions:
EventBusName: !Ref MessagesEventBus
EventSource: !Ref AWS::StackName
BotInstructions: !Ref BotInstructions
BedRockModelId: !Ref BedRockModelId
Policies:
- EventBridgePutEventsPolicy:
EventBusName: !Ref MessagesEventBus
- Statement:
- Sid: BedRockModelAccess
Effect: Allow
Action:
- "bedrock:InvokeModel"
Resource:
- !Ref BedRockModelId
Events:
ReceivedEvent:
Type: EventBridgeRule
Properties:
EventBusName: !Ref EventBus
Pattern:
source:
- org.telegram.webhook
detail-type:
- 'Webhook Event Received'
detail:
message:
from:
username: !If
- IsUsernameWhitelistEnabled
- !Ref UsernameWhitelist
- - exist: true