-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtemplate.yml
106 lines (98 loc) · 3.04 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
AWSTemplateFormatVersion: "2010-09-09"
Transform: "AWS::Serverless-2016-10-31"
Description: >
Code Scanning Alerts to Slack
Resources:
AccessLogs:
Type: "AWS::Logs::LogGroup"
CodeScanningToSlack:
Type: "AWS::Serverless::Function"
Properties:
CodeUri: functions/codeScanningToSlack
Description: "A Lambda that connects GitHub Code Scanning Results to a Slack Channel"
Environment:
Variables:
NODE_ENV: Production
REGION: !Ref "AWS::Region"
Events:
GatewayEndpoint:
Properties:
ApiId: !Ref HttpApi
Method: POST
Path: /codescanning
Type: HttpApi
Handler: lib/main.handler
Policies:
- AmazonSSMReadOnlyAccess
Runtime: nodejs20.x
Timeout: 60
Tracing: Active
GitHubWebhookIPValidator:
Type: "AWS::Serverless::Function"
Properties:
CodeUri: functions/githubWebhookIPValidator
Description: "A Lambda Function that validates the IP comes from GitHub"
Environment:
Variables:
NODE_ENV: Production
REGION: !Ref "AWS::Region"
Handler: lib/main.handler
Policies:
- AmazonSSMReadOnlyAccess
Runtime: nodejs20.x
Timeout: 60
Tracing: Active
HttpApi:
Type: "AWS::Serverless::HttpApi"
Properties:
AccessLogSettings:
DestinationArn: !GetAtt AccessLogs.Arn
Format: >-
{ "requestId":"$context.requestId","ip": "$context.identity.sourceIp",
"requestTime":"$context.requestTime","httpMethod":"$context.httpMethod",
"routeKey":"$context.routeKey","status":"$context.status",
"protocol":"$context.protocol","responseLength":"$context.responseLength",
"error" : $context.authorizer.error }
Auth:
Authorizers:
LambdaAuthorizer:
AuthorizerPayloadFormatVersion: "2.0"
EnableSimpleResponses: true
FunctionArn: !GetAtt GitHubWebhookIPValidator.Arn
FunctionInvokeRole: !GetAtt LambdaInvokeRole.Arn
Identity:
Headers:
- X-Hub-Signature
DefaultAuthorizer: LambdaAuthorizer
RouteSettings:
"POST /codescanning":
ThrottlingBurstLimit: 10
LambdaInvokeRole:
Type: "AWS::IAM::Role"
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service:
- apigateway.amazonaws.com
Action:
- "sts:AssumeRole"
LambdaInvokePolicy:
Type: "AWS::IAM::Policy"
Properties:
PolicyName: "LambdaInvokePolicy"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Action: "lambda:InvokeFunction"
Resource: !GetAtt GitHubWebhookIPValidator.Arn
Roles:
- Ref: "LambdaInvokeRole"
Outputs:
HttpApiUrl:
Description: HTTP API URL
Value:
Fn::Sub: "https://${HttpApi}.execute-api.${AWS::Region}.${AWS::URLSuffix}/"