Simple python code to connect to lambda using boto3 API:
print('boto3 version: ' + boto3.__version__)
redshift = boto3.client('redshift-data')
def lambda_handler(event, context):
print('Preparing query')
response = redshift.batch_execute_statement(
Database='dev',
Sqls=[
'<<SQL QUERY>>'
],
StatementName='get view'
)
print('Query executed '+ response)
This script gives the following error when run:
boto3 version: 1.20.32
Response
{
"errorMessage": "An error occurred (ValidationException) when calling the BatchExecuteStatement operation: Either ClusterIdentifier or WorkgroupName needs to be specified.",
"errorType": "ValidationException",
"requestId": "6aebba50",
"stackTrace": [
" File \"/var/task/lambda_function.py\", line 13, in lambda_handler\n response = redshift.batch_execute_statement(\n",
" File \"/var/runtime/botocore/client.py\", line 391, in _api_call\n return self._make_api_call(operation_name, kwargs)\n",
" File \"/var/runtime/botocore/client.py\", line 719, in _make_api_call\n raise error_class(parsed_response, operation_name)\n"
]
}
This error does not make sense to me since the lambda uses boto3-1.20.32 botocore-1.23.32 and according to doc, this version of boto3 does not have the WorkgroupName argument:
When connecting to a serverless endpoint, specify the database name.
Regardless, I tried adding the WorkgroupName
as an arg which gives me the following (expected) error
Parameter validation failed:\nUnknown parameter in input: \"WorkgroupName\", must be one of: ClusterIdentifier, Database, DbUser, SecretArn, Sqls, StatementName, WithEvent"
To connect to Redshift Serverless, you will need to use boto3 1.24.11 at the minimum. See the changelog for boto3. Note that the error is returned from the Redshift data API which runs in the cloud and does not depend on boto3.