-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtemplate.yaml
109 lines (99 loc) · 3.15 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
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Simple implementation of a microservice to query and insert data in DynamoDB Database
Globals:
Function:
Runtime: nodejs18.x
Timeout: 3
Environment:
Variables:
TABLE: !Ref DeviceServiceTable
Parameters:
Service:
Type: String
Description: The name of the service
Stage:
Type: String
Description: The stage name for deployment
S3BucketName:
Type: String
Description: The S3 Bucket name for the artifacts
ReadCapacity:
Type: Number
Default: 1
Description: The ReadCapacityUnits value
WriteCapacity:
Type: Number
Default: 1
Description: The WriteCapacityUnits value
Resources:
DeviceServiceApi:
Type: AWS::Serverless::Api
Properties:
StageName: !Ref Stage
DefinitionBody:
'Fn::Transform':
Name: 'AWS::Include'
Parameters:
Location: !Join [ '', [ !Ref S3BucketName, '/swagger.yaml' ] ]
GetDeviceListFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/functions/list-devices/
Handler: index.handler
Timeout: 10 # Scan may need longer processing time
FunctionName: !Join [ '-', [ !Ref Service, 'list-devices' ] ]
Policies:
- DynamoDBReadPolicy:
TableName: !Ref DeviceServiceTable
GetDeviceListFunctionPermission:
Type: AWS::Lambda::Permission
Properties:
Action: lambda:InvokeFunction
FunctionName: !Ref GetDeviceListFunction
Principal: apigateway.amazonaws.com
GetDeviceFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/functions/get-device/
Handler: index.handler
FunctionName: !Join [ '-', [ !Ref Service, 'get-device' ] ]
Policies:
- DynamoDBReadPolicy:
TableName: !Ref DeviceServiceTable
GetDeviceFunctionPermission:
Type: AWS::Lambda::Permission
Properties:
Action: lambda:InvokeFunction
FunctionName: !Ref GetDeviceFunction
Principal: apigateway.amazonaws.com
PostOrPutDeviceFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/functions/post-or-put-device
Handler: index.handler
FunctionName: !Join [ '-', [ !Ref Service, 'create-or-update-device' ] ]
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref DeviceServiceTable
PostOrPutDeviceFunctionPermission:
Type: AWS::Lambda::Permission
Properties:
Action: lambda:InvokeFunction
FunctionName: !Ref PostOrPutDeviceFunction
Principal: apigateway.amazonaws.com
DeviceServiceTable:
Type: "AWS::DynamoDB::Table"
Properties:
TableName: !Sub '${Service}-table'
AttributeDefinitions:
- AttributeName: "deviceId"
AttributeType: "S"
KeySchema:
- AttributeName: "deviceId"
KeyType: "HASH"
ProvisionedThroughput:
ReadCapacityUnits: !Ref ReadCapacity
WriteCapacityUnits: !Ref WriteCapacity
PointInTimeRecoverySpecification:
PointInTimeRecoveryEnabled: true