forked from aws-samples/serverless-test-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.yaml
128 lines (110 loc) · 3.97 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
# 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: SAM Template for kinesis-lambda-dynamodb
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: 30
Resources:
RecordsStream:
Type: AWS::Kinesis::Stream
Properties:
Name: RecordsStream
RetentionPeriodHours: 48
ShardCount: 2
# DynamoDB Resource https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-dynamodb-table.html
# This single-table DynamoDB design has a generic Partition Key (PK) and Sort Key (RK), and the item fields
# are dependent on the item type:
# "Person Name Items" : PK = {id}, SK = "NAME#", data = "Person's Name"
# "Hello Message Items" : PK = {id}, SK = "DT#{datetime}", data = "Hello Message"
DynamoDBTable:
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
Metadata:
SamResourceId: DynamoDBTable
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.lambda_handler
Runtime: python3.9
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 DynamoDBTable
- KinesisStreamReadPolicy:
StreamName: !Ref RecordsStream
Environment:
Variables:
DYNAMODB_TABLE_NAME: !Ref DynamoDBTable
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
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
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 DynamoDBTable
DynamoDBTableName:
Description: "The DynamoDB Table Name"
Value: !Ref DynamoDBTable
RecordProcessingTestResultsTableName:
Condition: CreateTestResources
Description: "Test results table allows monitoring of processed test records"
Value: !Ref RecordProcessingTestResultsTable