-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yaml
169 lines (149 loc) · 4.63 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
pritunl-slack-app
Sample SAM Template for pritunl-slack-app
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: "General"
Parameters:
- PritunlBaseUrl
- PritunlApiSecret
- PritunlApiToken
- SlackSigningSecret
- SlackBotToken
AWS::ServerlessRepo::Application:
Name: pritunl-slack-app
Description: Pritunl Slack App Slash Commands
Author: Nathaniel Varona
SpdxLicenseId: MIT
LicenseUrl: LICENSE
ReadmeUrl: README.md
Labels: [serverless, lambda, pritunl, vpn]
HomePageUrl: https://github.com/nathanielvarona/pritunl-slack-app
SemanticVersion: 0.1.0
SourceCodeUrl: https://github.com/nathanielvarona/pritunl-slack-app
Parameters:
PritunlBaseUrl:
Type: String
Description: Pritunl API Base Url
NoEcho: true
PritunlApiSecret:
Type: String
Description: Pritunl API Secret
NoEcho: true
PritunlApiToken:
Type: String
Description: Pritunl API Token
NoEcho: true
SlackSigningSecret:
Type: String
Description: Slack Signing Secret
NoEcho: true
SlackBotToken:
Type: String
Description: Salck Signing Token
NoEcho: true
Mappings:
RegionToLayerArnMap:
us-east-1:
"LayerArn": "arn:aws:lambda:us-east-1:177933569100:layer:AWS-Parameters-and-Secrets-Lambda-Extension:4"
us-east-2:
"LayerArn": "arn:aws:lambda:us-east-2:590474943231:layer:AWS-Parameters-and-Secrets-Lambda-Extension:4"
Globals:
Function:
Timeout: 10
MemorySize: 128
Resources:
PritunlSlackFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: pritunl_slack_app/function
Handler: pritunl_slack_app.function_handler.handler
Runtime: python3.10
PackageType: Zip
Architectures:
- x86_64
Environment:
Variables:
PRITUNL_BASE_URL: !Ref AWSPritunlBaseUrl
PRITUNL_API_SECRET: !Ref AWSSecretPritunlApiSecret
PRITUNL_API_TOKEN: !Ref AWSSecretPritunlApiToken
SLACK_SIGNING_SECRET: !Ref AWSSecretSlackSigningSecret
SLACK_BOT_TOKEN: !Ref AWSSecretSlackBotToken
SSM_PARAMETER_STORE_TTL: 120
SECRETS_MANAGER_TTL: 120
Policies:
- Version: '2012-10-17'
Statement:
- Sid: SecretManagerPolicy
Effect: Allow
Action:
- "secretsmanager:GetSecretValue"
Resource:
- !Ref AWSPritunlBaseUrl
- !Ref AWSSecretPritunlApiSecret
- !Ref AWSSecretPritunlApiToken
- !Ref AWSSecretSlackSigningSecret
- !Ref AWSSecretSlackBotToken
- Version: '2012-10-17'
Statement:
- Sid: InvokeLambda
Effect: Allow
Action:
- "lambda:InvokeFunction"
- "lambda:InvokeAsync"
Resource:
- "*"
Layers:
- !FindInMap [RegionToLayerArnMap, !Ref "AWS::Region", LayerArn]
PritunlSlackUrlFunctionPermissions:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !Ref PritunlSlackFunction
Action: lambda:InvokeFunctionUrl
Principal: "*"
FunctionUrlAuthType: NONE
PritunlSlackFunctionUrl:
Type: AWS::Lambda::Url
Properties:
TargetFunctionArn: !Ref PritunlSlackFunction
AuthType: NONE
AWSPritunlBaseUrl:
Type: "AWS::SecretsManager::Secret"
Properties:
Name: PritunlBaseUrl
SecretString: !Ref PritunlBaseUrl
AWSSecretPritunlApiSecret:
Type: "AWS::SecretsManager::Secret"
Properties:
Name: PritunlApiSecret
SecretString: !Ref PritunlApiSecret
AWSSecretPritunlApiToken:
Type: "AWS::SecretsManager::Secret"
Properties:
Name: PritunlApiToken
SecretString: !Ref PritunlApiToken
AWSSecretSlackSigningSecret:
Type: "AWS::SecretsManager::Secret"
Properties:
Name: SlackSigningSecret
SecretString: !Ref SlackSigningSecret
AWSSecretSlackBotToken:
Type: "AWS::SecretsManager::Secret"
Properties:
Name: SlackBotToken
SecretString: !Ref SlackBotToken
Outputs:
PritunlSlackFunctionUrl:
Description: "Pritunl Slack App Lambda Function URL"
Value:
Fn::GetAtt: PritunlSlackFunctionUrl.FunctionUrl
PritunlSlackFunction:
Description: "Pritunl Slack App Lambda Function ARN"
Value: !GetAtt PritunlSlackFunction.Arn
PritunlSlackFunctionIamRole:
Description: "Implicit IAM Role created for Pritunl Slack App function"
Value: !GetAtt PritunlSlackFunctionRole.Arn