@@ -54,12 +54,17 @@ Parameters:
5454 Description : " (Optional) An IAM policy ARN to use as the PermissionsBoundary for the created Lambda function's execution role"
5555 Default : ' '
5656 Type : String
57+ LambdaRoleArn :
58+ Description : " (Optional) A custom role to be used by the Connector lambda"
59+ Type : String
60+ Default : " "
5761Conditions :
5862 HasPermissionsBoundary : !Not [ !Equals [ !Ref PermissionsBoundaryARN, "" ] ]
5963 HasSecurityGroups : !Not [ !Equals [ !Join ["", !Ref SecurityGroupIds], "" ] ]
6064 HasSubnets : !Not [ !Equals [ !Join ["", !Ref SubnetIds], "" ] ]
6165 IsRegionBAH : !Equals [!Ref "AWS::Region", "me-south-1"]
6266 IsRegionHKG : !Equals [!Ref "AWS::Region", "ap-east-1"]
67+ NotHasLambdaRole : !Equals [ !Ref LambdaRoleArn, "" ]
6368Resources :
6469 JdbcConnectorConfig :
6570 Type : ' AWS::Serverless::Function'
@@ -76,43 +81,84 @@ Resources:
7681 - ' ${Account}.dkr.ecr.${AWS::Region}.amazonaws.com/athena-federation-repository-snowflake:2022.47.1'
7782 - Account : !If [IsRegionBAH, 084828588479, !If [IsRegionHKG, 183295418215, 292517598671]]
7883 ImageConfig :
79- Command : [ "com.amazonaws.athena.connectors.snowflake.SnowflakeMuxCompositeHandler " ]
84+ Command : [ "com.amazonaws.athena.connectors.snowflake.SnowflakeCompositeHandler " ]
8085 Description : " Enables Amazon Athena to communicate with Snowflake using JDBC"
8186 Timeout : !Ref LambdaTimeout
8287 MemorySize : !Ref LambdaMemory
88+ Role : !If [ NotHasLambdaRole, !GetAtt FunctionRole.Arn, !Ref LambdaRoleArn ]
89+ VpcConfig :
90+ SecurityGroupIds : !If [ HasSecurityGroups, !Ref SecurityGroupIds, !Ref "AWS::NoValue" ]
91+ SubnetIds : !If [ HasSubnets, !Ref SubnetIds, !Ref "AWS::NoValue" ]
92+
93+ FunctionRole :
94+ Condition : NotHasLambdaRole
95+ Type : AWS::IAM::Role
96+ Properties :
8397 PermissionsBoundary : !If [ HasPermissionsBoundary, !Ref PermissionsBoundaryARN, !Ref "AWS::NoValue" ]
84- Policies :
85- - Statement :
86- - Action :
87- - secretsmanager:GetSecretValue
88- Effect : Allow
89- Resource : !Sub 'arn:${AWS::Partition}:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:${SecretNamePrefix}*'
90- Version : ' 2012-10-17'
91- - Statement :
92- - Action :
93- - logs:CreateLogGroup
94- Effect : Allow
95- Resource : !Sub 'arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:*'
96- Version : ' 2012-10-17'
97- - Statement :
98- - Action :
99- - logs:CreateLogStream
100- - logs:PutLogEvents
101- Effect : Allow
102- Resource : !Sub 'arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/${LambdaFunctionName}:*'
103- Version : ' 2012-10-17'
104- - Statement :
105- - Action :
106- - athena:GetQueryExecution
107- Effect : Allow
108- Resource : ' *'
109- Version : ' 2012-10-17'
98+ ManagedPolicyArns :
99+ - !Sub " arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
100+ AssumeRolePolicyDocument :
101+ Version : 2012-10-17
102+ Statement :
103+ - Effect : Allow
104+ Principal :
105+ Service :
106+ - lambda.amazonaws.com
107+ AWS : ' *'
108+ Action :
109+ - " sts:AssumeRole"
110+
111+ FunctionExecutionPolicy :
112+ Condition : NotHasLambdaRole
113+ Type : " AWS::IAM::Policy"
114+ Properties :
115+ PolicyName : FunctionExecutionPolicy
116+ PolicyDocument :
117+ Version : 2012-10-17
118+ Statement :
119+ - Action :
120+ - secretsmanager:GetSecretValue
121+ Effect : Allow
122+ Resource : !Sub 'arn:${AWS::Partition}:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:${SecretNamePrefix}*'
123+ - Action :
124+ - logs:CreateLogGroup
125+ Effect : Allow
126+ Resource : !Sub 'arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:*'
127+ - Action :
128+ - logs:CreateLogStream
129+ - logs:PutLogEvents
130+ Effect : Allow
131+ Resource : !Sub 'arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/${LambdaFunctionName}:*'
132+ - Action :
133+ - lambda:GetFunction
134+ Effect : Allow
135+ Resource : !Sub 'arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${LambdaFunctionName}'
136+ - Action :
137+ - athena:GetQueryExecution
138+ Effect : Allow
139+ Resource : ' *'
110140 # S3CrudPolicy allows our connector to spill large responses to S3. You can optionally replace this pre-made policy
111141 # with one that is more restrictive and can only 'put' but not read,delete, or overwrite files.
112- - S3CrudPolicy :
113- BucketName : !Ref SpillBucket
114- # VPCAccessPolicy allows our connector to run in a VPC so that it can access your data source.
115- - VPCAccessPolicy : {}
116- VpcConfig :
117- SecurityGroupIds : !If [ HasSecurityGroups, !Ref SecurityGroupIds, !Ref "AWS::NoValue" ]
118- SubnetIds : !If [ HasSubnets, !Ref SubnetIds, !Ref "AWS::NoValue" ]
142+ - Action :
143+ - s3:GetObject
144+ - s3:GetObjectVersion
145+ - s3:ListBucket
146+ - s3:GetBucketLocation
147+ - s3:PutObject
148+ - s3:PutObjectAcl
149+ - s3:GetLifecycleConfiguration
150+ - s3:PutLifecycleConfiguration
151+ - s3:DeleteObject
152+ - s3:DeleteObjectVersion
153+ Effect : Allow
154+ Resource :
155+ - Fn::Sub :
156+ - arn:${AWS::Partition}:s3:::${bucketName}
157+ - bucketName :
158+ Ref : SpillBucket
159+ - Fn::Sub :
160+ - arn:${AWS::Partition}:s3:::${bucketName}/*
161+ - bucketName :
162+ Ref : SpillBucket
163+ Roles :
164+ - !Ref FunctionRole
0 commit comments