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"

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

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 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.
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
@MP24, ran into this issue when testing Python Lambda function against Redshift serverless table. I wish the documentation made this clear.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.