-
Notifications
You must be signed in to change notification settings - Fork 31
/
template.yaml
100 lines (86 loc) · 3.08 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
## Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
## SPDX-License-Identifier: MIT-0
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Introduction to serverless for developers:part3 GitHub to Slack
##########################################################################
# Parameters & Globals #
##########################################################################
Parameters:
slackUrl:
Type: String
Description: your Slack Webhook Url.
Default: ""
Resources:
##########################################################################
# Lambda Functions #
##########################################################################
StarWebhookHandler:
Type: AWS::Serverless::Function
Properties:
Description: A github webhook handler when repo is starred
CodeUri: src_starred/
Handler: app.handler
Runtime: nodejs12.x
Timeout: 3
Policies:
- S3ReadPolicy:
BucketName: !Ref SrcBucket
# Un-comment the following 2 lines to grant S3 read permissions
#- S3WritePolicy:
# BucketName: !Ref SrcBucket
Environment:
Variables:
slackEndpoint: !Ref slackUrl
bucket: !Ref SrcBucket
Events:
HttpApiEvent:
Type: HttpApi
Properties:
Path: /
Method: POST
PushWebhookHandler:
Type: AWS::Serverless::Function
Properties:
Description: A github webhook handler when repo is forked
CodeUri: src_push/
Handler: app.handler
Runtime: nodejs12.x
Timeout: 3
Policies:
- S3WritePolicy:
BucketName: !Ref SrcBucket
Environment:
Variables:
slackEndpoint: !Ref slackUrl
bucket: !Ref SrcBucket
Events:
HttpApiEvent:
Type: HttpApi
Properties:
Path: /push
Method: POST
SrcBucket:
Type: AWS::S3::Bucket
##########################################################################
# Stack outputs #
##########################################################################
Outputs:
StackName:
Description: "The stack name"
Value: !Ref AWS::StackName
StarGitHubEndpoint:
Description: "The star invocation URl to provide to github webhook"
Value: !Sub "https://${ServerlessHttpApi}.execute-api.${AWS::Region}.amazonaws.com"
PushGitHubEndpoint:
Description: "The Push invocation URl to provide to github webhook"
Value: !Sub "https://${ServerlessHttpApi}.execute-api.${AWS::Region}.amazonaws.com/fork"
StarWebhookLambdaFunctionName:
Description: "Logical resource name of the deployed Lambda function"
Value: !Ref StarWebhookHandler
PushWebhookFunctionName:
Description: "Logical resource name of the deployed Lambda function"
Value: !Ref PushWebhookHandler
Bucket:
Description: "My S3 log bucket"
Value: !Ref SrcBucket