-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.yaml
114 lines (107 loc) · 3.28 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
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
AWS SAM Template for aws-codepipeline-deploy-status-badge-generator,
which listens on CodePipeline CloudWatch State Execution Change Events
to spot when a deployment starts and stops to generate a badge SVG file
that can be added to GitHub for example
Resources:
DeploymentInformationTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: CodePipelineDeploymentInformation
AttributeDefinitions:
- AttributeName: pipelineName
AttributeType: S
KeySchema:
- AttributeName: pipelineName
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
BadgeGeneratorApi:
Type: AWS::Serverless::Api
Properties:
StageName: v1
Cors: "'*'"
BadgeGenerator:
Type: AWS::Serverless::Function
Properties:
FunctionName: aws-codepipeline-deploy-status-badge-generator-api
CodeUri: aws-codepipeline-deploy-status-badge-generator-api/
Handler: app.handler
Runtime: nodejs12.x
Environment:
Variables:
DYANMO_DB_TABLE_NAME: !Ref DeploymentInformationTable
Policies:
- Statement:
- Effect: Allow
Action:
- 'dynamodb:*'
Resource:
- !GetAtt DeploymentInformationTable.Arn
Events:
GetCommitId:
Type: Api
Properties:
RestApiId: !Ref BadgeGeneratorApi
Method: GET
Path: /pipeline/{pipelineName}/commit/id
GetCommitUrl:
Type: Api
Properties:
RestApiId: !Ref BadgeGeneratorApi
Method: GET
Path: /pipeline/{pipelineName}/commit/url
GetStatus:
Type: Api
Properties:
RestApiId: !Ref BadgeGeneratorApi
Method: GET
Path: /pipeline/{pipelineName}/status
Update:
Type: Api
Properties:
RestApiId: !Ref BadgeGeneratorApi
Path: /pipeline/{pipelineName}
Method: POST
Auth:
ApiKeyRequired: true
DeploymenInformationUpdater:
Type: AWS::Serverless::Function
Properties:
FunctionName: aws-codepipeline-deploy-status-badge-generator-updater
CodeUri: aws-codepipeline-deploy-status-badge-generator-updater/
Handler: app.handler
Runtime: nodejs12.x
Environment:
Variables:
DYANMO_DB_TABLE_NAME: !Ref DeploymentInformationTable
Policies:
- Statement:
- Effect: Allow
Action:
- codepipeline:ListActionExecutions
Resource: '*'
- Statement:
- Effect: Allow
Action:
- 'dynamodb:*'
Resource:
- !GetAtt DeploymentInformationTable.Arn
Events:
CloudWatchCodePipeline:
Type: EventBridgeRule
Properties:
Pattern:
source:
- "aws.codepipeline"
detail-type:
- "CodePipeline Stage Execution State Change"
detail:
state:
- STARTED
- FAILED
- SUCCEEDED
InputPath: "$.detail"