forked from PagerDuty/pd-oncall-chat-topic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deployment.yml
108 lines (103 loc) · 2.63 KB
/
deployment.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
---
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Parameters:
SSMKeyArn:
Type: String
PDSSMKeyName:
Type: String
Default: "pd-oncall-chat-topic"
SlackSSMKeyName:
Type: String
Default: "pd-oncall-chat-topic-slack"
Bucket:
Type: String
md5:
Type: String
Outputs:
ConfigTableName:
Description: "Name of Config Table"
Value: !Ref ConfigTable
ConfigTableArn:
Description: "Arn of Config Table"
Value: !GetAtt ConfigTable.Arn
Resources:
ChatTopicRole:
Type: AWS::IAM::Role
Properties:
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Sid: 'Lambda'
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Path: "/cfn/"
Policies:
- PolicyName: SSM
PolicyDocument:
Statement:
- Effect: Allow
Action:
- ssm:GetParameters
Resource:
- !Sub "arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/${PDSSMKeyName}"
- !Sub "arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/${SlackSSMKeyName}"
- PolicyName: KMS
PolicyDocument:
Statement:
- Effect: Allow
Action:
- kms:Decrypt
Resource:
- !Ref SSMKeyArn
- PolicyName: DDB
PolicyDocument:
Statement:
- Effect: Allow
Action:
- dynamodb:scan
Resource:
- !GetAtt ConfigTable.Arn
ConfigTable:
Type: "AWS::DynamoDB::Table"
Properties:
AttributeDefinitions:
-
AttributeName: "schedule"
AttributeType: "S"
KeySchema:
-
AttributeName: "schedule"
KeyType: "HASH"
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
TimeToLiveSpecification:
AttributeName: expiretime
Enabled: true
ChatTopicFunction:
Type: AWS::Serverless::Function
Properties:
Handler: main.handler
Runtime: python3.6
Timeout: 120
CodeUri:
Bucket: !Ref Bucket
Key: !Ref md5
Environment:
Variables:
PD_API_KEY_NAME: !Ref PDSSMKeyName
SLACK_API_KEY_NAME: !Ref SlackSSMKeyName
CONFIG_TABLE: !Ref ConfigTable
Role: !GetAtt ChatTopicRole.Arn
Events:
Cron:
Type: Schedule
Properties:
Schedule: 'rate(5 minutes)'