Hello all,
I’ve been trying to get a Q search bar for anonymous users to render with minimal code following the instructions from GitHub - awslabs/amazon-quicksight-embedding-sdk: A SDK to help users embed QuickSight dashboards on other pages. but unfortunately have not been able to get it rendered. Each time I execute my lambda function, I see the dashboard being briefly processed (loading shows up) but immediately vanishes and goes to a normal white screen. Below is the code I am currently using:
EmbedTest.html:
html, body { height: 100%; width: 100%; margin: 0; padding: 0; overflow: hidden; background-color: #eeeeee; } #QEmbedDiv { position: absolute; top: 0; left: 0; right: 0; bottom: 0; width: 100%; height: 100%; } $(document).ready(async function() { try { if (typeof QuickSightEmbedding !== 'undefined') { const embeddingContext = await QuickSightEmbedding.createEmbeddingContext(); const frameOptions = {
url: 'EMBED_URL_PLACEHOLDER',
container: '#QEmbedDiv',
width: '100%',
height: '100%',
withFramePlaceholder: true
};
const contentOptions = {
panelOptions: {
panelType: 'SEARCH_BAR',
focusedHeight: '250px',
expandedHeight: '500px'
},
showTopicName: false,
allowTopicSelection: true
};
await embeddingContext.embedQSearchBar(frameOptions, contentOptions);
console.log('Q Search bar embedded successfully.');
} else {
console.error('QuickSightEmbedding is not defined');
}
} catch (error) {
console.error('Error embedding Q Search bar:', error);
}
});
</script>
lambda_function.py:
import boto3
import re
def lambda_handler(event, context):
try:
quicksight = boto3.client(‘quicksight’, region_name=‘<REGION_HERE>’)
aws_account_id = context.invoked_function_arn.split(“:”)[4]
embed_url_response = quicksight.generate_embed_url_for_anonymous_user(
AwsAccountId=aws_account_id,
Namespace='default',
SessionLifetimeInMinutes=60,
AuthorizedResourceArns=[
'arn:aws:quicksight:<REGION_HERE>:<ACCOUNT_NUMBER>:topic/<TOPIC_ID_HERE>'
],
ExperienceConfiguration={
'QSearchBar': {
'InitialTopicId': '<TOPIC_ID_HERE>'
}
},
AllowedDomains=[
'<LAMBDA_FUNCTION_URL>'
]
)
embed_url = embed_url_response.get('EmbedUrl')
if not embed_url:
raise Exception('Failed to generate embed URL')
with open('EmbedTest.html', 'r') as file:
html_content = file.read()
html_content = re.sub('EMBED_URL_PLACEHOLDER', embed_url, html_content)
return {
'statusCode': 200,
'headers': {
'Content-Type': 'text/html',
'Access-Control-Allow-Origin': '*'
},
'body': html_content
}
except Exception as e:
print(f"Error generating embed URL or creating HTML: {e}")
return {
'statusCode': 500,
'headers': {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
},
'body': f"Error: {str(e)}"
}
Below is the elements rendered on the page:
Could anyone provide me some pointers on what I may be doing wrong? I already have an IAM role which grants permission to the topic and generate_embed_url_for_anonymous_user. The lambda function url is also already within the list of allowed domains on QuickSight. I also can confirm that this is for the regular classic search bar.
I also tried to open the embedded links manually, but they also show nothing. As they are meant to be embedded, I assume that this is expected, or am I missing something?
Thanks in advance.