@@ -47,26 +47,62 @@ export class DataLakeEnrollment extends cdk.Construct {
4747 public grantRead ( principal : iam . Role ) {
4848
4949
50- const dataLakeBucket = s3 . Bucket . fromBucketName ( this , 'dataLakeBucket' , this . DataEnrollment . DataLakeBucketName ) ;
51- dataLakeBucket . grantRead ( principal , this . DataEnrollment . DataLakePrefix + "*" )
50+ const s3Policy = {
51+ "Action" : [
52+ "s3:GetObject*" ,
53+ "s3:GetBucket*" ,
54+ "s3:List*"
55+ ] ,
56+ "Resource" : [
57+ `arn:aws:s3:::${ this . DataEnrollment . DataLakeBucketName } ` ,
58+ `arn:aws:s3:::${ this . DataEnrollment . DataLakeBucketName } ${ this . DataEnrollment . DataLakePrefix } *`
59+ ] ,
60+ "Effect" : "Allow"
61+ } ;
62+
63+
64+ const s3PolicyStatement = iam . PolicyStatement . fromJson ( s3Policy ) ;
65+
66+ const gluePolicy = {
67+ "Action" : [
68+ "glue:GetDatabase" ,
69+ "glue:GetTable" ,
70+ ] ,
71+ "Resource" : [
72+ `arn:aws:glue:${ cdk . Stack . of ( this ) . region } :${ cdk . Stack . of ( this ) . account } :catalog` ,
73+ `arn:aws:glue:${ cdk . Stack . of ( this ) . region } :${ cdk . Stack . of ( this ) . account } :database/default` ,
74+ this . DataEnrollment . Dataset_Datalake . databaseArn ,
75+ `arn:aws:glue:${ cdk . Stack . of ( this ) . region } :${ cdk . Stack . of ( this ) . account } :table/${ this . DataEnrollment . Dataset_Datalake . databaseName } /*`
76+ ] ,
77+ "Effect" : "Allow"
78+ } ;
79+ const gluePolicyStatement = iam . PolicyStatement . fromJson ( gluePolicy ) ;
80+
81+
82+ const athenaPolicy = {
83+ "Action" : [
84+ "athena:BatchGetNamedQuery" ,
85+ "athena:BatchGetQueryExecution" ,
86+ "athena:GetQueryExecution" ,
87+ "athena:GetQueryResults" ,
88+ "athena:GetQueryResultsStream" ,
89+ "athena:GetWorkGroup" ,
90+ "athena:ListTagsForResource"
91+ ] ,
92+ "Resource" : [
93+ `arn:aws:athena:${ cdk . Stack . of ( this ) . region } :${ cdk . Stack . of ( this ) . account } :*`
94+
95+ ] ,
96+ "Effect" : "Allow"
97+ } ;
98+ const athenaPolicyStatement = iam . PolicyStatement . fromJson ( athenaPolicy ) ;
5299
53- const gluePolicy = new iam . PolicyStatement ( {
54- actions : [ "glue:GetDatabase" ] ,
55- effect : iam . Effect . ALLOW ,
56- resources : [ `arn:aws:glue:${ cdk . Stack . of ( this ) . region } :${ cdk . Stack . of ( this ) . account } :catalog` ,
57- `arn:aws:glue:${ cdk . Stack . of ( this ) . region } :${ cdk . Stack . of ( this ) . account } :database/default` ,
58- this . DataEnrollment . Dataset_Datalake . databaseArn
59- ]
60- } ) ;
61100
62- const athenaPolicy = new iam . PolicyStatement ( {
63- actions : [ "athena:*" ] ,
64- effect : iam . Effect . ALLOW ,
65- resources : [ "*" ] ,
66- } ) ;
101+
102+ principal . addToPolicy ( gluePolicyStatement ) ;
103+ principal . addToPolicy ( s3PolicyStatement ) ;
104+ principal . addToPolicy ( athenaPolicyStatement ) ;
67105
68- principal . addToPolicy ( gluePolicy ) ;
69- principal . addToPolicy ( athenaPolicy ) ;
70106
71107
72108 }
0 commit comments