-
Notifications
You must be signed in to change notification settings - Fork 36
/
cfn-greengrass2-installer-config-generators.yml
194 lines (178 loc) · 7.46 KB
/
cfn-greengrass2-installer-config-generators.yml
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
194
--- #-----------------------------------------------------------------------------------------------------------------------
#-----------------------------------------------------------------------------------------------------------------------
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
# with the License. A copy of the License is located at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES
# OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions
# and limitations under the License.
#-----------------------------------------------------------------------------------------------------------------------
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: CDF Greengrass2 Installer Config Generators
Parameters:
ApplicationConfigurationOverride:
Description: This allows you to override any application configuration. It should consists of a text-based content with a structure and syntax comprising key–value pairs for properties. Any configurations contained in this will override the configurations found and merged from the default .env files.
Type: String
Environment:
Description: Name of environment. Used to name the created resources.
Type: String
MinLength: 1
CustomResourceLambdaArn:
Description: Custom resource lambda arn
Type: String
MinLength: 1
TokenExchangeRoleAliasPrefix:
Description: The AWS IoT role alias that points to a token exchange IAM role. The AWS IoT credentials provider assumes this role to allow the Greengrass core device to interact with AWS services.
Type: String
MinLength: 1
Default: 'greengrass2-role-alias'
Resources:
GreengrassIotRoleAlias:
Type: Custom::IotRoleAlias
Version: 1.0
Properties:
ServiceToken: !Ref CustomResourceLambdaArn
TokenExchangeRoleNameArn: !GetAtt GreengrassTokenExchangeRole.Arn
TokenExchangeRoleAlias: !Sub '${TokenExchangeRoleAliasPrefix}-${Environment}'
GreengrassTokenExchangeRole:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: 'Allow'
Principal:
Service:
- 'credentials.iot.amazonaws.com'
Action:
- 'sts:AssumeRole'
Path: '/'
GreengrassTokenExchangePolicy:
Type: 'AWS::IAM::Policy'
Properties:
PolicyName: 'root'
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- iot:Connect
- iot:DescribeCertificate
- iot:Publish
- iot:Receive
- iot:Subscribe
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:DescribeLogStreams
- logs:PutLogEvents
- s3:GetBucketLocation
Resource: '*'
Roles:
- Ref: 'GreengrassTokenExchangeRole'
LambdaExecutionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
Effect: Allow
Principal:
Service: lambda.amazonaws.com
Action: sts:AssumeRole
Path: '/cdf/greengrass2/'
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AWSLambdaExecute
- arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess
- arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole
ManualInstallConfigLambda:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub 'cdf-greengrass2-manual-config-generator-${Environment}'
CodeUri: ../bundle.zip
Handler: lambda_manual_handler.handler
MemorySize: 512
Role: !GetAtt LambdaExecutionRole.Arn
Runtime: nodejs18.x
Timeout: 30
AutoPublishAlias: live
DeploymentPreference:
Type: AllAtOnce
Environment:
Variables:
APP_CONFIG_DIR: 'config'
APP_CONFIG: !Ref ApplicationConfigurationOverride
AWS_IOT_ROLE_ALIAS: !Sub '${TokenExchangeRoleAliasPrefix}-${Environment}'
AWS_IOT_ENDPOINT_DATA: !GetAtt IotDataEndpoint.address
AWS_IOT_ENDPOINT_CREDENTIALS: !GetAtt IotCredentialProviderEndpoint.address
Tracing: Active
FleetProvisioningConfigLambda:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub 'cdf-greengrass2-fleet-config-generator-${Environment}'
CodeUri: ../bundle.zip
Handler: lambda_fleetProvisioning_handler.handler
MemorySize: 512
Role: !GetAtt LambdaExecutionRole.Arn
Runtime: nodejs18.x
Timeout: 30
AutoPublishAlias: live
DeploymentPreference:
Type: AllAtOnce
Environment:
Variables:
APP_CONFIG_DIR: 'config'
APP_CONFIG: !Ref ApplicationConfigurationOverride
AWS_IOT_ROLE_ALIAS: !Sub '${TokenExchangeRoleAliasPrefix}-${Environment}'
AWS_IOT_ENDPOINT_DATA: !Ref IotDataEndpoint
AWS_IOT_ENDPOINT_CREDENTIALS: !Ref IotCredentialProviderEndpoint
Tracing: Active
IotDataEndpoint:
Type: Custom::IotEndpoint
Version: 1.0
Properties:
ServiceToken: !Ref CustomResourceLambdaArn
EndpointType: 'iot:Data-ATS'
IotCredentialProviderEndpoint:
Type: Custom::IotEndpoint
Version: 1.0
Properties:
ServiceToken: !Ref CustomResourceLambdaArn
EndpointType: 'iot:CredentialProvider'
Outputs:
TokenExchangeRoleAlias:
Description: Role Alias which will be assumed by Greengrass Core
Value: !Sub '${TokenExchangeRoleAliasPrefix}-${Environment}'
TokenExchangeRoleName:
Description: Name of the IAM Role which will be assumed by Greengrass Core
Value: !Ref GreengrassTokenExchangeRole
ManualInstallConfigLambdaConsoleUrl:
Description: Console URL for the manual install Lambda Function.
Value: !Sub 'https://${AWS::Region}.console.aws.amazon.com/lambda/home?region=${AWS::Region}#/functions/${ManualInstallConfigLambda}'
ManualInstallConfigLambdaArn:
Description: ManualInstallConfigLambda Arn
Value: !Sub '${ManualInstallConfigLambda.Arn}'
Export:
Name: !Sub 'cdf-greengrass2-installer-config-generators-${Environment}-manualInstallConfigLambdaArn'
ManualInstallConfigLambdaName:
Description: ManualInstallConfigLambda lambda function name
Value: !Ref ManualInstallConfigLambda
Export:
Name: !Sub 'cdf-greengrass2-installer-config-generators-${Environment}-manualInstallConfigLambdaName'
FleetProvisioningConfigLambdaConsoleUrl:
Description: Console URL for the manual install Lambda Function.
Value: !Sub 'https://${AWS::Region}.console.aws.amazon.com/lambda/home?region=${AWS::Region}#/functions/${FleetProvisioningConfigLambda}'
FleetProvisioningConfigLambdaArn:
Description: FleetProvisioningConfigLambda Arn
Value: !Sub '${FleetProvisioningConfigLambda.Arn}'
Export:
Name: !Sub 'cdf-greengrass2-installer-config-generators-${Environment}-fleetProvisioningConfigLambdaArn'
FleetProvisioningConfigLambdaName:
Description: FleetProvisioningConfigLambda lambda function name
Value: !Ref FleetProvisioningConfigLambda
Export:
Name: !Sub 'cdf-greengrass2-installer-config-generators-${Environment}-fleetProvisioningConfigLambdaName'