Skip to content

Commit ccb1f6f

Browse files
author
Varun Rao Bhamidimarri
committed
Merge branch 'beta' into main
2 parents f4175fc + d631083 commit ccb1f6f

15 files changed

+878
-105
lines changed
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
AWSTemplateFormatVersion: 2010-09-09
2+
Description: Copy S3 object to local S3 bucket
3+
4+
Parameters:
5+
6+
S3BucketSources:
7+
Type: String
8+
Description: S3 bucket with source files
9+
MaxLength: 63
10+
MinLength: 3
11+
Default: aws-bigdata-blog
12+
AllowedValues: ["aws-bigdata-blog"]
13+
S3SourcesPrefix:
14+
Type: String
15+
Description: S3 prefix with sources WITH ending slash
16+
MaxLength: 63
17+
MinLength: 3
18+
Default: artifacts/aws-blog-emr-ranger
19+
AllowedValues: ["artifacts/aws-blog-emr-ranger"]
20+
ProjectVersion:
21+
Default: 3.0
22+
Description: Project version
23+
Type: String
24+
AllowedValues:
25+
- 3.0
26+
- beta
27+
S3Objects:
28+
Type: CommaDelimitedList
29+
Description: S3 Object to be copied
30+
Default: launch-cluster.zip, scripts/download-scripts.sh, scripts/remove-yum-package-name-validator.sh, scripts/configure_ranger_glue_support_with_bootstrap.sh, scripts/enable-glue-catalog-support.sh, scripts/create-hdfs-home-ba.sh, scripts/setup-trino-redshift-connector.sh
31+
32+
Resources:
33+
34+
S3BucketRegionSources:
35+
Type: AWS::S3::Bucket
36+
Properties:
37+
BucketEncryption:
38+
ServerSideEncryptionConfiguration:
39+
- ServerSideEncryptionByDefault:
40+
SSEAlgorithm: AES256
41+
DeletionPolicy: Delete
42+
43+
CopyZips:
44+
Type: AWS::CloudFormation::CustomResource
45+
DependsOn:
46+
- S3BucketRegionSources
47+
Properties:
48+
ServiceToken: !GetAtt 'CopyZipsFunction.Arn'
49+
DestBucket: !Ref 'S3BucketRegionSources'
50+
SourceBucket: !Ref 'S3BucketSources'
51+
SourcePrefix: !Ref 'S3SourcesPrefix'
52+
ProjectVersion: !Ref 'ProjectVersion'
53+
Counter: "1"
54+
Objects: !Ref S3Objects
55+
56+
CopyZipsRole:
57+
Type: AWS::IAM::Role
58+
Properties:
59+
AssumeRolePolicyDocument:
60+
Version: '2012-10-17'
61+
Statement:
62+
- Effect: Allow
63+
Principal:
64+
Service: lambda.amazonaws.com
65+
Action: sts:AssumeRole
66+
ManagedPolicyArns:
67+
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
68+
Path: /
69+
Policies:
70+
- PolicyName: lambda-copier
71+
PolicyDocument:
72+
Version: '2012-10-17'
73+
Statement:
74+
- Effect: Allow
75+
Action:
76+
- s3:GetObject
77+
- s3:GetObjectTagging
78+
Resource:
79+
- !Sub 'arn:aws:s3:::${S3BucketSources}/*'
80+
- Effect: Allow
81+
Action:
82+
- s3:ListBucket
83+
Resource:
84+
- !Sub 'arn:aws:s3:::${S3BucketSources}'
85+
- Effect: Allow
86+
Action:
87+
- s3:ListBucket
88+
Resource:
89+
- !Sub 'arn:aws:s3:::${S3BucketRegionSources}'
90+
- Effect: Allow
91+
Action:
92+
- s3:PutObject
93+
- s3:DeleteObject
94+
- s3:PutObjectTagging
95+
Resource:
96+
- !Sub 'arn:aws:s3:::${S3BucketRegionSources}/*'
97+
98+
CopyZipsFunction:
99+
Type: AWS::Lambda::Function
100+
Properties:
101+
FunctionName: "CopyRangerArtifacts"
102+
Description: Copies objects from a source S3 bucket to a destination
103+
Handler: index.handler
104+
Runtime: python3.9
105+
Role: !GetAtt 'CopyZipsRole.Arn'
106+
Timeout: 240
107+
Code:
108+
ZipFile: |
109+
import json
110+
import logging
111+
import threading
112+
import boto3
113+
import cfnresponse
114+
115+
def copy_objects(source_bucket, dest_bucket, objects, prefix, project_version):
116+
s3 = boto3.client('s3')
117+
for o in objects:
118+
key = prefix + '/' + project_version + '/' + o
119+
copy_source = {
120+
'Bucket': source_bucket,
121+
'Key': key
122+
}
123+
print('copy source_bucket:' + source_bucket + ' destination_bucket: '+ dest_bucket + ' key: ' + key)
124+
s3.copy_object(CopySource=copy_source, Bucket=dest_bucket, Key=key)
125+
126+
def delete_objects(bucket, objects, prefix, project_version):
127+
s3 = boto3.client('s3')
128+
objects = {'Objects': [{'Key': prefix + '/' + project_version + '/' + o} for o in objects]}
129+
s3.delete_objects(Bucket=bucket, Delete=objects)
130+
s3_list_response = s3.list_objects_v2(Bucket=bucket, Prefix=prefix + '/' + project_version + '/emr-tls/')
131+
if 'Contents' in s3_list_response:
132+
for object in s3_list_response['Contents']:
133+
print('Deleting', object['Key'])
134+
s3.delete_object(Bucket=bucket, Key=object['Key'])
135+
136+
def timeout(event, context):
137+
logging.error('Execution is about to time out, sending failure response to CloudFormation')
138+
cfnresponse.send(event, context, cfnresponse.FAILED, {}, None)
139+
140+
def handler(event, context):
141+
# make sure we send a failure to CloudFormation if the function is going to timeout
142+
timer = threading.Timer((context.get_remaining_time_in_millis() / 1000.00) - 0.5, timeout, args=[event, context])
143+
timer.start()
144+
145+
print('Received event: %s' % json.dumps(event))
146+
status = cfnresponse.SUCCESS
147+
try:
148+
source_bucket = event['ResourceProperties']['SourceBucket']
149+
source_prefix = event['ResourceProperties']['SourcePrefix']
150+
project_version = event['ResourceProperties']['ProjectVersion']
151+
dest_bucket = event['ResourceProperties']['DestBucket']
152+
if source_bucket == dest_bucket:
153+
return
154+
objects = event['ResourceProperties']['Objects']
155+
if event['RequestType'] == 'Delete':
156+
delete_objects(dest_bucket, objects, source_prefix, project_version)
157+
else:
158+
copy_objects(source_bucket, dest_bucket, objects, source_prefix, project_version)
159+
except Exception as e:
160+
logging.error('Exception: %s' % e, exc_info=True)
161+
status = cfnresponse.FAILED
162+
finally:
163+
timer.cancel()
164+
cfnresponse.send(event, context, status, {}, None)
165+
166+
Outputs:
167+
168+
RegionalS3Bucket:
169+
Description: Regional S3 bucket with artifacts required by the EMR cluster. This bucket can be reused as the 'S3Bucket' value for future EMR cluster stacks
170+
Value: !Ref S3BucketRegionSources

aws_emr_blog_v3/cloudformation/ec2-win-ad.template

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,28 @@ Resources:
290290
- !Ref 'DefaultADUserPassword'
291291
- "' -Force)\n"
292292
- "Enable-ADAccount -Identity \"analyst2\"\n"
293+
- "New-ADUser -Name \"tina\" -OtherAttributes @{'title'=\"tina\";'mail'=\"tina@"
294+
- !Ref 'DomainDNSName'
295+
- "\"}\n"
296+
- "Enable-ADAccount -Identity \"tina\"\n"
297+
- "Set-ADAccountPassword -Identity 'tina' -Reset -NewPassword (ConvertTo-SecureString -AsPlainText '"
298+
- !Ref 'DefaultADUserPassword'
299+
- "' -Force)\n"
300+
- "Enable-ADAccount -Identity \"tina\"\n"
301+
- "New-ADUser -Name \"alex\" -OtherAttributes @{'title'=\"alex\";'mail'=\"alex@"
302+
- !Ref 'DomainDNSName'
303+
- "\"}\n"
304+
- "Enable-ADAccount -Identity \"alex\"\n"
305+
- "Set-ADAccountPassword -Identity 'alex' -Reset -NewPassword (ConvertTo-SecureString -AsPlainText '"
306+
- !Ref 'DefaultADUserPassword'
307+
- "' -Force)\n"
308+
- "Enable-ADAccount -Identity \"alex\"\n"
309+
- "$domain='"
310+
- !Ref 'DomainDNSName'
311+
- "'\n"
312+
- "Get-ADUser -Filter * -SearchBase ('DC={0},DC={1}' -f $domain.split(\".\")[0],$domain.split(\".\")[1]) -Properties userPrincipalName | foreach { Set-ADUser $_ -UserPrincipalName (\"{0}@{1}\" -f $_.name,$domain)}\n"
313+
- "New-ADGroup -Name \"DataScience\" -SamAccountName DataScience -GroupCategory Security -GroupScope Global -DisplayName \"DataScience\" -Path ('CN=Users,DC={0},DC={1}' -f $domain.split(\".\")[0],$domain.split(\".\")[1]) -Description \"Members of this group have access to data science resources and data sets\"\n"
314+
- "Add-ADGroupMember -Identity \"DataScience\" -Members alex,tina \n"
293315
services:
294316
windows:
295317
cfn-hup:
@@ -491,3 +513,8 @@ Outputs:
491513
ADDomainJoinUser:
492514
Description: The DomainAdminUser
493515
Value: !Ref 'DomainAdminUser'
516+
ADSecurityGroupID:
517+
Description: AD security group ID.
518+
Value: !Ref SecurityGroup
519+
Export:
520+
Name: !Sub ${AWS::StackName}-ADSecurityGroupID

aws_emr_blog_v3/cloudformation/emr-template.template

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ Parameters:
247247
- emr-6.3.0
248248
- emr-6.4.0
249249
- emr-6.7.0
250+
- emr-6.8.0
250251
Description: Release label for the EMR cluster
251252
AppsEMR:
252253
Description: 'Comma separated list of applications to install on the cluster e.g., '
@@ -365,6 +366,11 @@ Parameters:
365366
Default: false
366367
Type: String
367368
AllowedValues: [ true, false ]
369+
InstallRangerHDFSPlugin:
370+
Description: Flag to control if the Ranger HDFS plugin will be added
371+
Default: false
372+
Type: String
373+
AllowedValues: [ true, false ]
368374
Conditions:
369375
USEastRegion: !Equals [ !Ref 'AWS::Region', "us-east-1" ]
370376
EnableKerberos: !Equals [true, !Ref EnableKerberos]
@@ -449,6 +455,23 @@ Resources:
449455
- arn:aws:iam::aws:policy/service-role/AmazonElasticMapReduceforEC2Role
450456
- arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore
451457
- arn:aws:iam::aws:policy/CloudWatchFullAccess
458+
AllowSecretsRetrievalPolicy:
459+
Type: 'AWS::IAM::Policy'
460+
DependsOn: EmrEc2Role
461+
Properties:
462+
PolicyName: AllowSecretsRetrievalPolicy
463+
PolicyDocument:
464+
Version: 2012-10-17
465+
Statement:
466+
- Effect: Allow
467+
Action:
468+
- secretsmanager:GetSecretValue
469+
- secretsmanager:ListSecrets
470+
- secretsmanager:DescribeSecret
471+
Resource:
472+
- !Join [ '', [ 'arn:aws:secretsmanager:', !Ref "AWS::Region", ':', !Ref "AWS::AccountId", ':secret:emr/ranger*' ] ]
473+
Roles:
474+
- !Ref EmrEc2Role
452475
DataAccessRoleARN:
453476
Type: AWS::IAM::Role
454477
Properties:
@@ -497,22 +520,6 @@ Resources:
497520
- !GetAtt 'DataAccessRoleARN.Arn'
498521
Roles:
499522
- !Ref EmrEc2Role
500-
501-
AllowSecretsRetrievalPolicy:
502-
Type: 'AWS::IAM::Policy'
503-
Properties:
504-
PolicyName: AllowSecretsRetrieval
505-
PolicyDocument:
506-
Version: 2012-10-17
507-
Statement:
508-
- Effect: Allow
509-
Action:
510-
- secretsmanager:GetSecretValue
511-
Resource:
512-
- !Join ['', ['arn:aws:secretsmanager:', !Ref "AWS::Region", ':', !Ref "AWS::AccountId", ':secret:', !Ref RangerAgentKeySecretName, '*']]
513-
- !Join ['', ['arn:aws:secretsmanager:', !Ref "AWS::Region", ':', !Ref "AWS::AccountId", ':secret:', !Ref RangerServerCertSecretName, '*']]
514-
Roles:
515-
- !Ref EmrEc2Role
516523
EMRInstanceProfile:
517524
Type: AWS::IAM::InstanceProfile
518525
Properties:
@@ -563,7 +570,7 @@ Resources:
563570
InTransitEncryptionConfiguration:
564571
TLSCertificateConfiguration:
565572
CertificateProviderType: PEM
566-
S3Object: !Join ['', ["s3://", !Ref S3ArtifactBucket, "/", !Ref S3ArtifactKey, "/", !Ref ProjectVersion, "/emr-tls/", "emr-certs-certs.zip"]]
573+
S3Object: !Join ['', ["s3://", !Ref S3Bucket, "/", !Ref S3Key, "/", !Ref ProjectVersion, "/emr-tls/", "emr-certs-certs.zip"]]
567574
LaunchEMRClusterFunction:
568575
Type: AWS::Lambda::Function
569576
DependsOn: LambdaExecutionRole
@@ -636,6 +643,7 @@ Resources:
636643
DefaultDomain: !If [ USEastRegion, 'EC2.INTERNAL', 'COMPUTE.INTERNAL' ]
637644
EnableIcebergSupport: !Ref EnableIcebergSupport
638645
EnableGlueSupport: !Ref EnableGlueSupport
646+
InstallRangerHDFSPlugin: !Ref InstallRangerHDFSPlugin
639647
emrCreateWaitHandle:
640648
Type: AWS::CloudFormation::WaitConditionHandle
641649
Properties: {}

aws_emr_blog_v3/cloudformation/ranger-server.template

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)