@@ -30,6 +30,9 @@ Parameters:
3030 Description : ' The prefix within SpillBucket where this function can spill data.'
3131 Type : String
3232 Default : athena-spill
33+ SnowflakeExportBucket :
34+ Description : " The bucket where the Snowflake Query results will be exported."
35+ Type : String
3336 LambdaTimeout :
3437 Description : ' Maximum Lambda invocation runtime in seconds. (min 1 - 900 max)'
3538 Default : 900
@@ -54,12 +57,17 @@ Parameters:
5457 Description : " (Optional) An IAM policy ARN to use as the PermissionsBoundary for the created Lambda function's execution role"
5558 Default : ' '
5659 Type : String
60+ LambdaRoleArn :
61+ Description : " (Optional) A custom role to be used by the Connector lambda"
62+ Type : String
63+ Default : " "
5764Conditions :
5865 HasPermissionsBoundary : !Not [ !Equals [ !Ref PermissionsBoundaryARN, "" ] ]
5966 HasSecurityGroups : !Not [ !Equals [ !Join ["", !Ref SecurityGroupIds], "" ] ]
6067 HasSubnets : !Not [ !Equals [ !Join ["", !Ref SubnetIds], "" ] ]
6168 IsRegionBAH : !Equals [!Ref "AWS::Region", "me-south-1"]
6269 IsRegionHKG : !Equals [!Ref "AWS::Region", "ap-east-1"]
70+ NotHasLambdaRole : !Equals [ !Ref LambdaRoleArn, "" ]
6371Resources :
6472 JdbcConnectorConfig :
6573 Type : ' AWS::Serverless::Function'
@@ -70,49 +78,107 @@ Resources:
7078 spill_bucket : !Ref SpillBucket
7179 spill_prefix : !Ref SpillPrefix
7280 default : !Ref DefaultConnectionString
81+ export_bucket : !Ref SnowflakeExportBucket
7382 FunctionName : !Ref LambdaFunctionName
7483 PackageType : " Image"
7584 ImageUri : !Sub
7685 - ' ${Account}.dkr.ecr.${AWS::Region}.amazonaws.com/athena-federation-repository-snowflake:2022.47.1'
7786 - Account : !If [IsRegionBAH, 084828588479, !If [IsRegionHKG, 183295418215, 292517598671]]
7887 ImageConfig :
79- Command : [ "com.amazonaws.athena.connectors.snowflake.SnowflakeMuxCompositeHandler " ]
88+ Command : [ "com.amazonaws.athena.connectors.snowflake.SnowflakeCompositeHandler " ]
8089 Description : " Enables Amazon Athena to communicate with Snowflake using JDBC"
8190 Timeout : !Ref LambdaTimeout
8291 MemorySize : !Ref LambdaMemory
92+ Role : !If [ NotHasLambdaRole, !GetAtt FunctionRole.Arn, !Ref LambdaRoleArn ]
93+ VpcConfig :
94+ SecurityGroupIds : !If [ HasSecurityGroups, !Ref SecurityGroupIds, !Ref "AWS::NoValue" ]
95+ SubnetIds : !If [ HasSubnets, !Ref SubnetIds, !Ref "AWS::NoValue" ]
96+
97+ FunctionRole :
98+ Condition : NotHasLambdaRole
99+ Type : AWS::IAM::Role
100+ Properties :
83101 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'
102+ ManagedPolicyArns :
103+ - !Sub " arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
104+ AssumeRolePolicyDocument :
105+ Version : 2012-10-17
106+ Statement :
107+ - Effect : Allow
108+ Principal :
109+ Service :
110+ - lambda.amazonaws.com
111+ AWS : ' *'
112+ Action :
113+ - " sts:AssumeRole"
114+
115+ FunctionExecutionPolicy :
116+ Condition : NotHasLambdaRole
117+ Type : " AWS::IAM::Policy"
118+ Properties :
119+ PolicyName : FunctionExecutionPolicy
120+ PolicyDocument :
121+ Version : 2012-10-17
122+ Statement :
123+ - Action :
124+ - secretsmanager:GetSecretValue
125+ Effect : Allow
126+ Resource : !Sub 'arn:${AWS::Partition}:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:${SecretNamePrefix}*'
127+ - Action :
128+ - logs:CreateLogGroup
129+ Effect : Allow
130+ Resource : !Sub 'arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:*'
131+ - Action :
132+ - logs:CreateLogStream
133+ - logs:PutLogEvents
134+ Effect : Allow
135+ Resource : !Sub 'arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/${LambdaFunctionName}:*'
136+ - Action :
137+ - lambda:GetFunction
138+ Effect : Allow
139+ Resource : !Sub 'arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${LambdaFunctionName}'
140+ - Action :
141+ - athena:GetQueryExecution
142+ Effect : Allow
143+ Resource : ' *'
110144 # S3CrudPolicy allows our connector to spill large responses to S3. You can optionally replace this pre-made policy
111145 # 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" ]
146+ - Action :
147+ - s3:GetObject
148+ - s3:ListBucket
149+ - s3:GetBucketLocation
150+ - s3:GetObjectVersion
151+ - s3:PutObject
152+ - s3:PutObjectAcl
153+ - s3:GetLifecycleConfiguration
154+ - s3:PutLifecycleConfiguration
155+ - s3:DeleteObject
156+ Effect : Allow
157+ Resource :
158+ - Fn::Sub :
159+ - arn:${AWS::Partition}:s3:::${bucketName}
160+ - bucketName :
161+ Ref : SpillBucket
162+ - Fn::Sub :
163+ - arn:${AWS::Partition}:s3:::${bucketName}/*
164+ - bucketName :
165+ Ref : SpillBucket
166+ - Action :
167+ - s3:GetObject
168+ - s3:GetObjectVersion
169+ - s3:PutObject
170+ - s3:DeleteObject
171+ - s3:DeleteObjectVersion
172+ Effect : Allow
173+ Resource : !Sub 'arn:${AWS::Partition}:s3:::${SnowflakeExportBucket}/*'
174+ - Action :
175+ - s3:ListBucket
176+ - s3:GetBucketLocation
177+ Effect : Allow
178+ Resource : !Sub 'arn:${AWS::Partition}:s3:::${SnowflakeExportBucket}'
179+ Condition :
180+ StringLike :
181+ " s3:prefix " :
182+ - !Sub " *"
183+ Roles :
184+ - !Ref FunctionRole
0 commit comments