Access Quicksight assets using Lambda function and boto3

I have deployed a Lambda function to VPC. The function will be used for exporting quicksight dashboard asset bundles on daily basis and storing them in an S3 bucket for backup purposes. The quicksight account has access to athena workgroup and s3 buckets, but it is not running in VPC.

First, I need to fetch the list of available dashboards for using each dashboard’s name in backup files. For this purpose, I have added the following permission policies to the lambda execution role, but getting timeout error while trying to list the assets:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor2",
            "Effect": "Allow",
            "Action": [
                "quicksight:ListDashboards",
                "quicksight:ListAnalyses"
            ],
            "Resource": "*"
        }
    ]
}

Code snippet from my lambda function looks like:

import boto3

quicksight_client = boto3.client(
    service_name='quicksight',
    region_name="ap-northeast-1"
)


def list_quicksight_dashboards():
	# Get the list of dashboards
	response = quicksight_client.list_dashboards(
		AwsAccountId='001122334455'
	)
	
	# Print the list of dashboards
	dashboards = response.get('DashboardSummaryList', [])

	for dashboard in dashboards:
		print(f"Dashboard ID: {dashboard['DashboardId']}, Name: {dashboard['Name']}")

def lambda_handler(event, context):
	list_quicksight_dashboards()
	
	return {
        'statusCode': 200,
        'body': json.dumps('OK')
    }

I have already tried to follow this solution: Adding permissions for Lambda access - JSON - Question & Answer - Amazon QuickSight Community

Is there anythink that I probably may have missed during configuration of the lambda function?

Hello @nasa !

Is the lambda timing out or is the QuickSight API that is timing out?

Hello @duncan

Unfortunately, the quicksight api call gets timed out. If I add some print statements into lambda handler, it gets printed and written into logs.

def lambda_handler(event, context):
    print("this text will be printed")
	
	list_quicksight_dashboards()
	
	print("waiting for results from quicksight api...")
	
	return {
		'statusCode': 200,
		'body': json.dumps('OK')
	}

Hey @nasa

Thank you for following up!

If its the QS APIs that time out then I recommend trying to break up the job like the post below describes:

Let me know if you try this and still run into the time out error.

Hello @duncan

Thank you for the reply.

I have increased lambda function’s timeout configuration to 5 minutes. Additionally, I tried to call only the list_analysis API and got after 1 minute the following exception:

Connect timeout on endpoint URL: "https://quicksight.ap-northeast-1.amazonaws.com/accounts/001122334455/analyses"

The function printed that exception message and returned http status 200. It means, the function itself isn’t timing out. Probably the Security Group configuration has to be updated.

Solved it using a proxy connection