-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtemplate.yml
129 lines (121 loc) · 3.39 KB
/
template.yml
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: SAM template for LINE bot with Amazon Bedrock
Globals:
Function:
Timeout: 180
Runtime: nodejs20.x
Parameters:
Stage:
Type: String
Default: dev
Resources:
BotFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: ./
Handler: handler.callback
Events:
ApiEvent:
Type: Api
Properties:
Path: /callback
Method: post
Environment:
Variables:
CHANNEL_SECRET: "YOUR_CHANNEL_SECRET"
CHANNEL_ACCESS_TOKEN: "YOUR_CHANNEL_ACCESS_TOKEN"
DYNAMODB_TABLE: !Ref ConversationsTable
S3_BUCKET: !Ref S3Bucket
Policies:
- AWSLambdaBasicExecutionRole
- Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- bedrock:InvokeModel
- bedrock:ListFoundationModels
Resource: arn:aws:bedrock:*:*:foundation-model/*
- Effect: Allow
Action:
- dynamodb:PutItem
- dynamodb:GetItem
- dynamodb:UpdateItem
- dynamodb:Query
- dynamodb:Scan
- dynamodb:DeleteItem
Resource: !GetAtt ConversationsTable.Arn
- Effect: Allow
Action:
- s3:PutObject
- s3:GetObject
- s3:DeleteObject
- s3:ListBucket
Resource:
- !GetAtt S3Bucket.Arn
- !Sub "${S3Bucket.Arn}/*"
# HelloFunction:
# Type: AWS::Serverless::Function
# Properties:
# CodeUri: ./
# Handler: handler.hello
# Events:
# ApiEvent:
# Type: Api
# Properties:
# Path: /hello
# Method: get
ConversationsTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: !Sub "${AWS::StackName}-conversations"
AttributeDefinitions:
- AttributeName: userId
AttributeType: S
- AttributeName: timestamp
AttributeType: N
KeySchema:
- AttributeName: userId
KeyType: HASH
- AttributeName: timestamp
KeyType: RANGE
BillingMode: PAY_PER_REQUEST
S3Bucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Sub "${AWS::StackName}-bucket"
PublicAccessBlockConfiguration:
BlockPublicAcls: false
BlockPublicPolicy: false
IgnorePublicAcls: false
RestrictPublicBuckets: false
OwnershipControls:
Rules:
- ObjectOwnership: BucketOwnerPreferred
CorsConfiguration:
CorsRules:
- AllowedHeaders:
- "*"
AllowedMethods:
- GET
- PUT
- POST
- DELETE
AllowedOrigins:
- "*"
S3BucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref S3Bucket
PolicyDocument:
Statement:
- Sid: PublicReadGetObject
Effect: Allow
Principal: '*'
Action:
- s3:GetObject
Resource: !Sub "${S3Bucket.Arn}/*"
Outputs:
ApiUrl:
Description: "API Gateway endpoint URL for Prod stage"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/callback"