-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yaml
executable file
·130 lines (120 loc) · 3.04 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
AWSTemplateFormatVersion: 2010-09-09
Description: >-
postman-api-testing-sam
Transform:
- AWS::Serverless-2016-10-31
Parameters:
TestName:
Type: String
Default: MyService
SecretId:
Type: String
Default: /secret/api-tests/MyService
ReportsFolder:
Type: String
Default: reports
Timeout:
Type: Number
Default: 60
MemorySize:
Type: Number
Default: 1024
MinValue: 128
MaxValue: 10240
TestSchedule:
Type: String
Default: rate(1 minute)
MetricName:
Type: String
Default: MyServiceTestFailureCount
Namespace:
Type: String
Default: ApiTests
SecretKeys:
Type: String
Default: ''
Globals:
Function:
Layers:
- !Ref RuntimeDependenciesLayer
Runtime: nodejs18.x
Resources:
RuntimeDependenciesLayer:
Type: AWS::Serverless::LayerVersion
Metadata:
BuildMethod: makefile
Properties:
Description: Runtime dependencies for Lambdas
ContentUri: ./
CompatibleRuntimes:
- nodejs18.x
ScheduledApiTestingHandler:
Type: AWS::Serverless::Function
Metadata:
BuildMethod: makefile
Properties:
Description: A Lambda function that runs API tests based on postman collections.
Runtime: nodejs18.x
Architectures:
- x86_64
Handler: dist/handlers/api-testing-handler.handler
Environment:
Variables:
S3_BUCKET_NAME: !Ref Bucket
S3_DESTINATION_PREFIX: !Ref TestName
ENVIRONMENT_FILENAME: postman_environment.json
GLOBALS_FILENAME: postman_globals.json
COLLECTION_FILENAME: postman_collection.json
SECRET_ID: !Ref SecretId
REPORTS_FOLDER: !Ref ReportsFolder
METRIC_NAME: !Ref MetricName
METRIC_NAMESPACE: !Ref Namespace
SECRET_KEYS: !Ref SecretKeys
Events:
CloudWatchEvent:
Type: Schedule
Properties:
Schedule: !Ref TestSchedule
MemorySize: !Ref MemorySize
Timeout: !Ref Timeout
Policies:
- S3CrudPolicy:
BucketName:
!Ref Bucket
- CloudWatchPutMetricPolicy: {}
- AWSSecretsManagerGetSecretValuePolicy:
SecretArn: !Ref Secrets
Bucket:
Type: AWS::S3::Bucket
ApiTestFailureAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: API test failure alarm
AlarmName: !Join
- ''
- - !Ref TestName
- 'Failed'
ComparisonOperator: GreaterThanOrEqualToThreshold
DatapointsToAlarm: 1
EvaluationPeriods: 1
Threshold: 1
Period: 60
TreatMissingData: breaching
Statistic: Sum
Unit: Count
Namespace: !Ref Namespace
MetricName: !Ref MetricName
Secrets:
Type: AWS::SecretsManager::Secret
Properties:
Name: !Ref SecretId
Description: "Your test secrets."
SecretString: '{}'
Outputs:
S3Bucket:
Description: "Store your test assets at this bucket folder."
Value: !Join
- ''
- - !Ref Bucket
- '/'
- !Ref TestName