-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtemplate.yaml
107 lines (107 loc) · 3.32 KB
/
template.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
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
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: Halma Telegram Bot Running on AWS Lambda
Parameters:
TelegramTokenParam:
NoEcho: true # hide
Type: String
Resources:
HalmaBucket:
Type: 'AWS::S3::Bucket'
Properties:
BucketName: "halma-chats-bucket"
VersioningConfiguration:
Status: Suspended
HalmaTelegramBot:
Type: 'AWS::Serverless::Function'
Properties:
Handler: NOT_USED
Runtime: provided
CodeUri: build
Description: Halma Telegram Bot Running on AWS Lambda
MemorySize: 640 # MB
# The program only uses ~100 MB but allocating more memory also means that more CPU power
# is allocated, which is critical for answering messages in a timely manner (and not
# triggering the timeout).
Timeout: 30 # seconds
Policies:
- AWSLambdaExecute # Managed Policy
- Version: '2012-10-17' # Policy Document
Statement:
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource: 'arn:aws:logs:*:*:*'
- Effect: Allow
Action:
- s3:ListBucket
Resource: 'arn:aws:s3:::halma-chats-bucket'
- Effect: Allow
Action:
- s3:GetObject
- s3:PutObject
Resource: !Join
- ''
- - !GetAtt HalmaBucket.Arn
- '/*'
Environment:
Variables:
HALMA_S3_BUCKET: halma-chats-bucket
TELEGRAM_TOKEN: !Ref TelegramTokenParam
Events:
HalmaTelegramWebhook:
Type: Api
Properties:
Path: "/halma-telegram-bot"
Method: POST
RestApiId: !Ref HalmaTelegramApi
#GatewayLogGroup:
# Type: "AWS::Logs::LogGroup"
# Properties:
# LogGroupName: !Sub "/${AWS::StackName}-gateway-access-log"
# RetentionInDays: 7
HalmaTelegramApi:
Type: 'AWS::Serverless::Api'
Properties:
StageName: "Prod"
#AccessLogSetting:
# DestinationArn: !GetAtt "GatewayLogGroup.Arn"
MethodSettings:
- HttpMethod: '*'
ResourcePath: '/*'
DataTraceEnabled: true
LoggingLevel: INFO
MetricsEnabled: true
ThrottlingBurstLimit: 50
ThrottlingRateLimit: 100.0
DefinitionBody:
swagger: "2.0"
paths:
"/halma-telegram-bot":
post:
produces:
- application/json
responses:
'200':
description: OK
'500':
description: Error
x-amazon-apigateway-integration:
type: aws
httpMethod: POST
passthroughBehavior: when_no_templates
responses:
default:
statusCode: 200
"(\\n|.)+":
statusCode: 500
uri: !Sub "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HalmaTelegramBot.Arn}/invocations"
Outputs:
WebhookUrl:
Description: The URL of the webhook for getting updates from the Telegram Bot API
Value: !Sub "https://${HalmaTelegramApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/halma-telegram-bot"
# TODO:
# - use generated name for S3 bucket?
# - expire logs