1

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"
IamAshay
  • 1,377
  • 1
  • 7
  • 16

1 Answers1

3

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.

MP24
  • 3,110
  • 21
  • 23
  • Where does it say that it requires 1.24.11+? All I see is that they added this new parameter "WorkgroupName" to be used with newer clients. – IamAshay Sep 20 '22 at 21:35
  • @IamAshay from the page *api-change:redshift-data: [botocore] This release adds a new --workgroup-name field to operations that connect to an endpoint. **Customers can now execute queries against their serverless workgroups.*** – MP24 Sep 21 '22 at 21:24
  • Okay, it worked after updating the boto3 to 1.24.xx. They should have documented it better, especially since the boto3 version present in Lambda by default does not have this functionality – IamAshay Sep 22 '22 at 16:44
  • @MP24, ran into this issue when testing Python Lambda function against Redshift serverless table. I wish the documentation made this clear. – cnu Nov 18 '22 at 01:48