-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhmts-support-stack.yml
229 lines (227 loc) · 8.03 KB
/
hmts-support-stack.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
---
AWSTemplateFormatVersion: '2010-09-09'
Description: This is an AWS Cloudformation template that will create the source and targets and accompanying roles to quickly utilize the Healthshare Transformation Service.
Parameters:
PipelineName:
Description: The name of the pipeline, that will be used to create the resources.
Type: String
HL7SourceBucketKey:
Description: The key (folder) in the source bucket to pull from. (Enforced)
Type: String
Default: in
FHIRTargetBucketKey:
Description: The key (folder) in the source bucket to pull from. (enforced)
Type: String
Default: out
FHIRSourceBucketLoggingKey:
Description: The key (folder) in the source bucket to log to. (enforced)
Type: String
Default: logs
HMTSTransformType:
Description: Deploy a highly available IRIS deployment conditional
Default: "s3tos3"
Type: String
AllowedValues:
- "s3tos3"
- "s3tohl"
Conditions:
ShouldCreateS3toS3: !Equals
- "s3tos3"
- !Ref HMTSTransformType
ShouldCreateS3toHL: !Equals
- "s3tohl"
- !Ref HMTSTransformType
Resources:
HL7SourceBucket:
Type: AWS::S3::Bucket
Condition: ShouldCreateS3toS3
Properties:
BucketName: !Sub ${PipelineName}-hmts-source
PublicAccessBlockConfiguration:
BlockPublicAcls: true
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
FHIRTargetBucket:
Type: AWS::S3::Bucket
Condition: ShouldCreateS3toS3
Properties:
BucketName: !Sub ${PipelineName}-hmts-target
PublicAccessBlockConfiguration:
BlockPublicAcls: true
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
HealthLake:
Type: AWS::HealthLake::FHIRDatastore
Condition: ShouldCreateS3toHL
Properties:
DatastoreName: !Sub ${PipelineName}
DatastoreTypeVersion: R4
IAMRoleS3toS3:
Type: AWS::IAM::Role
Condition: ShouldCreateS3toS3
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- s3.amazonaws.com
Action:
- sts:AssumeRole
Path: /
Policies:
- PolicyName: HMTSBucketAccess
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- s3:PutObject
- s3:GetObject
- s3:ListObject
- s3:DeleteObject
- s3:GetBucketLocation
Resource:
- !Sub "arn:aws:s3:::${PipelineName}-hmts-source"
- !Sub "arn:aws:s3:::${PipelineName}-hmts-source/*"
- !Sub "arn:aws:s3:::${PipelineName}-hmts-target"
- !Sub "arn:aws:s3:::${PipelineName}-hmts-target/*"
IAMRoleS3toHealthLake:
Type: AWS::IAM::Role
DependsOn: HealthLake
Condition: ShouldCreateS3toHL
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- s3.amazonaws.com
- healthlake.amazonaws.com
Action:
- sts:AssumeRole
Path: /
Policies:
- PolicyName: HMTSBucketHealthlakeAccess
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- s3:PutObject
- s3:GetObject
- s3:ListObject
- s3:DeleteObject
- s3:GetBucketLocation
- healthlake:CreateResource
- healthlake:ReadResource
- healthlake:DeleteResource
- healthlake:SearchWithGet
- healthlake:SearchWithPost
- healthlake:UpdateResource
- healthlake:GetCapabilities
Resource:
- !Sub "arn:aws:s3:::${PipelineName}-hmts-source"
- !Sub "arn:aws:s3:::${PipelineName}-hmts-source/*"
- !Sub "arn:aws:s3:::${PipelineName}-hmts-target"
- !Sub "arn:aws:s3:::${PipelineName}-hmts-target/*"
- !Sub "arn:aws:healthlake:${AWS::Region}:${AWS::AccountId}:datastore/fhir/$(Fn::GetAtt:[HealthLake, DatastoreId])"
BucketKeysRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Sub ${PipelineName}-lambda-role
AssumeRolePolicyDocument:
Statement:
- Action:
- sts:AssumeRole
Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Version: 2012-10-17
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AWSLambdaExecute
- arn:aws:iam::aws:policy/AmazonS3FullAccess
Path: /
BucketKeysFunction:
Type: AWS::Lambda::Function
Condition: ShouldCreateS3toS3
Properties:
Handler: "index.lambda_handler"
Role: !GetAtt BucketKeysRole.Arn #!If [ShouldCreateS3toS3, !Ref IAMRoleS3toS3, !Ref IAMRoleS3toHealthLake]
Runtime: python3.6
FunctionName: !Sub ${PipelineName}-hmts-keys
Description: Simply creates keys in buckets.
Timeout: "300"
Code:
ZipFile: !Sub |
import boto3
import cfnresponse
def lambda_handler(event, context):
pipeline_name = event['ResourceProperties']['PipelineName']
hl7_src_key = event['ResourceProperties']['HL7SourceBucketKey']
fhir_target_key = event['ResourceProperties']['FHIRTargetBucketKey']
fhir_src_logging_key = event['ResourceProperties']['FHIRSourceBucketLoggingKey']
if event['RequestType'] == "Create":
# Redeploy the Api After Changes from stack
try:
s3 = boto3.client('s3')
src_bucket = pipeline_name + '-hmts-source'
target_bucket = pipeline_name + '-hmts-target'
# create keys here
s3.put_object(Bucket=src_bucket, Key=hl7_src_key)
s3.put_object(Bucket=src_bucket, Key=fhir_src_logging_key)
s3.put_object(Bucket=target_bucket, Key=fhir_target_key)
except Exception as e:
print(e)
send_cfnresponse(event, context, "SUCCESS",
{'message': 'donesies'})
if event['RequestType'] == "Delete":
#
send_cfnresponse(event, context, "SUCCESS",
{'message': 'delete no op'})
if event['RequestType'] == "Update":
#
send_cfnresponse(event, context, "SUCCESS",
{'message': 'update no op'})
def send_cfnresponse(event, context, status, data):
if status == "SUCCESS":
cfnresponse.send(event, context, cfnresponse.SUCCESS, data)
else:
cfnresponse.send(event, context, cfnresponse.FAILED, data)
BucketKeysResource:
Type: "Custom::BucketKeysResource"
Properties:
ServiceToken: !GetAtt BucketKeysFunction.Arn
PipelineName: !Ref PipelineName
HL7SourceBucketKey: !Ref HL7SourceBucketKey
FHIRTargetBucketKey: !Ref FHIRTargetBucketKey
FHIRSourceBucketLoggingKey: !Ref FHIRSourceBucketLoggingKey
Outputs:
HMTSS3toS3RoleArn:
Condition: ShouldCreateS3toS3
Description: IAM Role for S3 to S3
Value:
Fn::GetAtt:
- IAMRoleS3toS3
- Arn
HMTSFHIRtoS3RoleArn:
Condition: ShouldCreateS3toHL
Description: IAM Role for S3 to Healthlake
Value:
Fn::GetAtt:
- IAMRoleS3toHealthLake
- Arn
Source:
Description: Upload HL7 Here
Value: !Sub ${PipelineName}-hmts-src/${HL7SourceBucketKey}
Target:
Description: FHIR Here
Value: !Sub ${PipelineName}-hmts-target/${FHIRTargetBucketKey}
Logging:
Description: Logs Here
Value: !Sub ${PipelineName}-hmts-src/${FHIRSourceBucketLoggingKey}