-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yaml
193 lines (182 loc) · 5.68 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
AWSTemplateFormatVersion: "2010-09-09"
Parameters:
ProvisioningTemplateName:
Type: String
Default: 'ProvisionTemplate'
GGTokenExchangeRoleName:
Type: String
Default: 'TokenExchangeRole'
GGFleetProvisioningRoleName:
Type: String
Default: 'ProvisioningRole'
GGDeviceDefaultPolicyName:
Type: String
Default: 'DeviceDefaultIoTPolicy'
GGProvisioningClaimPolicyName:
Type: String
Default: 'ProvisioningClaimPolicy'
Resources:
GGTokenExchangeRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Ref GGTokenExchangeRoleName
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- credentials.iot.amazonaws.com
Action:
- 'sts:AssumeRole'
Path: '/'
Policies:
- PolicyName: !Sub ${GGTokenExchangeRoleName}Access
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- 'iot:DescribeCertificate'
- 'logs:CreateLogGroup'
- 'logs:CreateLogStream'
- 'logs:PutLogEvents'
- 'logs:DescribeLogStreams'
- 's3:GetBucketLocation'
- 's3:GetObject'
Resource: '*'
GGTokenExchangeRoleAlias:
Type: AWS::IoT::RoleAlias
Properties:
RoleArn: !GetAtt GGTokenExchangeRole.Arn
RoleAlias: !Sub ${GGTokenExchangeRoleName}Alias
GGFleetProvisioningRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Ref GGFleetProvisioningRoleName
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- iot.amazonaws.com
Action:
- 'sts:AssumeRole'
Path: '/'
ManagedPolicyArns:
- 'arn:aws:iam::aws:policy/service-role/AWSIoTThingsRegistration'
GGDeviceDefaultPolicy:
Type: AWS::IoT::Policy
Properties:
PolicyName: !Ref GGDeviceDefaultPolicyName
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- 'iot:Connect'
- 'iot:Publish'
- 'iot:Subscribe'
- 'iot:Receive'
- 'iot:Connect'
- 'greengrass:*'
Resource: '*'
- Effect: Allow
Action:
- 'iot:AssumeRoleWithCertificate'
Resource: !GetAtt GGTokenExchangeRoleAlias.RoleAliasArn
GGFleetProvisionTemplate:
Type: AWS::IoT::ProvisioningTemplate
Properties:
TemplateName: !Ref ProvisioningTemplateName
Description: 'Fleet Provisioning template for AWS IoT Greengrass.'
Enabled: True
ProvisioningRoleArn: !GetAtt GGFleetProvisioningRole.Arn
TemplateBody: !Sub |+
{
"Parameters": {
"ThingName": {
"Type": "String"
},
"ThingGroupName": {
"Type": "String"
},
"AWS::IoT::Certificate::Id": {
"Type": "String"
}
},
"Resources": {
"GGThing": {
"OverrideSettings": {
"AttributePayload": "REPLACE",
"ThingGroups": "REPLACE",
"ThingTypeName": "REPLACE"
},
"Properties": {
"AttributePayload": {},
"ThingGroups": [
{
"Ref": "ThingGroupName"
}
],
"ThingName": {
"Ref": "ThingName"
}
},
"Type": "AWS::IoT::Thing"
},
"GGDefaultPolicy": {
"Properties": {
"PolicyName": "${GGDeviceDefaultPolicyName}"
},
"Type": "AWS::IoT::Policy"
},
"GGCertificate": {
"Properties": {
"CertificateId": {
"Ref": "AWS::IoT::Certificate::Id"
},
"Status": "Active"
},
"Type": "AWS::IoT::Certificate"
}
}
}
GGProvisioningClaimPolicy:
Type: AWS::IoT::Policy
Properties:
PolicyName: !Ref GGProvisioningClaimPolicyName
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- 'iot:Connect'
Resource: '*'
- Effect: Allow
Action:
- 'iot:Publish'
- 'iot:Receive'
Resource:
- !Sub 'arn:aws:iot:${AWS::Region}:${AWS::AccountId}:topic/$aws/certificates/create/*'
- !Sub 'arn:aws:iot:${AWS::Region}:${AWS::AccountId}:topic/$aws/provisioning-templates/${ProvisioningTemplateName}/provision/*'
- Effect: Allow
Action:
- 'iot:Subscribe'
Resource:
- !Sub 'arn:aws:iot:${AWS::Region}:${AWS::AccountId}:topicfilter/$aws/certificates/create/*'
- !Sub 'arn:aws:iot:${AWS::Region}:${AWS::AccountId}:topicfilter/$aws/provisioning-templates/${ProvisioningTemplateName}/provision/*'
Outputs:
GGTokenExchangeRole:
Description: Name of token exchange role.
Value: !Ref GGTokenExchangeRole
GGTokenExchangeRoleAlias:
Description: Name of token exchange role alias.
Value: !Ref GGTokenExchangeRoleAlias
GGFleetProvisionTemplate:
Description: Name of Fleet provisioning template.
Value: !Ref GGFleetProvisionTemplate
GGProvisioningClaimPolicy:
Description: Name of claim certificate IoT policy.
Value: !Ref GGProvisioningClaimPolicy