@@ -54,12 +54,24 @@ 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 : " "
61+ EnableS3Export :
62+ Description : ' (Optional) Enable S3 export functionality for data transfer. Set to true to use S3 export path, false for direct query path.'
63+ Type : String
64+ Default : ' false'
65+ AllowedValues :
66+ - ' true'
67+ - ' false'
5768Conditions :
5869 HasPermissionsBoundary : !Not [ !Equals [ !Ref PermissionsBoundaryARN, "" ] ]
5970 HasSecurityGroups : !Not [ !Equals [ !Join ["", !Ref SecurityGroupIds], "" ] ]
6071 HasSubnets : !Not [ !Equals [ !Join ["", !Ref SubnetIds], "" ] ]
6172 IsRegionBAH : !Equals [!Ref "AWS::Region", "me-south-1"]
6273 IsRegionHKG : !Equals [!Ref "AWS::Region", "ap-east-1"]
74+ NotHasLambdaRole : !Equals [ !Ref LambdaRoleArn, "" ]
6375Resources :
6476 JdbcConnectorConfig :
6577 Type : ' AWS::Serverless::Function'
@@ -70,6 +82,7 @@ Resources:
7082 spill_bucket : !Ref SpillBucket
7183 spill_prefix : !Ref SpillPrefix
7284 default : !Ref DefaultConnectionString
85+ SNOWFLAKE_ENABLE_S3_EXPORT : !Ref EnableS3Export
7386 FunctionName : !Ref LambdaFunctionName
7487 PackageType : " Image"
7588 ImageUri : !Sub
@@ -80,40 +93,87 @@ Resources:
8093 Description : " Enables Amazon Athena to communicate with Snowflake using JDBC"
8194 Timeout : !Ref LambdaTimeout
8295 MemorySize : !Ref LambdaMemory
96+ Role : !If [ NotHasLambdaRole, !GetAtt FunctionRole.Arn, !Ref LambdaRoleArn ]
97+ VpcConfig :
98+ SecurityGroupIds : !If [ HasSecurityGroups, !Ref SecurityGroupIds, !Ref "AWS::NoValue" ]
99+ SubnetIds : !If [ HasSubnets, !Ref SubnetIds, !Ref "AWS::NoValue" ]
100+
101+ FunctionRole :
102+ Condition : NotHasLambdaRole
103+ Type : AWS::IAM::Role
104+ Properties :
83105 PermissionsBoundary : !If [ HasPermissionsBoundary, !Ref PermissionsBoundaryARN, !Ref "AWS::NoValue" ]
84- Policies :
85- - Statement :
86- - Action :
87- - secretsmanager:GetSecretValue
88- - secretsmanager:PutSecretValue
89- Effect : Allow
90- Resource : !Sub 'arn:${AWS::Partition}:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:${SecretNamePrefix}*'
91- Version : ' 2012-10-17'
92- - Statement :
93- - Action :
94- - logs:CreateLogGroup
95- Effect : Allow
96- Resource : !Sub 'arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:*'
97- Version : ' 2012-10-17'
98- - Statement :
99- - Action :
100- - logs:CreateLogStream
101- - logs:PutLogEvents
102- Effect : Allow
103- Resource : !Sub 'arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/${LambdaFunctionName}:*'
104- Version : ' 2012-10-17'
105- - Statement :
106- - Action :
107- - athena:GetQueryExecution
108- Effect : Allow
109- Resource : ' *'
110- Version : ' 2012-10-17'
106+ ManagedPolicyArns :
107+ - !Sub " arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
108+ AssumeRolePolicyDocument :
109+ Version : 2012-10-17
110+ Statement :
111+ - Effect : Allow
112+ Principal :
113+ Service :
114+ - lambda.amazonaws.com
115+ Action :
116+ - " sts:AssumeRole"
117+
118+ FunctionExecutionPolicy :
119+ Condition : NotHasLambdaRole
120+ Type : " AWS::IAM::Policy"
121+ Properties :
122+ PolicyName : FunctionExecutionPolicy
123+ PolicyDocument :
124+ Version : 2012-10-17
125+ Statement :
126+ - Action :
127+ - secretsmanager:GetSecretValue
128+ - secretsmanager:PutSecretValue
129+ Effect : Allow
130+ Resource : !Sub 'arn:${AWS::Partition}:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:${SecretNamePrefix}*'
131+ - Action :
132+ - logs:CreateLogGroup
133+ Effect : Allow
134+ Resource : !Sub 'arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:*'
135+ - Action :
136+ - logs:CreateLogStream
137+ - logs:PutLogEvents
138+ Effect : Allow
139+ Resource : !Sub 'arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/${LambdaFunctionName}:*'
140+ - Action :
141+ - lambda:GetFunction
142+ Effect : Allow
143+ Resource : !Sub 'arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${LambdaFunctionName}'
144+ - Action :
145+ - athena:GetQueryExecution
146+ Effect : Allow
147+ Resource : ' *'
148+ - Action :
149+ - ec2:CreateNetworkInterface
150+ - ec2:DeleteNetworkInterface
151+ - ec2:DescribeNetworkInterfaces
152+ - ec2:DetachNetworkInterface
153+ Effect : Allow
154+ Resource : ' *'
111155 # S3CrudPolicy allows our connector to spill large responses to S3. You can optionally replace this pre-made policy
112156 # with one that is more restrictive and can only 'put' but not read,delete, or overwrite files.
113- - S3CrudPolicy :
114- BucketName : !Ref SpillBucket
115- # VPCAccessPolicy allows our connector to run in a VPC so that it can access your data source.
116- - VPCAccessPolicy : {}
117- VpcConfig :
118- SecurityGroupIds : !If [ HasSecurityGroups, !Ref SecurityGroupIds, !Ref "AWS::NoValue" ]
119- SubnetIds : !If [ HasSubnets, !Ref SubnetIds, !Ref "AWS::NoValue" ]
157+ - Action :
158+ - s3:GetObject
159+ - s3:GetObjectVersion
160+ - s3:ListBucket
161+ - s3:GetBucketLocation
162+ - s3:PutObject
163+ - s3:PutObjectAcl
164+ - s3:GetLifecycleConfiguration
165+ - s3:PutLifecycleConfiguration
166+ - s3:DeleteObject
167+ - s3:DeleteObjectVersion
168+ Effect : Allow
169+ Resource :
170+ - Fn::Sub :
171+ - arn:${AWS::Partition}:s3:::${bucketName}
172+ - bucketName :
173+ Ref : SpillBucket
174+ - Fn::Sub :
175+ - arn:${AWS::Partition}:s3:::${bucketName}/*
176+ - bucketName :
177+ Ref : SpillBucket
178+ Roles :
179+ - !Ref FunctionRole
0 commit comments