forked from aws-samples/serverless-test-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.yaml
161 lines (147 loc) · 4.94 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
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
typescript-test-samples
Sample SAM Template for typescript-test-samples
Parameters:
DeployTestResources:
Description: The parameter instructs the template whether or not to deploy test resources to your environment.
Default: "True"
Type: String
AllowedValues:
- "True"
- "False"
ConstraintDescription: Allowed values are True and False
Conditions:
CreateTestResources: !Equals [!Ref DeployTestResources, "True"]
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
Timeout: 10
MemorySize: 512
Resources:
RecordsStream:
Type: AWS::Kinesis::Stream
Properties:
Name: RecordsStream
RetentionPeriodHours: 48
ShardCount: 2
ProcessedRecordsTable:
Type: AWS::DynamoDB::Table
UpdateReplacePolicy: Delete
Properties:
AttributeDefinitions:
- AttributeName: PK
AttributeType: S
- AttributeName: SK
AttributeType: S
KeySchema:
- AttributeName: PK
KeyType: HASH
- AttributeName: SK
KeyType: RANGE
BillingMode: PAY_PER_REQUEST
SSESpecification:
SSEEnabled: true
StreamSpecification:
!If
- CreateTestResources
-
StreamViewType: NEW_AND_OLD_IMAGES
- !Ref AWS::NoValue
Metadata:
SamResourceId: ProcessedRecordsTable
RecordProcessorFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: src/
Handler: app.lambdaHandler
Runtime: nodejs16.x
Architectures:
- x86_64
Tracing: Active
# Available policies:
# https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-policy-template-list.html
Policies:
- AWSXrayWriteOnlyAccess
- DynamoDBWritePolicy:
TableName: !Ref ProcessedRecordsTable
- KinesisStreamReadPolicy:
StreamName: !Ref RecordsStream
Environment:
Variables:
PROCESSED_RECORDS_TABLE_NAME: !Ref ProcessedRecordsTable
Events:
KinesisRecords:
Type: Kinesis # More info about API Event Source: https://github.com/aws/serverless-application-model/blob/master/versions/2016-10-31.md#kinesis
Properties:
Stream: !GetAtt RecordsStream.Arn
BatchSize: 20
StartingPosition: LATEST
Metadata: # Manage esbuild properties
BuildMethod: esbuild
BuildProperties:
Minify: true
Target: "es2020"
# Sourcemap: true # Enabling source maps will create the required NODE_OPTIONS environment variables on your lambda function during sam build
EntryPoints:
- app.ts
RecordProcessingTestResultsTable:
Type: AWS::DynamoDB::Table
Condition: CreateTestResources
Properties:
AttributeDefinitions:
- AttributeName: PK
AttributeType: S
- AttributeName: SK
AttributeType: S
KeySchema:
- AttributeName: PK
KeyType: HASH
- AttributeName: SK
KeyType: RANGE
BillingMode: PAY_PER_REQUEST
ProcessedRecordsTableListener:
Type: AWS::Serverless::Function
Condition: CreateTestResources
Properties:
CodeUri: src/tests/integration/
Handler: appTest.lambdaHandler
Runtime: nodejs16.x
Policies:
- DynamoDBWritePolicy:
TableName: !Ref RecordProcessingTestResultsTable
Environment:
Variables:
TEST_RESULTS_TABLE_NAME: !Ref RecordProcessingTestResultsTable
Events:
ProcessedRecordsTableEvent:
Type: DynamoDB
Properties:
Stream:
!GetAtt ProcessedRecordsTable.StreamArn
StartingPosition: TRIM_HORIZON
BatchSize: 20
Enabled: true
Metadata: # Manage esbuild properties
BuildMethod: esbuild
BuildProperties:
Minify: true
Target: "es2020"
# Sourcemap: true # Enabling source maps will create the required NODE_OPTIONS environment variables on your lambda function during sam build
EntryPoints:
- appTest.ts
Outputs:
RecordsStreamArn:
Description: "Kinesis stream accepts records for processing"
Value: !GetAtt RecordsStream.Arn
RecordProcessorFunctionArn:
Description: "Kinesis records processor Lambda Function ARN"
Value: !GetAtt RecordProcessorFunction.Arn
ProcessedRecordsTableName:
Description: "Processed Records DynamoDB table name"
Value: !Ref ProcessedRecordsTable
RecordProcessingTestResultsTableName:
Condition: CreateTestResources
Description: "Test results table allows monitoring of processed test records"
Value: !Ref RecordProcessingTestResultsTable