-
Notifications
You must be signed in to change notification settings - Fork 4
/
template.yaml
210 lines (195 loc) · 6.2 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >-
A Cloudformation custom resource to apply Sage Bionetworks Synapse data to cloud resources
Metadata:
AWS::ServerlessRepo::Application:
Name: "cfn-cr-synapse-tagger"
Description: >-
A Cloudformation custom resource to apply Sage Bionetworks Synapse data to cloud resources
Author: "Sage-Bionetworks"
SpdxLicenseId: "Apache-2.0"
# paths are relative to .aws-sam/build directory
LicenseUrl: "LICENSE"
ReadmeUrl: "README.md"
Labels: ["serverless", "custom-resource", "cloudformation", "synapse", "tags"]
HomePageUrl: "https://github.com/Sage-Bionetworks-IT/cfn-cr-synapse-tagger"
SemanticVersion: "0.0.11"
SourceCodeUrl: "https://github.com/Sage-Bionetworks-IT/cfn-cr-synapse-tagger/tree/0.0.11"
Parameters:
TeamToRoleArnMapParamName:
Description: 'The TeamToRoleArnMap parameter name in the SSM parameter store'
Type: String
Default: '/service-catalog/TeamToRoleArnMap'
Globals:
Function:
Timeout: 180
Runtime: python3.8
Handler: app.handler
Resources:
SetBatchTagsFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: .
Handler: set_tags/set_batch_tags.handler
Role: !GetAtt SetBatchTagsFunctionRole.Arn
Environment:
Variables:
TEAM_TO_ROLE_ARN_MAP_PARAM_NAME: !Ref TeamToRoleArnMapParamName
SetBatchTagsFunctionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
- !Ref BatchTagPolicy
- !Ref SsmManagedPolicy
- !Ref CloudformationAccessPolicy
BatchTagPolicy:
Type: AWS::IAM::ManagedPolicy
Properties:
PolicyDocument:
Version: '2012-10-17'
Statement:
- Sid: GetAndPutBatchTags
Effect: 'Allow'
Action:
- 'batch:ListTagsForResource'
- 'batch:TagResource'
- 'batch:UntagResource'
Resource: '*'
SetBucketTagsFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: .
Handler: set_tags/set_bucket_tags.handler
Role: !GetAtt SetBucketTagsFunctionRole.Arn
Environment:
Variables:
TEAM_TO_ROLE_ARN_MAP_PARAM_NAME: !Ref TeamToRoleArnMapParamName
SetBucketTagsFunctionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
- !Ref BucketTagPolicy
- !Ref SsmManagedPolicy
BucketTagPolicy:
Type: AWS::IAM::ManagedPolicy
Properties:
PolicyDocument:
Version: '2012-10-17'
Statement:
- Sid: GetAndPutBucketTags
Effect: 'Allow'
Action:
- 's3:GetBucketTagging'
- 's3:PutBucketTagging'
Resource: '*'
SetInstanceTagsFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: .
Handler: set_tags/set_instance_tags.handler
Role: !GetAtt SetInstanceTagsFunctionRole.Arn
Environment:
Variables:
TEAM_TO_ROLE_ARN_MAP_PARAM_NAME: !Ref TeamToRoleArnMapParamName
SetInstanceTagsFunctionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
- !Ref InstanceTagPolicy
- !Ref SsmManagedPolicy
InstanceTagPolicy:
Type: AWS::IAM::ManagedPolicy
Properties:
PolicyDocument:
Version: '2012-10-17'
Statement:
- Sid: AccessInstanceTags
Effect: 'Allow'
Action:
- 'EC2:Describe*'
- 'EC2:CreateTags'
- 'EC2:DeleteTags'
- 'iam:ListRoles'
- 'iam:GetRole'
Resource: '*'
SsmManagedPolicy:
Type: AWS::IAM::ManagedPolicy
Properties:
PolicyDocument:
Version: 2012-10-17
Statement:
- Sid: GetParamAccess
Action:
- 'ssm:*'
Effect: Allow
Resource:
- !Sub 'arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter${TeamToRoleArnMapParamName}'
CloudformationAccessPolicy:
Type: AWS::IAM::ManagedPolicy
Properties:
PolicyDocument:
Version: '2012-10-17'
Statement:
- Sid: GetAndPutBatchTags
Effect: 'Allow'
Action:
- 'cloudformation:Describe*'
- 'cloudformation:Get*'
- 'cloudformation:List*'
Resource: '*'
Outputs:
SetBatchTagsFunctionName:
Value: !Ref SetBatchTagsFunction
Export:
Name: !Sub '${AWS::Region}-${AWS::StackName}-SetBatchTagsFunctionName'
SetBatchTagsFunctionArn:
Value: !GetAtt SetBatchTagsFunction.Arn
Export:
Name: !Sub '${AWS::Region}-${AWS::StackName}-SetBatchTagsFunctionArn'
SetBucketTagsFunctionName:
Value: !Ref SetBucketTagsFunction
Export:
Name: !Sub '${AWS::Region}-${AWS::StackName}-SetBucketTagsFunctionName'
SetBucketTagsFunctionArn:
Value: !GetAtt SetBucketTagsFunction.Arn
Export:
Name: !Sub '${AWS::Region}-${AWS::StackName}-SetBucketTagsFunctionArn'
SetInstanceTagsFunctionName:
Value: !Ref SetInstanceTagsFunction
Export:
Name: !Sub '${AWS::Region}-${AWS::StackName}-SetInstanceTagsFunctionName'
SetInstanceTagsFunctionArn:
Value: !GetAtt SetInstanceTagsFunction.Arn
Export:
Name: !Sub '${AWS::Region}-${AWS::StackName}-SetInstanceTagsFunctionArn'